Java Code Examples for org.eclipse.core.resources.IWorkspaceRoot#getProject()
The following examples show how to use
org.eclipse.core.resources.IWorkspaceRoot#getProject() .
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: JavaProjectUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * a Finds a Java project with the given name. * * @param projectName The name of the Java project * @return The Java project, or null if it cannot be found or if it does not * have the Java nature */ public static IJavaProject findJavaProject(String projectName) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = workspaceRoot.getProject(projectName); if (!project.exists()) { return null; } try { if (!NatureUtils.hasNature(project, JavaCore.NATURE_ID)) { return null; } } catch (CoreException e) { // Thrown if the project doesn't exist or is not open return null; } return JavaCore.create(project); }
Example 2
Source File: EclipseFileSystemTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public IProject createProject(final String name) { try { IProject _xblockexpression = null; { final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final IProject project = root.getProject(name); boolean _exists = project.exists(); if (_exists) { Assert.fail("Project \'foo\' should not exist yet"); } project.create(null); project.open(null); _xblockexpression = project; } return _xblockexpression; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 3
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 4
Source File: N4JSGenerateImmediatelyBuilderState.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** logic of {@link IN4JSCore#findAllProjects()} with filtering by name */ private IProject findProject(BuildData buildData) { String eclipseProjectName = buildData.getProjectName(); if (Strings.isNullOrEmpty(eclipseProjectName)) { return null; } IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IProject project = root.getProject(eclipseProjectName); // creates a project instance if not existing if (null == project || !project.isAccessible()) { N4JSProjectName n4jsProjectName = new EclipseProjectName(eclipseProjectName).toN4JSProjectName(); final IProject externalProject = externalLibraryWorkspace.getProject(n4jsProjectName); if (null != externalProject && externalProject.exists()) { project = externalProject; } } return project; }
Example 5
Source File: UserLibraryPreferencePage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static IJavaProject createPlaceholderProject() { String name= "####internal"; //$NON-NLS-1$ IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); while (true) { IProject project= root.getProject(name); if (!project.exists()) { return JavaCore.create(project); } name += '1'; } }
Example 6
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 7
Source File: HybridProjectTest.java From thym with Eclipse Public License 1.0 | 5 votes |
private void setupProjectMock() { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject theProject = workspaceRoot.getProject(PROJECT_NAME); HybridProject hProject = HybridProject.getHybridProject(theProject); assertNotNull(hProject); mockProject = spy(hProject); mockEclipseProject = spy(mockProject.getProject()); doReturn(mockEclipseProject).when(mockProject).getProject(); }
Example 8
Source File: ProjectUtils.java From txtUML with Eclipse Public License 1.0 | 5 votes |
/** * Creates project or returns the existing. * * @param name * - The Name of the Project * @return Existing or created project */ public static IProject createProject(String name) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final IProject project = root.getProject(name); if (!project.exists()) { try { project.create(null); } catch (CoreException e) { e.printStackTrace(); } } return project; }
Example 9
Source File: FileEntryTester.java From ice with Eclipse Public License 1.0 | 5 votes |
/** * <p> * This operation checks the project setup of the Item to ensure that * calling the constructor with an IProject and Item.setProject() setup the * project reference such that Item.hasProject() returns true. * </p> * */ @BeforeClass public static void beforeClass() { // Local Declarations IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); URI defaultProjectLocation = null; String separator = System.getProperty("file.separator"); // Setup the project try { // Get the project handle project = workspaceRoot.getProject("itemData"); // If the project does not exist, create it if (!project.exists()) { // Set the location as ${workspace_loc}/ItemTesterWorkspace defaultProjectLocation = new File( System.getProperty("user.home") + separator + "ICETests" + separator + "itemData").toURI(); // Create the project description IProjectDescription desc = ResourcesPlugin.getWorkspace() .newProjectDescription("itemData"); // 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(); } }
Example 10
Source File: ErrorLineMatcher.java From corrosion with Eclipse Public License 2.0 | 5 votes |
@Override public void matchFound(PatternMatchEvent event) { try { int offset = event.getOffset(); int length = event.getLength(); IProcess process = (IProcess) console.getAttribute(IDebugUIConstants.ATTR_CONSOLE_PROCESS); if (process != null) { ILaunch launch = process.getLaunch(); String projectAttribute = RustLaunchDelegateTools.PROJECT_ATTRIBUTE; String launchConfigurationType = launch.getLaunchConfiguration().getType().getIdentifier(); if (launchConfigurationType.equals(RustLaunchDelegateTools.CORROSION_DEBUG_LAUNCH_CONFIG_TYPE)) { // support debug launch configs projectAttribute = ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME; } String projectName = launch.getLaunchConfiguration().getAttribute(projectAttribute, ""); //$NON-NLS-1$ if (projectName.trim().isEmpty()) { return; // can't determine project so prevent error down } IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject myProject = myWorkspaceRoot.getProject(projectName); String errorString = console.getDocument().get(event.getOffset(), event.getLength()); String[] coordinates = errorString.split(":"); //$NON-NLS-1$ IHyperlink link = makeHyperlink(myProject.getFile(coordinates[0]), Integer.parseInt(coordinates[1]), Integer.parseInt(coordinates[2])); console.addHyperlink(link, offset, length); } } catch (BadLocationException | CoreException e) { // ignore } }
Example 11
Source File: UserLibraryWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static IJavaProject createPlaceholderProject() { String name= "####internal"; //$NON-NLS-1$ IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); while (true) { IProject project= root.getProject(name); if (!project.exists()) { return JavaCore.create(project); } name += '1'; } }
Example 12
Source File: PROTEUSModelTester.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(); String separator = System.getProperty("file.separator"); String userDir = System.getProperty("user.home") + separator + "ICETests" + separator + "proteusTesterWorkspace"; // 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("PROTEUS Model Tester: Error! Could not set up project space"); } // Set the global project reference. return; }
Example 13
Source File: VibeKVPairBuilderTester.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; }
Example 14
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 15
Source File: ProjectCreator.java From txtUML with Eclipse Public License 1.0 | 4 votes |
public static void deleteProjectbyName(String projectname) throws CoreException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(projectname); deleteProject(project); }
Example 16
Source File: BatMLModelTester.java From ice with Eclipse Public License 1.0 | 4 votes |
/** * This operation sets up the workspace. */ @BeforeClass public static void beforeTests() { // Local Declarations IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); URI defaultProjectLocation = null; IProject project = null; String projectName = "batMLTesterWorkspace"; String separator = System.getProperty("file.separator"); // Setup the project try { // Get the project handle project = workspaceRoot.getProject(projectName); // If the project does not exist, create it if (!project.exists()) { // Set the location as // ${workspace_loc}/CAEBATModelTesterWorkspace defaultProjectLocation = (new File( System.getProperty("user.home") + separator + "ICETests" + separator + projectName)) .toURI(); // Create the project description IProjectDescription desc = ResourcesPlugin.getWorkspace() .newProjectDescription(projectName); // 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); } // 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; }
Example 17
Source File: IPSWriterTester.java From ice with Eclipse Public License 1.0 | 4 votes |
/** * */ @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; }
Example 18
Source File: CoreTester.java From ice with Eclipse Public License 1.0 | 4 votes |
/** * This is a utility operation that returns the project of the given name * for the test. It removes any old test files from the project . It * attempts to create the project if it does not exist. * * @param name * the name of the project to retrieve from the Workspace * @return the project */ public IProject getProject(String name) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); URI defaultProjectLocation = null; IProject project = null; String separator = System.getProperty("file.separator"); // Setup the project space so that the output file can be checked. System.out.println("CoreTester Workspace Root = " + workspaceRoot.getLocation()); System.out.println("Constructing project " + name); try { // Get the project handle project = workspaceRoot.getProject(name); // If the project does not exist, create it if (!project.exists()) { defaultProjectLocation = (new File(System.getProperty("user.dir") + separator + name)).toURI(); // Create the project description IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(name); // Set the location of the project desc.setLocationURI(defaultProjectLocation); System.out.println("CoreTester Message: " + "Project location is " + desc.getLocationURI()); // 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(); } // Clean out any old test files try { for (IResource resource : project.members()) { resource.delete(true, null); } } catch (CoreException e1) { // Complain e1.printStackTrace(); fail(); } return project; }
Example 19
Source File: TestProject.java From thym with Eclipse Public License 1.0 | 4 votes |
public IProject getProject() { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(projectName); return project; }
Example 20
Source File: ProjectUtils.java From txtUML with Eclipse Public License 1.0 | 2 votes |
/** * @param projectName * - Name of the project * @return a project resource handle * @see IWorkspaceRoot#getProject(String) */ public static IProject getProject(String projectName) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); return root.getProject(projectName); }