Java Code Examples for org.eclipse.core.resources.IProject#members()

The following examples show how to use org.eclipse.core.resources.IProject#members() . 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: JavaWorkingSetPageContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object[] getChildren(Object parentElement) {
	try {
		if (parentElement instanceof IJavaModel)
			return concatenate(super.getChildren(parentElement), getNonJavaProjects((IJavaModel)parentElement));

		if (parentElement instanceof IProject) {
			IProject project= (IProject) parentElement;
			if (project.isAccessible()) {
				return project.members();
			}
			return NO_CHILDREN;
		}
		return super.getChildren(parentElement);
	} catch (CoreException e) {
		return NO_CHILDREN;
	}
}
 
Example 2
Source File: BonitaExplorerContentProvider.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object[] getChildren(Object parentElement) {
    if (UIDArtifactFilters.isUIDArtifact(parentElement)) {
        return new Object[0];
    }
    if (parentElement instanceof IFolder && isEnvironmentsFolder((IFolder) parentElement)) {
        return addLocalEnvironment(parentElement);
    }
    
    Object[] children = super.getChildren(parentElement);
    if (parentElement instanceof IProject && children.length == 0) {
        IProject project = (IProject) parentElement;
        if (project.isAccessible()) {
            try {
                return project.members();
            } catch (CoreException e) {
                return NO_CHILDREN;
            }
        }
    }
    return children;
}
 
Example 3
Source File: PythonExistingSourceGroup.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Tell this group what the active project is. Doing so will update its list of linked source paths
 * that are already included in the project, which is necessary for proper conflict-checking. 
 * @param project
 */
public void setActiveProject(IProject project) {
    if (iProject == project) {
        return;
    }

    iProject = project;
    projectLinkTargets.clear();

    if (project != null) {
        try {
            IResource[] members = project.members();
            for (IResource member : members) {
                if (member.isLinked()) {
                    projectLinkTargets.add(member.getLocation());
                }
            }
        } catch (CoreException e) {
            Log.log(e);
        }
        conflictCheck();
    }
}
 
Example 4
Source File: XMLPersistenceProviderTester.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This is a private utility operation used by the tests.
 * 
 * @param name
 *            the name that the resource should have
 * @param projectToCheck
 *            The project to check
 * @return true if the file was found, false if not
 */
private boolean checkPersistedFile(String name, IProject projectToCheck) {

	System.out.println("XMLPersistenceProviderTester Message: "
			+ "Searching for " + name);

	try {
		// Get the list of resources
		IResource[] resources = projectToCheck.members();
		// Check the list and make sure the file was stored
		for (IResource resource : resources) {
			System.out.println("XMLPersistenceProviderTester Message: "
					+ "Found resource " + resource.getName());
			if (resource.getName().equals(name)) {
				return true;
			}
		}
	} catch (CoreException e) {
		// Complain
		e.printStackTrace();
		fail();
	}

	return false;
}
 
Example 5
Source File: JavaEditorBreadcrumb.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean hasChildren(Object element) {
	if (element instanceof IProject) {
		IProject project= (IProject) element;
		if (!project.isAccessible()) {
			return false;
		}
		try {
			return project.members().length > 0;
		} catch (CoreException e) {
			JavaPlugin.log(e);
		}
		return false;
	} else {
		return fParent.hasChildren(element);
	}
}
 
Example 6
Source File: PackageExplorerContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object[] getChildren(Object parentElement) {
	try {
		if (parentElement instanceof IJavaModel)
			return concatenate(getJavaProjects((IJavaModel)parentElement), getNonJavaProjects((IJavaModel)parentElement));

		if (parentElement instanceof PackageFragmentRootContainer)
			return getContainerPackageFragmentRoots((PackageFragmentRootContainer)parentElement);

		if (parentElement instanceof IProject) {
			IProject project= (IProject) parentElement;
			if (project.isAccessible())
				return project.members();
			return NO_CHILDREN;
		}

		return super.getChildren(parentElement);
	} catch (CoreException e) {
		return NO_CHILDREN;
	}
}
 
Example 7
Source File: MSyncWizardFilePage.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This methods searches for all Bib-Files.
 * For each Bib-File a WorkspaceBibTexEntry will be created/updated.
 * In order to do that the content of each Bib-File will be parsed
 * with the JBibTeX Library and put into the WorkspaceBibTexEntry
 */
private void createWorkspaceContent(){
	IWorkspace workspace = ResourcesPlugin.getWorkspace();

	for(IProject project : workspace.getRoot().getProjects()){
		try {
			for(IResource resource :project.members()){
				if(resource.getFileExtension().equals("bib")){
					URI uri = resource.getLocationURI();
					WorkspaceBibTexEntry entry = new WorkspaceBibTexEntry(uri, project);
					wm.updateFileBibTex(entry);
				}
			}
		} catch (CoreException e) {
			e.printStackTrace();
		}
	}
}
 
