List of usage examples for org.eclipse.jdt.core IJavaProject exists
boolean exists();
From source file:org.eclipse.wb.internal.core.utils.jdt.core.CodeUtils.java
License:Open Source License
/** * Adds {@link IContainer}'s for all source directories of given {@link IJavaProject} and its * required projects./* w w w.j a v a 2 s . co m*/ */ private static void addSourceContainers(List<IContainer> containers, Set<IJavaProject> visitedProjects, IJavaProject javaProject, boolean includeRequiredProjects) throws Exception { // check for existence if (!javaProject.exists()) { return; } // check for recursion if (visitedProjects.contains(javaProject)) { return; } visitedProjects.add(javaProject); // prepare information IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = javaProject.getProject(); // add source folders for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IContainer container = (IContainer) root.findMember(entry.getPath()); if (container != null) { containers.add(container); } } } // source folders of required projects if (includeRequiredProjects) { for (String requiredProjectName : javaProject.getRequiredProjectNames()) { addSourceContainers(containers, visitedProjects, requiredProjectName); } } // source folders for fragments if (includeRequiredProjects) { Object model = ReflectivePDE.findModel(project); if (model != null) { BundleDescription bundleDescription = ReflectivePDE.getPluginModelBundleDescription(model); if (bundleDescription != null) { BundleDescription[] fragments = bundleDescription.getFragments(); for (BundleDescription fragment : fragments) { String fragmentProjectName = fragment.getSymbolicName(); addSourceContainers(containers, visitedProjects, fragmentProjectName); } } } } }
From source file:org.eclipse.wb.internal.core.utils.jdt.core.CodeUtils.java
License:Open Source License
/** * @return the {@link IPackageFragmentRoot} that is parent of given {@link IJavaElement} or first * {@link IPackageFragmentRoot} of {@link IJavaProject}. *///from w w w . j a v a 2 s. c om public static IPackageFragmentRoot getPackageFragmentRoot(IJavaElement element) throws JavaModelException { if (element != null) { // try to find valid parent IPackageFragmentRoot { IPackageFragmentRoot root = (IPackageFragmentRoot) element .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null && root.getKind() == IPackageFragmentRoot.K_SOURCE) { return root; } } // use IPackageFragmentRoot of IJavaProject { IJavaProject javaProject = element.getJavaProject(); if (javaProject != null && javaProject.exists()) { for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { return root; } } } } } // invalid element return null; }
From source file:org.eclipse.wb.internal.core.utils.jdt.core.ProjectUtils.java
License:Open Source License
/** * Finds {@link IFile}'s with given path in {@link IJavaProject} and required {@link IJavaProject} * 's./*ww w . j a v a2 s . com*/ */ private static void findFiles(List<IFile> files, IJavaProject javaProject, String filePath, Set<IJavaProject> visitedProjects) throws Exception { // may be not exists if (!javaProject.exists()) { return; } // may be already visited if (visitedProjects.contains(javaProject)) { return; } visitedProjects.add(javaProject); // check required projects IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); for (String projectName : javaProject.getRequiredProjectNames()) { IJavaProject requiredJavaProject = JavaCore.create(workspaceRoot.getProject(projectName)); findFiles(files, requiredJavaProject, filePath, visitedProjects); } // check current project { IProject project = javaProject.getProject(); IFile file = project.getFile(new Path(filePath)); if (file.exists()) { files.add(file); } } }
From source file:org.eclipse.wb.internal.core.utils.jdt.ui.ProjectSelectionDialogField.java
License:Open Source License
/** * @return the {@link IJavaProject} for a string. *//*www .j ava 2 s . c o m*/ private static IJavaProject getProjectFromString(String projectString) { if (projectString.length() == 0) { return null; } // check project IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = workspaceRoot.getProject(projectString); IJavaProject javaProject = JavaCore.create(project); return javaProject.exists() ? javaProject : null; }
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 ww w.ja va2 s .co 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); }
From source file:org.eclipse.wb.internal.core.utils.reflect.ProjectClassLoader.java
License:Open Source License
private static void addFragments(List<String> entries, IProject project, Set<IJavaProject> visitedProjects) throws Exception { IJavaProject javaProject = JavaCore.create(project); if (!javaProject.exists()) { return;//ww w .j a v a 2 s.c o m } // add fragments of this project { Object model = ReflectivePDE.findModel(project); if (model != null) { org.eclipse.osgi.service.resolver.BundleDescription modelBundleDescription = ReflectivePDE .getPluginModelBundleDescription(model); if (modelBundleDescription != null) { org.eclipse.osgi.service.resolver.BundleDescription[] fragments = modelBundleDescription .getFragments(); for (org.eclipse.osgi.service.resolver.BundleDescription fragment : fragments) { String fragmentProjectName = fragment.getSymbolicName(); addFragment_runtimeClassPathEntries(entries, fragmentProjectName, visitedProjects); } } } } // add also fragments of required projects { String[] requiredProjectNames = javaProject.getRequiredProjectNames(); for (String requiredProjectName : requiredProjectNames) { addFragment_runtimeClassPathEntries(entries, requiredProjectName, visitedProjects); } } }
From source file:org.eclipse.wb.internal.core.utils.reflect.ProjectClassLoader.java
License:Open Source License
/** * Adds absolute locations (in file system) of output folders for given and required projects. *//* w w w . j a v a 2s . c om*/ public static void addOutputLocations(Set<IProject> visitedProjects, List<String> locations, IProject project) throws Exception { // may be not exists if (!project.exists()) { return; } // check for recursion if (visitedProjects.contains(project)) { return; } visitedProjects.add(project); // add output folders for IJavaProject { IJavaProject javaProject = JavaCore.create(project); if (javaProject.exists()) { // default output location { IPath outputPath = javaProject.getOutputLocation(); addAbsoluteLocation(locations, outputPath); } // source folder specific output locations for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputPath = entry.getOutputLocation(); addAbsoluteLocation(locations, outputPath); } } } } // process required projects IProject[] referencedProjects = project.getReferencedProjects(); for (IProject referencedProject : referencedProjects) { addOutputLocations(visitedProjects, locations, referencedProject); } }
From source file:org.eclipse.wb.internal.core.utils.reflect.ProjectClassLoader.java
License:Open Source License
/** * Adds absolute locations (in file system) of source folders for given and required projects. *///from ww w.j a v a 2 s .c om public static void addSourceLocations(Set<IProject> visitedProjects, List<String> locations, IProject project) throws Exception { // may be not exists if (!project.exists()) { return; } // check for recursion if (visitedProjects.contains(project)) { return; } visitedProjects.add(project); // add source folders for IJavaProject { IJavaProject javaProject = JavaCore.create(project); if (javaProject.exists()) { for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath entryPath = entry.getPath(); addAbsoluteLocation(locations, entryPath); } } } } // process required projects IProject[] referencedProjects = project.getReferencedProjects(); for (IProject referencedProject : referencedProjects) { addSourceLocations(visitedProjects, locations, referencedProject); } }
From source file:org.eclipse.xtend.ide.tests.contentassist.Bug462915Test.java
License:Open Source License
@Override public IJavaProject getJavaProject(final ResourceSet resourceSet) { IJavaProject javaProject = JavaProjectSetupUtil.findJavaProject(Bug462915Test.NO_GUICE_PROJECT_NAME); if (((javaProject == null) || (!javaProject.exists()))) { try {//from ww w .ja v a 2s . co m this.noGuiceProject = WorkbenchTestHelper.createPluginProject(Bug462915Test.NO_GUICE_PROJECT_NAME, ((String[]) Conversions.unwrapArray(this.getTestProjectRequiredBundles(), String.class))); javaProject = JavaProjectSetupUtil.findJavaProject(Bug462915Test.NO_GUICE_PROJECT_NAME); } catch (final Throwable _t) { if (_t instanceof CoreException) { final CoreException e = (CoreException) _t; String _message = e.getMessage(); String _plus = ("cannot create java project due to: " + _message); String _plus_1 = (_plus + " / "); String _plus_2 = (_plus_1 + e); Assert.fail(_plus_2); } else { throw Exceptions.sneakyThrow(_t); } } } return javaProject; }
From source file:org.eclipse.xtend.ide.tests.contentassist.ContentAssistTest.java
License:Open Source License
@Override public IJavaProject getJavaProject(ResourceSet resourceSet) { IJavaProject javaProject = findJavaProject(PROJECT_NAME); if (javaProject == null || !javaProject.exists()) { try {/* w w w.j av a 2 s . co m*/ demandCreateProject = createPluginProject(PROJECT_NAME); javaProject = findJavaProject(PROJECT_NAME); } catch (CoreException e) { fail("cannot create java project due to: " + e.getMessage() + " / " + e); } } return javaProject; }