Java Code Examples for org.eclipse.core.resources.IWorkspaceRoot#getProjects()

The following examples show how to use org.eclipse.core.resources.IWorkspaceRoot#getProjects() . 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: ProjectLocationAwareWorkingSetManager.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private Multimap<String, IProject> initProjectLocation() {
	final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
	final IProject[] projects = root.getProjects();
	final Multimap<String, IProject> locations = HashMultimap.create();

	// initialize the repository paths
	repositoryPaths = repositoriesProvider.getWorkspaceRepositories().stream()
			.map(r -> r.getDirectory().getParentFile().toPath()).collect(Collectors.toSet());

	for (final IProject project : projects) {
		if (isRemoteEditNature(project)) {
			continue;
		}
		final String pair = getWorkingSetId(project);
		locations.put(pair, project);
	}

	return locations;
}
 
Example 2
Source File: BluemixUtil.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
public static DominoDesignerProject getDesignerProjectFromWorkspace(String nsfName) {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    if (root != null) {
        IProject[] projects = root.getProjects();
        for (int i = 0; i < projects.length; i++) {
            try {
                DominoDesignerProject ddp = (DominoDesignerProject)DominoResourcesPlugin.getDominoDesignerProject(projects[i]);
                if (ddp != null) {
                    String path = ddp.getNsfPath();
                    if (StringUtil.equalsIgnoreCase(path, nsfName)) {
                        return ddp;
                    }
                }
            } catch (NsfException e) {
                if (BluemixLogger.BLUEMIX_LOGGER.isErrorEnabled()) {
                    BluemixLogger.BLUEMIX_LOGGER.errorp(BluemixUtil.class, "getDesignerProjectFromWorkspace", e, "Failed to get Domino Designer Project"); // $NON-NLS-1$ $NLE-BluemixUtil.FailedtogetDominoDesignerProject-2$
                }
            }
        }
    }   
    return null;
}
 
Example 3
Source File: DefaultPathsForInterpreterInfo.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a Set of the root paths of all projects (and the workspace root itself).
 * @return A HashSet of root paths.
 */
public static HashSet<IPath> getRootPaths() {
    HashSet<IPath> rootPaths = new HashSet<IPath>();
    if (SharedCorePlugin.inTestMode()) {
        return rootPaths;
    }
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IPath rootLocation = root.getLocation().makeAbsolute();

    rootPaths.add(rootLocation);

    IProject[] projects = root.getProjects();
    for (IProject iProject : projects) {
        IPath location = iProject.getLocation();
        if (location != null) {
            IPath abs = location.makeAbsolute();
            if (!rootLocation.isPrefixOf(abs)) {
                rootPaths.add(abs);
            }
        }
    }
    return rootPaths;
}
 
Example 4
Source File: BugContentProvider.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Set<IResource> getResources(Object parent) {
    Set<IResource> resources = new HashSet<>();
    if (parent instanceof IWorkingSet) {
        IWorkingSet workingSet = (IWorkingSet) parent;
        IAdaptable[] elements = workingSet.getElements();
        // elements may contain NON-resource elements, which we have to
        // convert to
        // resources
        for (IAdaptable adaptable : elements) {
            IResource resource = (IResource) adaptable.getAdapter(IResource.class);
            // TODO get only java projects or children of them
            if (resource != null) {
                resources.add(resource);
            }
        }
    } else if (parent instanceof IWorkspaceRoot) {
        IWorkspaceRoot workspaceRoot = (IWorkspaceRoot) parent;
        // TODO get only java projects
        IProject[] projects = workspaceRoot.getProjects();
        for (IProject project : projects) {
            resources.add(project);
        }
    }
    return resources;
}
 