Example 8
Source File: MetainformationEditor.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets bibtex documents and taxonomy input argument's resources as active
 * elements in ModelRegistry
 * 
 * @param project
 *            project whose workspace is searched for resources whose file
 *            extensions are checked. Matching .taxonomy and .bib-files are
 *            loaded in the ModelRegistry
 */
private void initializeWholeProject(IProject project) {
	initializeEditingDomain();

	if (project.isOpen()) {
		IResource[] resources = null;
		try {
			resources = project.members();
		} catch (CoreException e) {
			e.printStackTrace();
			return;
		}
		for (IResource res : resources) {
			if (res.getType() == IResource.FILE && "bib".equals(res.getFileExtension())) {
				URI uri = URI.createURI(((IFile) res).getFullPath().toString());
				editingDomain.getResourceSet().getResource(uri, true);
			} else if (res.getType() == IResource.FILE && "taxonomy".equals(res.getFileExtension())) {
				ModelRegistryPlugin.getModelRegistry().setTaxonomyFile((IFile) res);

			}
		}
	}
}
 
Example 9
Source File: EclipseUtils.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
public static List<IFile> listProjectFiles(IProject project) {
	List<IFile> files = new LinkedList<>();
	if (project == null)
		return files;

	try {
		for (IResource resource : project.members()) {
			if (resource instanceof IFile) {
				files.add((IFile) resource);
			}
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}

	return files;
}
 
Example 10
Source File: BibtexEntryView.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * register the resources of a project at the editing domain.
 * 
 * @param project
 */
private void registerResources(IProject project) {
	IResource[] resources = null;
	try {
		resources = project.members();
	} catch (CoreException e) {
		e.printStackTrace();
		return;
	}

	for (IResource res : resources) {
		if (res.getType() == IResource.FILE && "bib".equals(res.getFileExtension())) {
			URI uri = URI.createURI(((IFile) res).getFullPath().toString());
			editingDomain.getResourceSet().getResource(uri, true);
		} else if (res.getType() == IResource.FILE && "taxonomy".equals(res.getFileExtension())) {
			ModelRegistryPlugin.getModelRegistry().setTaxonomyFile((IFile) res);
		}
	}
}
 
Example 11
Source File: IsDartProjectPropertyTester.java    From dartboard with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
	if (IS_DART_PROJECT_PROPERTY.equals(property)) {
		IResource resource = Adapters.adapt(receiver, IResource.class);
		if (resource == null) {
			return false;
		}

		IProject project = resource.getProject();
		if (project == null) {
			return false;
		}
		if (project.findMember(GlobalConstants.PUBSPEC_YAML) != null) {
			return true;
		}

		try {
			for (IResource res : project.members()) {
				if ("dart".equals(res.getFileExtension())) { //$NON-NLS-1$
					return true;
				}
			}
		} catch (CoreException e) {
			LOG.log(DartLog.createError("Couldn't list members of project " + project.getName(), e)); //$NON-NLS-1$
		}
	}

	return false;
}
 
Example 12
Source File: ExternalFoldersManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void cleanUp(IProgressMonitor monitor) throws CoreException {
	ArrayList toDelete = getFoldersToCleanUp(monitor);
	if (toDelete == null)
		return;
	for (Iterator iterator = toDelete.iterator(); iterator.hasNext();) {
		Map.Entry entry = (Map.Entry) iterator.next();
		IFolder folder = (IFolder) entry.getValue();
		folder.delete(true, monitor);
		IPath key = (IPath) entry.getKey();
		this.folders.remove(key);
	}
	IProject project = getExternalFoldersProject();
	if (project.isAccessible() && project.members().length == 1/*remaining member is .project*/)
		project.delete(true, monitor);
}
 
Example 13
Source File: ExternalFoldersManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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: ReportAdvancedLauncherTab.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private List getReportDesignFileFromProject( IProject project )
{
	List retValue = new ArrayList( );
	try
	{
		IResource[] resources = project.members( );
		if ( resources != null && resources.length > 0 )
		{
			List extesionNameList = ReportPlugin.getDefault( )
					.getReportExtensionNameList( );
			for ( int i = 0; i < resources.length; i++ )
			{
				IResource resource = resources[i];
				// System.out.println(resource.getFullPath(
				// ).toPortableString( ));
				if ( extesionNameList.contains( resource.getFileExtension( ) ) )
				{
					retValue.add( resource );
				}
			}
		}
	}
	catch ( CoreException e )
	{
		logger.log( Level.SEVERE, e.getMessage( ), e );
	}
	return retValue;
}
 
