List of usage examples for org.eclipse.jdt.core IJavaProject getRequiredProjectNames
String[] getRequiredProjectNames() throws JavaModelException;
From source file:org.eclipselabs.spray.xtext.scoping.PackageSelector.java
License:Open Source License
/** * @return//w ww . j av a2 s . c o m */ private boolean projectsHasChangedSinceLastRun(IJavaProject project) { if (projectToChanged.size() == 0) { return true; } try { for (Map.Entry<IContainer, Boolean> entry : projectToChanged.entrySet()) { for (String requiredProjectName : project.getRequiredProjectNames()) { if (requiredProjectName.equals(entry.getKey().getName()) && entry.getValue() == Boolean.TRUE) { return true; } } } } catch (JavaModelException e) { e.printStackTrace(); } return false; }
From source file:org.fastcode.util.SourceUtil.java
License:Open Source License
/** * @param workingJavaProject//from www .j a v a 2 s . c o m * @param defaultPath * @return * @throws Exception */ public static IPackageFragment[] getPackagesInProject(IJavaProject workingJavaProject, String defaultPath, final String type) throws Exception { final List<IPackageFragment> allPackages = new ArrayList<IPackageFragment>(); if (workingJavaProject.getElementName().equals(FC_PLUGIN)) { workingJavaProject = getWorkingJavaProjectFromUser(); defaultPath = getDefaultPathFromProject(workingJavaProject, type, EMPTY_STR); } final IPackageFragmentRoot[] packageFragmentRootArray = workingJavaProject.getJavaProject() .getAllPackageFragmentRoots(); getPackagesForFragment(workingJavaProject, packageFragmentRootArray, allPackages, defaultPath); final String reqdPrjs[] = workingJavaProject.getRequiredProjectNames(); for (final String rqdPrj : reqdPrjs) { final IJavaProject javaPrj = getJavaProject(rqdPrj); if (javaPrj == null) { MessageDialog.openInformation(new Shell(), "Dependent Project Missing", "Dependent project is missing, going ahead with the available ones."); continue; } final IPackageFragmentRoot[] pkgFrgmRoots = javaPrj.getAllPackageFragmentRoots(); getPackagesForFragment(getJavaProject(rqdPrj), pkgFrgmRoots, allPackages, defaultPath); } final GlobalSettings globalSettings = getInstance(); if (allPackages.isEmpty()) { if (globalSettings.isUseDefaultForPath()) { MessageDialog.openInformation(new Shell(), "No Packages Found", "There are no packages in the path " + globalSettings.getSourcePathJava()); return new IPackageFragment[0]; } else { MessageDialog.openInformation(new Shell(), "No Packages Found", "There are no packages found in the project " + workingJavaProject.getElementName()); return new IPackageFragment[0]; } } return allPackages.toArray(new IPackageFragment[0]); }
From source file:org.hibernate.eclipse.console.utils.ProjectUtils.java
License:Open Source License
/** * Collects all persistent unit names: available in the project and required projects * @param javaProject//from w w w .j a v a2s. c o m * @return */ public static String[] availablePersistenceUnits(IJavaProject javaProject) { if (javaProject.isOpen()) { Set<IJavaProject> projects = new HashSet<IJavaProject>(); projects.add(javaProject); try { String[] requiredProjectNames = javaProject.getRequiredProjectNames(); for (String projectName : requiredProjectNames) { IProject project = findProject(projectName); try { if (project != null && project.isAccessible() && project.hasNature(JavaCore.NATURE_ID)) { projects.add(JavaCore.create(project)); } } catch (CoreException e) { HibernateConsolePlugin.getDefault().log(e); } } } catch (JavaModelException e) { HibernateConsolePlugin.getDefault().log(e); } Set<String> puNames = new TreeSet<String>(); for (IJavaProject iJavaProject : projects) { for (String puName : projectPersistenceUnits(iJavaProject)) { puNames.add(puName); } } return puNames.toArray(new String[puNames.size()]); } return new String[0]; }
From source file:org.jboss.tools.smooks.configuration.editors.utils.JavaTypeFieldDialog.java
License:Open Source License
public static String openJavaTypeDialog(Shell shell, IJavaProject javaProject, int javaType) { IJavaSearchScope scope = null;/*from w ww . j a v a 2 s . c o m*/ String className = null; if (javaProject == null) { scope = JavaSearchScopeFactory.getInstance().createWorkspaceScope(true); } else { String[] requiredProjects = null; try { requiredProjects = javaProject.getRequiredProjectNames(); } catch (Exception e) { } if (requiredProjects == null) { requiredProjects = new String[] { javaProject.getElementName() }; } else { String[] temp = new String[requiredProjects.length + 1]; temp[0] = javaProject.getElementName(); System.arraycopy(requiredProjects, 0, temp, 1, requiredProjects.length); requiredProjects = temp; } scope = JavaSearchScopeFactory.getInstance().createJavaProjectSearchScope(requiredProjects, true); } SelectionDialog dialog; try { dialog = JavaUI.createTypeDialog(shell, SmooksConfigurationActivator.getDefault().getWorkbench().getActiveWorkbenchWindow(), scope, javaType, false); dialog.setMessage(Messages.JavaTypeFieldDialog_SearchDialogTitle); dialog.setTitle(Messages.JavaTypeFieldDialog_SearchDialogTitle); if (dialog.open() == Window.OK) { Object[] results = dialog.getResult(); if (results.length > 0) { Object result = results[0]; String packageFullName = JavaModelUtil.getTypeContainerName((IType) result); if (packageFullName == null || packageFullName.length() <= 0) { className = ((IType) result).getElementName(); } else { className = packageFullName + "." //$NON-NLS-1$ + ((IType) result).getElementName(); } return className; } } } catch (Throwable t) { SmooksConfigurationActivator.getDefault().log(t); } return className; }
From source file:org.jbpm.eclipse.util.ProjectClassLoader.java
License:Apache License
public static List<URL> getProjectClassPathURLs(IJavaProject project, List<String> alreadyLoadedProjects) { List<URL> pathElements = new ArrayList<URL>(); try {//from w ww .j a va 2 s. c o m IClasspathEntry[] paths = project.getResolvedClasspath(true); Set<IPath> outputPaths = new HashSet<IPath>(); if (paths != null) { for (int i = 0; i < paths.length; i++) { IClasspathEntry path = paths[i]; if (path.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { URL url = getRawLocationURL(path.getPath()); pathElements.add(url); } else if (path.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath output = path.getOutputLocation(); if (path.getOutputLocation() != null) { outputPaths.add(output); } } } } IPath location = getProjectLocation(project.getProject()); IPath outputPath = location.append(project.getOutputLocation().removeFirstSegments(1)); pathElements.add(0, outputPath.toFile().toURI().toURL()); for (IPath path : outputPaths) { outputPath = location.append(path.removeFirstSegments(1)); pathElements.add(0, outputPath.toFile().toURI().toURL()); } // also add classpath of required projects for (String projectName : project.getRequiredProjectNames()) { if (!alreadyLoadedProjects.contains(projectName)) { alreadyLoadedProjects.add(projectName); IProject reqProject = project.getProject().getWorkspace().getRoot().getProject(projectName); if (reqProject != null) { IJavaProject reqJavaProject = JavaCore.create(reqProject); pathElements.addAll(getProjectClassPathURLs(reqJavaProject, alreadyLoadedProjects)); } } } } catch (JavaModelException e) { JBPMEclipsePlugin.log(e); } catch (MalformedURLException e) { JBPMEclipsePlugin.log(e); } catch (Throwable t) { JBPMEclipsePlugin.log(t); } return pathElements; }
From source file:org.objectstyle.wolips.launching.delegates.WOJavaLocalApplicationLaunchConfigurationDelegate.java
License:Open Source License
protected void addProjectsToSearchPath(IProject buildProject, IProject project, StringBuffer searchPathBuffer, Set<IProject> visitedProjects, Set<IProject> invalidProjects) throws JavaModelException { if (!visitedProjects.contains(project)) { visitedProjects.add(project);/*from w ww . jav a 2 s . co m*/ if (project.equals(buildProject)) { searchPathBuffer.append("\"..\",\"../..\""); } if (isValidProjectPath(project)) { ProjectAdapter projectAdapter = (ProjectAdapter) project.getAdapter(ProjectAdapter.class); if (projectAdapter != null && projectAdapter.isFramework()) { searchPathBuffer.append(",\""); searchPathBuffer.append(project.getLocation().toOSString()); searchPathBuffer.append("\""); } } else { invalidProjects.add(project); } IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { String[] requiredProjectNames = javaProject.getRequiredProjectNames(); for (int requiredProjectNameNum = 0; requiredProjectNameNum < requiredProjectNames.length; requiredProjectNameNum++) { String requiredProjectName = requiredProjectNames[requiredProjectNameNum]; IProject requiredProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(requiredProjectName); addProjectsToSearchPath(buildProject, requiredProject, searchPathBuffer, visitedProjects, invalidProjects); } } } }
From source file:org.opendaylight.yangide.core.indexing.IndexAllProject.java
License:Open Source License
@Override public boolean execute(IProgressMonitor progressMonitor) { log.info("[I] Project: {}", project.getName()); if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) { return true; }/* w ww . java 2s . c o m*/ if (!this.project.isAccessible()) { return true; } final Set<IPath> ignoredPath = new HashSet<>(); final Set<IPath> externalJarsPath = new HashSet<>(); try { JavaProject proj = (JavaProject) JavaCore.create(project); final Set<String> projectScope = new HashSet<>(); projectScope.add(project.getName()); if (proj != null) { IClasspathEntry[] classpath = proj.getResolvedClasspath(); for (IClasspathEntry entry : classpath) { 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 (IPackageFragmentRoot root : roots) { IPath entryPath = root.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 Set<String> indirectScope = new HashSet<>(); 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 path : externalJarsPath) { try (JarFile jarFile = new JarFile(path.toFile())) { ZipEntry entry = jarFile.getEntry("META-INF/yang/"); if (entry != null) { this.manager.addJarFile(project, path); } } catch (IOException e) { YangCorePlugin.log(e); } } try { final HashSet<IFile> indexedFiles = new HashSet<>(); project.accept(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 file : indexedFiles) { this.manager.addSource(file); } } catch (CoreException e) { this.manager.removeIndexFamily(project); return false; } return true; }
From source file:org.springframework.ide.eclipse.boot.dash.cloudfoundry.JavaPackageFragmentRootHandler.java
License:Open Source License
protected void getOrderedJavaProjectNames(List<String> sameLevelRequiredProjects, List<String> collectedProjects) { // The order in which required projects are collected is as follows, // with the RHS // being required projects of the LHS // A -> BC // B -> D/* w ww. j av a2s . c o m*/ // C -> E // = total 5 projects, added in the order that they are encountered. // so final ordered list should be ABCDE if (sameLevelRequiredProjects == null) { return; } List<String> nextLevelRequiredProjects = new ArrayList<String>(); // First add the current level java projects in the order they appear // and also collect each one's required names. for (String name : sameLevelRequiredProjects) { try { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); if (project != null) { IJavaProject jvPrj = JavaCore.create(project); if (jvPrj != null && jvPrj.exists()) { if (!collectedProjects.contains(name)) { collectedProjects.add(name); } String[] names = jvPrj.getRequiredProjectNames(); if (names != null && names.length > 0) { for (String reqName : names) { if (!nextLevelRequiredProjects.contains(reqName)) { nextLevelRequiredProjects.add(reqName); } } } } } } catch (JavaModelException e) { BootDashActivator.log(e); } } // Now recurse to fetch the required projects for the // list of java projects that were added at the current level above if (!nextLevelRequiredProjects.isEmpty()) { getOrderedJavaProjectNames(nextLevelRequiredProjects, collectedProjects); } }
From source file:org.springframework.ide.eclipse.core.java.JdtUtils.java
License:Open Source License
public static List<IJavaProject> getAllDependingJavaProjects(IJavaProject project) { List<IJavaProject> javaProjects = new ArrayList<IJavaProject>(); IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); if (model != null) { try {/* www.j av a 2s. c o m*/ String[] names = project.getRequiredProjectNames(); IJavaProject[] projects = model.getJavaProjects(); for (int index = 0; index < projects.length; index++) { for (int offset = 0; offset < names.length; offset++) { String name = projects[index].getProject().getName(); if (name.equals(names[offset])) { javaProjects.add(projects[index]); } } } } catch (JavaModelException exception) { } } return javaProjects; }
From source file:org.springsource.ide.eclipse.commons.core.JdtUtils.java
License:Open Source License
/** * Checks if the given <code>type</code> implements/extends * <code>className</code>.//from ww w . jav a 2 s . com */ // public static boolean doesImplement(IResource resource, IType type, // String className) { // if (resource == null || type == null || className == null) { // return false; // } // if (className.startsWith("java.") || className.startsWith("javax.")) { // try { // ClassLoader cls = getClassLoader(resource.getProject(), null); // Class<?> typeClass = cls.loadClass(type.getFullyQualifiedName('$')); // Class<?> interfaceClass = cls.loadClass(className); // return typeClass.equals(interfaceClass) || // interfaceClass.isAssignableFrom(typeClass); // } // catch (Throwable e) { // // ignore this and fall back to JDT does implement checks // } // } // return doesImplementWithJdt(resource, type, className); // } // public static IType getAjdtType(IProject project, String className) { // IJavaProject javaProject = getJavaProject(project); // if (IS_AJDT_PRESENT && javaProject != null && className != null) { // // try { // IType type = null; // // // First look for the type in the project // if (isAjdtProject(project)) { // type = AjdtUtils.getAjdtType(project, className); // if (type != null) { // return type; // } // } // // // Then look for the type in the referenced Java projects // for (IProject refProject : project.getReferencedProjects()) { // if (isAjdtProject(refProject)) { // type = AjdtUtils.getAjdtType(refProject, className); // if (type != null) { // return type; // } // } // } // } // catch (CoreException e) { // StatusHandler.log(new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, // "Error getting Java type '" // + className + "'", e)); // } // } // return null; // } public static List<IJavaProject> getAllDependingJavaProjects(IJavaProject project) { List<IJavaProject> javaProjects = new ArrayList<IJavaProject>(); IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); if (model != null) { try { String[] names = project.getRequiredProjectNames(); IJavaProject[] projects = model.getJavaProjects(); for (IJavaProject project2 : projects) { for (String name2 : names) { String name = project2.getProject().getName(); if (name.equals(name2)) { javaProjects.add(project2); } } } } catch (JavaModelException exception) { } } return javaProjects; }