Example 5
Source File: EclipseFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@After
public void tearDown() {
  try {
    final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject[] _projects = root.getProjects();
    for (final IProject p : _projects) {
      boolean _remove = this.knownProjects.remove(p.getName());
      boolean _not = (!_remove);
      if (_not) {
        p.delete(true, null);
      }
    }
    Assert.assertTrue(this.knownProjects.isEmpty());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 6
Source File: SVNWorkspaceRoot.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Gets the repository which the local filesystem <code>location</code> belongs to.
   */
  public static ISVNRepositoryLocation getRepositoryFor(IPath location) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject[] projects = root.getProjects();
for (IProject project : projects) {
	if (project.getLocation().isPrefixOf(location) && SVNWorkspaceRoot.isManagedBySubclipse(project)) {
		try {
			SVNTeamProvider teamProvider = (SVNTeamProvider)RepositoryProvider.getProvider(project, SVNProviderPlugin.getTypeId());
			return teamProvider.getSVNWorkspaceRoot().getRepository();
		} catch (SVNException e) {
			// an exception is thrown when resource	is not managed
			SVNProviderPlugin.log(e);
			return null;
		}
	}
}
return null;
  }
 
Example 7
Source File: SVNWorkspaceRoot.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Gets the resources to which the local filesystem <code>location</code> is corresponding to.
   * The resources do not need to exists (yet)
   * @return IResource[]
   * @throws SVNException
   */
  public static IResource[] getResourcesFor(IPath location, boolean includeProjects) {
Set<IResource> resources = new LinkedHashSet<IResource>();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject[] projects = root.getProjects();
for (IProject project : projects) {
	IResource resource = getResourceFor(project, location);
	if (resource != null) {
		resources.add(resource);
	}
	if (includeProjects && isManagedBySubclipse(project) && location.isPrefixOf(project.getLocation())) {
		resources.add(project);
	}
}
return (IResource[]) resources.toArray(new IResource[resources.size()]);
  }
 
Example 8
Source File: PythonNature.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return all the python natures available in the workspace (for opened and existing projects)
 */
public static List<IPythonNature> getAllPythonNatures() {
    List<IPythonNature> natures = new ArrayList<IPythonNature>();
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject[] projects = root.getProjects();
    for (IProject project : projects) {
        PythonNature nature = getPythonNature(project);
        if (nature != null) {
            natures.add(nature);
        }
    }
    return natures;
}
 
Example 9
Source File: IDEClassPathBlock.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private Object[] getNotYetRequiredProjects( ) throws JavaModelException
{
	ArrayList selectable = new ArrayList( );
	IWorkspaceRoot root = ResourcesPlugin.getWorkspace( ).getRoot( );
	IProject[] projects = root.getProjects( );
	for ( int i = 0; i < projects.length; i++ )
	{
		if ( isJavaProject( projects[i] ) )
		{
			selectable.add( JavaCore.create( projects[i] ) );
		}
	}

	if ( isJavaProject( getProject( ) ) )
	{
		selectable.remove( JavaCore.create( getProject( ) ) );
	}
	List elements = fLibrariesList.getElements( );
	for ( int i = 0; i < elements.size( ); i++ )
	{
		IDECPListElement curr = (IDECPListElement) elements.get( i );
		if ( curr.getEntryKind( ) != IClasspathEntry.CPE_PROJECT )
		{
			continue;
		}
		IJavaProject proj = (IJavaProject) JavaCore.create( curr.getResource( ) );
		selectable.remove( proj );
	}
	Object[] selectArr = selectable.toArray( );
	return selectArr;
}
 
Example 10
Source File: OpenTypeAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Opens the new project dialog if the workspace is empty.
 * @param parent the parent shell
 * @return returns <code>true</code> when a project has been created, or <code>false</code> when the
 * new project has been canceled.
 */
protected boolean doCreateProjectFirstOnEmptyWorkspace(Shell parent) {
	IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot();
	if (workspaceRoot.getProjects().length == 0) {
		String title= JavaUIMessages.OpenTypeAction_dialogTitle;
		String message= JavaUIMessages.OpenTypeAction_createProjectFirst;
		if (MessageDialog.openQuestion(parent, title, message)) {
			new NewProjectAction().run();
			return workspaceRoot.getProjects().length != 0;
		}
		return false;
	}
	return true;
}
 
Example 11
Source File: AbstractOpenWizardAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Opens the new project dialog if the workspace is empty. This method is called on {@link #run()}.
 * @param shell the shell to use
 * @return returns <code>true</code> when a project has been created, or <code>false</code> when the
 * new project has been canceled.
 */
protected boolean doCreateProjectFirstOnEmptyWorkspace(Shell shell) {
	IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot();
	if (workspaceRoot.getProjects().length == 0) {
		String title= NewWizardMessages.AbstractOpenWizardAction_noproject_title;
		String message= NewWizardMessages.AbstractOpenWizardAction_noproject_message;
		if (MessageDialog.openQuestion(shell, title, message)) {
			new NewProjectAction().run();
			return workspaceRoot.getProjects().length != 0;
		}
		return false;
	}
	return true;
}
 
Example 12
Source File: SVNWorkspaceRoot.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public static IResource[] getResourcesFor(IResource resource) {
  	Set<IResource> resources = new LinkedHashSet<IResource>();
  	resources.add(resource);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject[] projects = root.getProjects();
for (IProject project : projects) {
	if (!project.getLocation().equals(resource.getLocation()) && resource.getLocation().isPrefixOf(project.getLocation())) {
		resources.add(project);
	}
}
  	return (IResource[]) resources.toArray(new IResource[resources.size()]);
  }
 
Example 13
Source File: ProjectsGroup.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void calculateChildren() {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject[] projects = root.getProjects();
    for (IProject iProject : projects) {
        PythonNature nature = PythonNature.getPythonNature(iProject);
        if (nature != null) {
            addChild(new NatureGroup(this, nature));
        }
    }
}
 
Example 14
Source File: AbstractOpenWizardAction.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Opens the new project dialog if the workspace is empty. This method is
 * called on {@link #run()}.
 * 
 * @param shell the shell to use
 * @return returns <code>true</code> when a project has been created, or
 *         <code>false</code> when the new project has been canceled.
 */
protected boolean doCreateProjectFirstOnEmptyWorkspace(Shell shell) {
  IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
  if (workspaceRoot.getProjects().length == 0) {
    String title = NewWizardMessages.AbstractOpenWizardAction_noproject_title;
    String message = NewWizardMessages.AbstractOpenWizardAction_noproject_message;
    if (MessageDialog.openQuestion(shell, title, message)) {
      new NewProjectAction().run();
      return workspaceRoot.getProjects().length != 0;
    }
    return false;
  }
  return true;
}
 
Example 15
Source File: EclipseWorkspaceConfigurationTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testConfig() throws Exception {
	IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
	for (IProject p : wsroot.getProjects()) {
		p.delete(true, true, null);
	}
	Assert.assertEquals(0, wsroot.getProjects().length);
	IJavaProject project = JavaProjectSetupUtil.createJavaProject("projectA");
	JavaProjectSetupUtil.createJavaProject("projectB");
	EclipseProjectConfig projectConfig = projectConfigProvider.createProjectConfig(project.getProject());
	Assert.assertNotNull(projectConfig);
	Assert.assertNotNull(projectConfig.getWorkspaceConfig().findProjectByName("projectB"));
}
 
Example 16
Source File: JdtUtils.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * List all available Java projects of the specified workspace.
 */
public static List<IJavaProject> listJavaProjects(IWorkspaceRoot workspace) {
    List<IJavaProject> results = new ArrayList<>();
    for (IProject project : workspace.getProjects()) {
        if (isJavaProject(project)) {
            results.add(JavaCore.create(project));
        }
    }
    return results;
}
 
Example 17
Source File: LaunchConfigTab.java    From dartboard with Eclipse Public License 2.0 4 votes vote down vote up
private IProject[] getProjectsInWorkspace() {
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	IWorkspaceRoot root = workspace.getRoot();
	return root.getProjects();
}
 
Example 18
Source File: CloneForeignModelHandler.java    From tlaplus with MIT License 4 votes vote down vote up
private TreeMap<String, TreeSet<Model>> buildMap() {
       final Spec currentSpec = ToolboxHandle.getCurrentSpec();
       if (currentSpec == null) {
       	return null;
       }
       
	final IProject specProject = currentSpec.getProject();
	final TreeMap<String, TreeSet<Model>> projectModelMap = new TreeMap<>();
	
	try {
		final IWorkspace iws = ResourcesPlugin.getWorkspace();
		final IWorkspaceRoot root = iws.getRoot();
		final IProject[] projects = root.getProjects();
		
		for (final IProject project : projects) {
			if (!specProject.equals(project)) {
				projectModelMap.put(project.getName(), new TreeSet<>(MODEL_SORTER));
			}
		}
		
		final String currentProjectName = specProject.getName();
		final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
		final ILaunchConfigurationType launchConfigurationType
				= launchManager.getLaunchConfigurationType(TLCModelLaunchDelegate.LAUNCH_CONFIGURATION_TYPE);
		final ILaunchConfiguration[] launchConfigurations
				= launchManager.getLaunchConfigurations(launchConfigurationType);
		for (final ILaunchConfiguration launchConfiguration : launchConfigurations) {
			final String projectName = launchConfiguration.getAttribute(IConfigurationConstants.SPEC_NAME, "-l!D!q_-l!D!q_-l!D!q_");
			if (!projectName.equals(currentProjectName)) {
				final TreeSet<Model> models = projectModelMap.get(projectName);
				
				if (models != null) {
					final Model model = launchConfiguration.getAdapter(Model.class);
					
					if (!model.isSnapshot()) {
						models.add(model);
					}
				} else {
					TLCUIActivator.getDefault().logError("Could not generate model map for [" + projectName + "]!");
				}
			}
		}
	} catch (final CoreException e) {
		TLCUIActivator.getDefault().logError("Building foreign model map.", e);
		
		return null;
	}
	
	return projectModelMap;
}
 
Example 19
Source File: OutputLocationDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private IContainer chooseOutputLocation() {
	IWorkspaceRoot root= fCurrProject.getWorkspace().getRoot();
	final Class<?>[] acceptedClasses= new Class[] { IProject.class, IFolder.class };
	IProject[] allProjects= root.getProjects();
	ArrayList<IProject> rejectedElements= new ArrayList<IProject>(allProjects.length);
	for (int i= 0; i < allProjects.length; i++) {
		if (!allProjects[i].equals(fCurrProject)) {
			rejectedElements.add(allProjects[i]);
		}
	}
	ViewerFilter filter= new TypedViewerFilter(acceptedClasses, rejectedElements.toArray());

	ILabelProvider lp= new WorkbenchLabelProvider();
	ITreeContentProvider cp= new WorkbenchContentProvider();

	IResource initSelection= null;
	if (fOutputLocation != null) {
		initSelection= root.findMember(fOutputLocation);
	}

	FolderSelectionDialog dialog= new FolderSelectionDialog(getShell(), lp, cp);
	dialog.setTitle(NewWizardMessages.OutputLocationDialog_ChooseOutputFolder_title);

       dialog.setValidator(new ISelectionStatusValidator() {
           ISelectionStatusValidator validator= new TypedElementSelectionValidator(acceptedClasses, false);
           public IStatus validate(Object[] selection) {
               IStatus typedStatus= validator.validate(selection);
               if (!typedStatus.isOK())
                   return typedStatus;
               if (selection[0] instanceof IFolder) {
                   IFolder folder= (IFolder) selection[0];
                   try {
                   	IStatus result= ClasspathModifier.checkSetOutputLocationPrecondition(fEntryToEdit, folder.getFullPath(), fAllowInvalidClasspath, fCPJavaProject);
                   	if (result.getSeverity() == IStatus.ERROR)
                    	return result;
                   } catch (CoreException e) {
                    JavaPlugin.log(e);
                   }
                   return new StatusInfo();
               } else {
               	return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
               }
           }
       });
	dialog.setMessage(NewWizardMessages.OutputLocationDialog_ChooseOutputFolder_description);
	dialog.addFilter(filter);
	dialog.setInput(root);
	dialog.setInitialSelection(initSelection);
	dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));

	if (dialog.open() == Window.OK) {
		return (IContainer)dialog.getFirstResult();
	}
	return null;
}
 
Example 20
Source File: BaseLaunchConfigTab.java    From dartboard with Eclipse Public License 2.0 4 votes vote down vote up
public IProject[] getProjectsInWorkspace() {
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	IWorkspaceRoot root = workspace.getRoot();
	return root.getProjects();
}