Java Code Examples for org.eclipse.core.resources.IProject#exists()
The following examples show how to use
org.eclipse.core.resources.IProject#exists() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodewindSourcePathComputer.java From codewind-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public ISourceContainer[] computeSourceContainers(ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException { // Get the project name from the launch configuration, look up the IProject, and return that IProject as a // source container. // CodewindLaunchConfigDelegate sets this attribute in the launch config. final String projectName = config.getAttribute(CodewindLaunchConfigDelegate.PROJECT_NAME_ATTR, ""); if (!projectName.isEmpty()) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); if (project == null || !project.exists()) { Logger.logError("Could not find project with name " + projectName + " to add to source path"); return new ISourceContainer[0]; } // What does the second boolean parameter 'referenced' mean ? ISourceContainer projectSourceContainer = new ProjectSourceContainer(project, true); Logger.log("Adding source container from project " + project.getName()); return new ISourceContainer[] { projectSourceContainer }; } Logger.logError("Could not retrieve project name from launch config " + config.getName()); return new ISourceContainer[0]; }
Example 2
Source File: ExampleWizard.java From statecharts with Eclipse Public License 1.0 | 6 votes |
protected boolean overrideIfExists(ExampleData selection) { String name = selection.getProjectDir().getName(); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); if (project.exists()) { OverrideRunnable runnable = new OverrideRunnable(getShell(), name); Display.getDefault().syncExec(runnable); if (runnable.isOverride()) { try { project.delete(true, new NullProgressMonitor()); } catch (CoreException e) { e.printStackTrace(); } } return runnable.isOverride(); } return true; }
Example 3
Source File: TodoTaskMarkerBuilder.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
private void peformSearchOnCompilationSet(String projectName, Collection<String> compilationSet) { if (compilationSet != null) { final Iterator<String> iterator = compilationSet.iterator(); final IProject project = ResourceUtils.getProject(projectName); if (!project.exists() || !project.isOpen()) { return; } performSearchOnResources(new Iterator<IResource>() { @Override public boolean hasNext() { return iterator.hasNext(); } @Override public IResource next() { String path = iterator.next(); return ResourceUtils.getResource(project, new File(path).toURI()); } @Override public void remove() { } }); } }
Example 4
Source File: AbstractPythonWizardPage.java From Pydev with Eclipse Public License 1.0 | 6 votes |
private String checkValidProject(String text) { validatedProject = null; if (text == null || text.trim().length() == 0) { return "The project name must be filled."; } IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(text); if (!project.exists()) { return "The project selected does not exist in the workspace."; } validatedProject = project; if (existingSourceGroup != null) { existingSourceGroup.setActiveProject(project); } return null; }
Example 5
Source File: IDEReportClasspathResolver.java From birt with Eclipse Public License 1.0 | 5 votes |
private String getProjectOutputClassPath( IProject project ) { if ( !hasJavaNature( project ) ) { return null; } IJavaProject fCurrJProject = JavaCore.create( project ); IPath path = null; boolean projectExists = ( project.exists( ) && project.getFile( ".classpath" ).exists( ) ); //$NON-NLS-1$ if ( projectExists ) { if ( path == null ) { path = fCurrJProject.readOutputLocation( ); // String curPath = path.toOSString( ); // String directPath = project.getLocation( ).toOSString( ); // int index = directPath.lastIndexOf( File.separator ); if (path == null) { return null; } String absPath = getFullPath( path, project ); return absPath; } } return null; }
Example 6
Source File: LauncherTabArguments.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
private IProject getXdsProject(ILaunchConfiguration config) { try { String prjname = config.getAttribute(ILaunchConfigConst.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$ if (prjname.length() > 0) { IProject ip = ResourcesPlugin.getWorkspace().getRoot().getProject(prjname); if (ip.exists() && ip.getNature(NatureIdRegistry.MODULA2_SOURCE_PROJECT_NATURE_ID) != null) { return ip; } } } catch (CoreException e) {} return null; }
Example 7
Source File: NewProjectFromScratchPage.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
public static void validateEclipseProjectAndLocation(String projectName, String projectRoot, boolean folderFirst) throws ValidationException { if (folderFirst) { validateProjectFolder(projectRoot); validateProjectName(projectName); } else { validateProjectName(projectName); validateProjectFolder(projectRoot); } // check whether project already exists final IProject handle= ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); if (handle.exists()) { throw new ValidationException(Messages.NewProjectFromScratchPage_ProjectAlreadyExists, true); } IProject p = ProjectUtils.getXdsProjectWithProjectRoot(projectRoot); if (p != null) { throw new ValidationException(String.format(Messages.NewProjectFromScratchPage_OtherProjectUsesThisFilesLocation, p.getName()), true); } // Another checks: IPath ipPrj = new Path(projectRoot); IPath ipPrjParent = ipPrj.removeLastSegments(1); IPath ipWorkspace = ResourcesPlugin.getWorkspace().getRoot().getLocation(); if (isPathsEquals(ipPrjParent, ipWorkspace)) { if (handle.getName().equals(ipPrj.lastSegment())) { // <workspace_dir>\<projectName> is legal location but // workspace.validateProjectLocation() rejects it } else { IStatus is = ResourcesPlugin.getWorkspace().validateProjectLocation(handle, ipPrj); if (!is.isOK()) { throw new ValidationException (is.getMessage(), true); } } } }
Example 8
Source File: ProjectUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Returns an IProject by the given name, or null if no such project * can be found. * @param projectName The project's name * @return the IProject, or null if not found */ public static IProject findProject(String projectName) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = workspaceRoot.getProject(projectName); if (project == null || !project.exists()) { return null; } return project; }
Example 9
Source File: Importer.java From hybris-commerce-eclipse-plugin with Apache License 2.0 | 5 votes |
/** * Some addons don't have their classpath correctly configured in Eclipse and won't compile * * @param monitor * @param javaProject * @throws JavaModelException */ private void fixAddons(IProgressMonitor monitor, IJavaProject javaProject) throws JavaModelException { final String projectName = javaProject.getProject().getName(); if (projectName.equals("orderselfserviceaddon") || projectName.equals("notificationaddon") || projectName.equals("customerinterestsaddon") || projectName.equals("consignmenttrackingaddon")) { IProject acceleratorstorefrontcommonsProject = ResourcesPlugin.getWorkspace().getRoot() .getProject("acceleratorstorefrontcommons"); if (acceleratorstorefrontcommonsProject != null && acceleratorstorefrontcommonsProject.exists()) { if (!javaProject.isOnClasspath(acceleratorstorefrontcommonsProject)) { FixProjectsUtils.addToClassPath(acceleratorstorefrontcommonsProject, IClasspathEntry.CPE_PROJECT, javaProject, monitor); } } } if (projectName.equals("stocknotificationaddon")) { IProject notificationfacadesProject = ResourcesPlugin.getWorkspace().getRoot() .getProject("notificationfacades"); if (notificationfacadesProject != null && notificationfacadesProject.exists()) { if (!javaProject.isOnClasspath(notificationfacadesProject)) { FixProjectsUtils.addToClassPath(notificationfacadesProject, IClasspathEntry.CPE_PROJECT, javaProject, monitor); } } } }
Example 10
Source File: AbstractJavaGeneratorTest.java From statecharts with Eclipse Public License 1.0 | 5 votes |
public IMarker[] generateAndCompile(Statechart statechart) throws Exception { GeneratorEntry entry = createGeneratorEntry(statechart.getName(), SRC_GEN); entry.setElementRef(statechart); IProject targetProject = getProject(entry); targetProject.delete(true, new NullProgressMonitor()); targetProject = getProject(entry); if (!targetProject.exists()) { targetProject.create(new NullProgressMonitor()); targetProject.open(new NullProgressMonitor()); } IGeneratorEntryExecutor executor = new EclipseContextGeneratorExecutorLookup() { protected Module getContextModule() { return Modules.override(super.getContextModule()).with(new Module() { @Override public void configure(Binder binder) { binder.bind(IConsoleLogger.class).to(TestLogger.class); } }); }; }.createExecutor(entry, "yakindu::java"); executor.execute(entry); targetProject.refreshLocal(IResource.DEPTH_INFINITE, null); targetProject.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null); targetProject.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor()); IMarker[] markers = targetProject.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE); return markers; }
Example 11
Source File: BaseEditor.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * @return the project for the file that's being edited (or null if not available) */ public IProject getProject() { IEditorInput editorInput = this.getEditorInput(); if (editorInput instanceof IAdaptable) { IAdaptable adaptable = editorInput; IFile file = adaptable.getAdapter(IFile.class); if (file != null) { return file.getProject(); } IResource resource = adaptable.getAdapter(IResource.class); if (resource != null) { return resource.getProject(); } if (editorInput instanceof IStorageEditorInput) { IStorageEditorInput iStorageEditorInput = (IStorageEditorInput) editorInput; try { IStorage storage = iStorageEditorInput.getStorage(); IPath fullPath = storage.getFullPath(); if (fullPath != null) { IWorkspace ws = ResourcesPlugin.getWorkspace(); for (String s : fullPath.segments()) { IProject p = ws.getRoot().getProject(s); if (p.exists()) { return p; } } } } catch (Exception e) { Log.log(e); } } } return null; }
Example 12
Source File: ProjectUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Creates a project with the specified name in the workspace. * * @param projectName * @return new project * @throws CoreException */ public static IProject createProject(String projectName) throws CoreException { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = workspaceRoot.getProject(projectName); if (project.exists()) { throw new IllegalStateException("Project " + projectName + " already exists in this workspace"); } IProgressMonitor monitor = new NullProgressMonitor(); BuildPathsBlock.createProject(project, project.getLocationURI(), monitor); return project; }
Example 13
Source File: ExternalFoldersManager.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private Map getFolders() { if (this.folders == null) { Map tempFolders = new HashMap(); IProject project = getExternalFoldersProject(); try { if (!project.isAccessible()) { if (project.exists()) { // workspace was moved (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=252571 ) openExternalFoldersProject(project, null/*no progress*/); } else { // if project doesn't exist, do not open and recreate it as it means that there are no external folders return this.folders = Collections.synchronizedMap(tempFolders); } } IResource[] members = project.members(); for (int i = 0, length = members.length; i < length; i++) { IResource member = members[i]; if (member.getType() == IResource.FOLDER && member.isLinked() && member.getName().startsWith(LINKED_FOLDER_NAME)) { IPath externalFolderPath = member.getLocation(); tempFolders.put(externalFolderPath, member); } } } catch (CoreException e) { Util.log(e, "Exception while initializing external folders"); //$NON-NLS-1$ } this.folders = Collections.synchronizedMap(tempFolders); } return this.folders; }
Example 14
Source File: SARLAgentMainLaunchConfigurationTab.java From sarl with Apache License 2.0 | 5 votes |
/** Replies if the project name is valid. * * <p>Copied from JDT. * * @return the validity state. */ protected boolean isValidProjectName() { final String name = this.fProjText.getText(); if (Strings.isNullOrEmpty(name)) { setErrorMessage(Messages.MainLaunchConfigurationTab_3); return false; } final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IStatus status = workspace.validateName(name, IResource.PROJECT); if (status.isOK()) { final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); if (!project.exists()) { setErrorMessage(MessageFormat.format( Messages.MainLaunchConfigurationTab_4, name)); return false; } if (!project.isOpen()) { setErrorMessage(MessageFormat.format( Messages.MainLaunchConfigurationTab_5, name)); return false; } } else { setErrorMessage(MessageFormat.format( Messages.MainLaunchConfigurationTab_6, status.getMessage())); return false; } return true; }
Example 15
Source File: ResourceUtils.java From goclipse with Eclipse Public License 1.0 | 5 votes |
public static IProject getProjectFromMemberLocation(Location fileLocation) { IFile[] files = getWorkspaceRoot().findFilesForLocationURI(fileLocation.toUri()); for (IFile file : files) { IProject project = file.getProject(); if(project.exists() && project.isOpen()) { return project; } } return null; }
Example 16
Source File: JavaProjectSetupUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
public static void deleteProject(IProject project) throws CoreException { if (project.exists()) { project.delete(true, true, null); } }
Example 17
Source File: PerformanceTestProjectSetup.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public static void deleteProject(IProject project) throws CoreException { if (project.exists()) { project.delete(true, true, null); } }
Example 18
Source File: GeometryEditorBuilderTester.java From ice with Eclipse Public License 1.0 | 4 votes |
/** * <p> * This operations checks the GeometryEditorBuilder to make sure that it * properly creates GeometryEditors. It also checks the name and the type of * the GeometryEditorBuilder and the GeometryEditor. * </p> * */ @Test public void checkConstruction() { // Local Declarations IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); URI defaultProjectLocation = null; IProject project = null; String separator = System.getProperty("file.separator"); String filename = null; // Setup the project workspace try { // Get the project handle project = workspaceRoot.getProject("itemTesterWorkspace"); // If the project does not exist, create it if (!project.exists()) { // Set the location as ${workspace_loc}/ItemTesterWorkspace defaultProjectLocation = (new File( System.getProperty("user.dir") + separator + "itemTesterWorkspace")).toURI(); // Create the project description IProjectDescription desc = ResourcesPlugin.getWorkspace() .newProjectDescription("itemTesterWorkspace"); // Set the location of the project desc.setLocationURI(defaultProjectLocation); // Create the project project.create(desc, null); } // Open the project if it is not already open if (project.exists() && !project.isOpen()) { project.open(null); } } catch (CoreException e) { // Catch for creating the project e.printStackTrace(); fail(); } // Instantiate the builder geometryEditorBuilder = new GeometryEditorBuilder(); // Check the name - the static value, the getter and the comparison of // the two assertEquals("Geometry Editor", geometryEditorBuilder.name); assertEquals("Geometry Editor", geometryEditorBuilder.getItemName()); assertEquals(geometryEditorBuilder.name, geometryEditorBuilder.getItemName()); // Check the type - the static value, the getter and the comparison of // the two assertEquals(ItemType.Geometry, geometryEditorBuilder.type); assertEquals(ItemType.Geometry, geometryEditorBuilder.getItemType()); assertEquals(geometryEditorBuilder.type, geometryEditorBuilder.getItemType()); // Make sure construction works properly Item editor = geometryEditorBuilder.build(project); assertNotNull(editor); assertTrue(editor instanceof GeometryEditor); assertEquals("Geometry Editor", editor.getName()); assertEquals(ItemType.Geometry, editor.getItemType()); return; }
Example 19
Source File: MockJavaProjectProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
public static void deleteProject(IProject project) throws CoreException { if (project.exists()) { project.delete(true, true, null); } }
Example 20
Source File: VibeKVPairTester.java From ice with Eclipse Public License 1.0 | 4 votes |
/** * <p> * This operation sets up the workspace. * </p> */ @BeforeClass public static void beforeTests() { // Local Declarations IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = null; String separator = System.getProperty("file.separator"); String userDir = System.getProperty("user.home") + separator + "ICETests" + separator + "caebatTesterWorkspace"; // Enable Debugging System.setProperty("DebugICE", ""); // Setup the project try { // Get the project handle IPath projectPath = new Path(userDir + separator + ".project"); // Create the project description IProjectDescription desc = ResourcesPlugin.getWorkspace() .loadProjectDescription(projectPath); // Get the project handle and create it project = workspaceRoot.getProject(desc.getName()); // Create the project if it doesn't exist if (!project.exists()) { project.create(desc, new NullProgressMonitor()); } // Open the project if it is not already open if (project.exists() && !project.isOpen()) { project.open(new NullProgressMonitor()); } // Refresh the workspace project.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { // Catch exception for creating the project e.printStackTrace(); fail(); } // Set the global project reference. projectSpace = project; return; }