Example 15
Source File: LibraryProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private ArrayList getProjectLibraryList( ) throws CoreException
{
	IEditorPart editor = UIUtil.getActiveEditor( true );
	if ( editor != null )
	{
		IFile file = ( (IFileEditorInput) editor.getEditorInput( ) ).getFile( );
		IProject project = file.getProject( );
		IResource[] resources = project.members( );
		return buildLibraryList( resources );
	}
	return null;
}
 
Example 16
Source File: Tester.java    From aCute with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean isDotnetProject(IProject p) {
	if (p == null || !p.isAccessible()) {
		return false;
	}
	try {
		for (IResource projItem : p.members()) {
			if (projItem.getName().equals("project.json") || projItem.getName().matches("^.*\\.csproj$")) { //$NON-NLS-1$ //$NON-NLS-2$
				return true;
			}
		}
	} catch (CoreException e) {
	}
	return false;
}
 
Example 17
Source File: CoreTester.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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 18
Source File: PartialBuildAction.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
    * 
 */
public void run(IAction action) {
    
       String value = action.isChecked() ? "true" : null;
       IProject project = ((FileEditorInput)editor.getEditorInput()).getFile().getProject();
       TexlipseProperties.setProjectProperty(project, TexlipseProperties.PARTIAL_BUILD_PROPERTY, value);
       if (value == null) {
           TexlipseProperties.setSessionProperty(project, TexlipseProperties.PARTIAL_BUILD_FILE, null);
           // delete all tempPartial0000 files
           try {
               IResource[] res;
               IFolder projectOutputDir = TexlipseProperties.getProjectOutputDir(project);
               if (projectOutputDir != null)
                   res = projectOutputDir.members();
               else
                   res = project.members();
               for (int i = 0; i < res.length; i++) {
                   if (res[i].getName().startsWith("tempPartial0000"))
                       res[i].delete(true, null);
               }
               
               IFolder projectTempDir = TexlipseProperties.getProjectTempDir(project);
               if (projectTempDir != null && projectTempDir.exists())
                   res = projectTempDir.members();
               else
                   res = project.members();
               
               for (int i = 0; i < res.length; i++) {
                   if (res[i].getName().startsWith("tempPartial0000"))
                       res[i].delete(true, null);
               }
               IContainer sourceDir = TexlipseProperties.getProjectSourceDir(project);
               res = sourceDir.members();
               for (int i = 0; i < res.length; i++) {
                   if (res[i].getName().startsWith("tempPartial0000"))
                       res[i].delete(true, null);
               }

           } catch (CoreException e) {
               TexlipsePlugin.log("Error while deleting temp files", e);
           }
       }
}
 
Example 19
Source File: PyDevBuilder.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Processes all python files.
 *
 * @param monitor
 */
private void performFullBuild(IProgressMonitor monitor) throws CoreException {
    IProject project = getProject();

    //we need the project...
    if (project != null) {
        IPythonNature nature = PythonNature.getPythonNature(project);

        //and the nature...
        if (nature != null && nature.startRequests()) {
            nature.updateMtime();

            try {
                IPythonPathNature pythonPathNature = nature.getPythonPathNature();
                pythonPathNature.getProjectSourcePath(false); //this is just to update the paths (in case the project name has just changed)

                List<IFile> resourcesToParse = new ArrayList<IFile>();

                List<PyDevBuilderVisitor> visitors = getVisitors();
                try (AutoCloseable closable = withStartEndVisitingNotifications(visitors, monitor, true, nature)) {
                    monitor.beginTask("Building...", (visitors.size() * 100) + 30);

                    IResource[] members = project.members();

                    if (members != null) {
                        // get all the python files to get information.
                        int len = members.length;
                        for (int i = 0; i < len; i++) {
                            try {
                                IResource member = members[i];
                                if (member == null) {
                                    continue;
                                }

                                if (member.getType() == IResource.FILE) {
                                    addToResourcesToParse(resourcesToParse, (IFile) member, nature);

                                } else if (member.getType() == IResource.FOLDER) {
                                    //if it is a folder, let's get all python files that are beneath it
                                    //the heuristics to know if we have to analyze them are the same we have
                                    //for a single file
                                    List<IFile> files = PyFileListing.getAllIFilesBelow((IFolder) member);

                                    for (IFile file : files) {
                                        if (file != null) {
                                            addToResourcesToParse(resourcesToParse, file, nature);
                                        }
                                    }
                                } else {
                                    if (DEBUG) {
                                        System.out.println("Unknown type: " + member.getType());
                                    }
                                }
                            } catch (Exception e) {
                                // that's ok...
                            }
                        }
                        monitor.worked(30);
                        buildResources(resourcesToParse, monitor, visitors);
                    }
                } catch (Exception e1) {
                    Log.log(e1);
                }

            } finally {
                nature.endRequests();
            }
        }
    }
    monitor.done();

}