List of usage examples for org.eclipse.jdt.core IJavaProject exists
boolean exists();
From source file:org.eclipse.ajdt.internal.ui.wizards.NewTypeWizardPage.java
License:Open Source License
private static IStatus validateJavaTypeName(String text, IJavaProject project) { if (project == null || !project.exists()) { return JavaConventions.validateJavaTypeName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3); }/*from w ww. j a va 2s. c o m*/ return JavaConventionsUtil.validateJavaTypeName(text, project); }
From source file:org.eclipse.ajdt.internal.ui.wizards.NewTypeWizardPage.java
License:Open Source License
/** * A hook method that gets called when the package field has changed. The method * validates the package name and returns the status of the validation. The validation * also updates the package fragment model. * <p>/*from w w w . j a va 2s . c o m*/ * Subclasses may extend this method to perform their own validation. * </p> * * @return the status of the validation */ protected IStatus packageChanged() { StatusInfo status = new StatusInfo(); IPackageFragmentRoot root = getPackageFragmentRoot(); fPackageDialogField.enableButton(root != null); IJavaProject project = root != null ? root.getJavaProject() : null; String packName = getPackageText(); if (packName.length() > 0) { IStatus val = validatePackageName(packName, project); if (val.getSeverity() == IStatus.ERROR) { status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName, val.getMessage())); return status; } else if (val.getSeverity() == IStatus.WARNING) { status.setWarning(Messages.format( NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName, val.getMessage())); // continue } } else { status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_DefaultPackageDiscouraged); } if (project != null) { if (project.exists() && packName.length() > 0) { try { IPath rootPath = root.getPath(); IPath outputPath = project.getOutputLocation(); if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) { // if the bin folder is inside of our root, don't allow to name a package // like the bin folder IPath packagePath = rootPath.append(packName.replace('.', '/')); if (outputPath.isPrefixOf(packagePath)) { status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation); return status; } } } catch (JavaModelException e) { JavaPlugin.log(e); // let pass } } fCurrPackage = root.getPackageFragment(packName); } else { status.setError(""); //$NON-NLS-1$ } return status; }
From source file:org.eclipse.ajdt.internal.ui.wizards.NewTypeWizardPage.java
License:Open Source License
private IType findType(IJavaProject project, String typeName) throws JavaModelException { if (project.exists()) { return project.findType(typeName); }/*ww w.j a va 2s .c o m*/ return null; }
From source file:org.eclipse.bpmn2.modeler.core.utils.JavaProjectClassLoader.java
License:Open Source License
public JavaProjectClassLoader(IJavaProject project) { super();/*from w w w .ja v a2 s. c o m*/ if (project == null || !project.exists()) throw new IllegalArgumentException("Invalid javaProject"); //$NON-NLS-1$ this.javaProject = project; }
From source file:org.eclipse.buckminster.jdt.internal.ClasspathEmitter.java
License:Open Source License
/** * Returns the default output folder relative to the project. * /*from w ww.j ava 2 s. co m*/ * @param project * @return The folder or <code>null</code> if not applicable. * @throws CoreException */ public static IPath getDefaultOutputFolder(IProject project) throws CoreException { String projectName = project.getName(); IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); IJavaProject javaProject = model.getJavaProject(projectName); if (javaProject == null || !javaProject.exists()) return null; return javaProject.getOutputLocation().removeFirstSegments(1); }
From source file:org.eclipse.buckminster.jdt.internal.ClasspathEmitter.java
License:Open Source License
private static void appendPaths(IJavaModel model, IProject project, String target, List<IPath> path, HashSet<IPath> seenPaths, HashSet<String> seenProjects, boolean atTop) throws CoreException { Logger log = Buckminster.getLogger(); String projectName = project.getName(); if (seenProjects.contains(projectName)) return;//from w w w. jav a2s . co m seenProjects.add(projectName); log.debug("Emitting classpath for project %s...", projectName); //$NON-NLS-1$ IJavaProject javaProject = model.getJavaProject(projectName); IClasspathEntry[] entries; if (javaProject == null || !javaProject.exists()) { // The project may still be a component that exports jar files. // BMClasspathContainer container = new BMClasspathContainer(project, target); entries = container.getClasspathEntries(); log.debug(" not a java project, contains %d entries", Integer.valueOf(entries.length)); //$NON-NLS-1$ } else { entries = (atTop && target != null) ? changeClasspathForTarget(javaProject, target) : javaProject.getResolvedClasspath(false); log.debug(" java project, contains %d entries", Integer.valueOf(entries.length)); //$NON-NLS-1$ } for (IClasspathEntry entry : entries) { IPath entryPath; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: log.debug(" found library with path: %s", entry.getPath()); //$NON-NLS-1$ if (!(atTop || entry.isExported())) { log.debug(" skipping path %s. It's neither at top nor exported", entry.getPath()); //$NON-NLS-1$ continue; } entryPath = entry.getPath(); break; case IClasspathEntry.CPE_SOURCE: entryPath = entry.getOutputLocation(); if (entryPath == null) { // Uses default output location // IJavaProject proj = model.getJavaProject(entry.getPath().segment(0)); if (proj == null) continue; entryPath = proj.getOutputLocation(); } log.debug(" found source with path: %s", entryPath); //$NON-NLS-1$ break; case IClasspathEntry.CPE_PROJECT: projectName = entry.getPath().segment(0); log.debug(" found project: %s", projectName); //$NON-NLS-1$ if (!(atTop || entry.isExported())) { log.debug(" skipping project %s. It's neither at top nor exported", projectName); //$NON-NLS-1$ continue; } IProject conProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); appendPaths(model, conProject, null, path, seenPaths, seenProjects, false); continue; default: throw BuckminsterException.fromMessage(Messages.unexpected_classpath_entry_kind); } IResource folder = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath); if (folder != null) { log.debug(" path %s is inside workspace, switching to %s", entryPath, folder.getLocation()); //$NON-NLS-1$ entryPath = folder.getLocation(); } if (!seenPaths.contains(entryPath)) { seenPaths.add(entryPath); path.add(entryPath); log.debug(" path %s added", entryPath); //$NON-NLS-1$ } } }
From source file:org.eclipse.buildship.core.launch.internal.GradleClasspathProvider.java
License:Open Source License
private IRuntimeClasspathEntry[] resolveProject(IRuntimeClasspathEntry projectEntry, IProject project, ILaunchConfiguration configuration) throws CoreException { if (!project.isOpen()) { return EMPTY_RESULT; }// w w w . ja v a2 s .com IJavaProject javaProject = JavaCore.create(project); if (javaProject == null || !javaProject.exists()) { return EMPTY_RESULT; } LaunchConfigurationScope configurationScopes = LaunchConfigurationScope.from(configuration); return resolveOutputLocations(projectEntry, javaProject, configurationScopes); }
From source file:org.eclipse.buildship.core.launch.internal.GradleClasspathProvider.java
License:Open Source License
private static IRuntimeClasspathEntry[] resolveOutputLocations(IRuntimeClasspathEntry projectEntry, IJavaProject project, LaunchConfigurationScope configurationScopes) throws CoreException { List<IPath> outputLocations = Lists.newArrayList(); boolean hasSourceFolderWithoutCustomOutput = false; if (project.exists() && project.getProject().isOpen()) { for (IClasspathEntry entry : project.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { // only add the output location if it's in the same source set if (configurationScopes.isEntryIncluded(entry)) { IPath path = entry.getOutputLocation(); if (path != null) { outputLocations.add(path); } else { // only use the default output if there's at least one source folder that doesn't have a custom output location hasSourceFolderWithoutCustomOutput = true; }// www . j a v a2s .com } } } } if (outputLocations.isEmpty()) { return new IRuntimeClasspathEntry[] { projectEntry }; } IPath defaultOutputLocation = project.getOutputLocation(); if (!outputLocations.contains(defaultOutputLocation) && hasSourceFolderWithoutCustomOutput) { outputLocations.add(defaultOutputLocation); } IRuntimeClasspathEntry[] result = new IRuntimeClasspathEntry[outputLocations.size()]; for (int i = 0; i < result.length; i++) { result[i] = new RuntimeClasspathEntry(JavaCore.newLibraryEntry(outputLocations.get(i), null, null)); result[i].setClasspathProperty(projectEntry.getClasspathProperty()); } return result; }
From source file:org.eclipse.cft.server.core.internal.debug.SshDebugProvider.java
License:Open Source License
@Override public boolean isDebugSupported(CloudFoundryApplicationModule appModule, CloudFoundryServer cloudServer) { IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(appModule); return javaProject != null && javaProject.exists() && cloudServer.supportsSsh(); }
From source file:org.eclipse.che.jdt.refactoring.RefactoringTest.java
License:Open Source License
private void restoreTestProject() throws Exception { IJavaProject javaProject = getRoot().getJavaProject(); if (javaProject.exists()) { IClasspathEntry srcEntry = getRoot().getRawClasspathEntry(); IClasspathEntry jreEntry = RefactoringTestSetup.getJRELibrary().getRawClasspathEntry(); IClasspathEntry[] cpes = javaProject.getRawClasspath(); ArrayList newCPEs = new ArrayList(); boolean cpChanged = false; for (int i = 0; i < cpes.length; i++) { IClasspathEntry cpe = cpes[i]; if (cpe.equals(srcEntry) || cpe.equals(jreEntry)) { newCPEs.add(cpe);//from w ww. jav a 2s . c o m } else { cpChanged = true; } } if (cpChanged) { IClasspathEntry[] newCPEsArray = (IClasspathEntry[]) newCPEs .toArray(new IClasspathEntry[newCPEs.size()]); javaProject.setRawClasspath(newCPEsArray, null); } Object[] nonJavaResources = javaProject.getNonJavaResources(); for (int i = 0; i < nonJavaResources.length; i++) { Object kid = nonJavaResources[i]; if (kid instanceof IResource) { IResource resource = (IResource) kid; if (!PROJECT_RESOURCE_CHILDREN.contains(resource.getName())) { JavaProjectHelper.delete(resource); } } } } }