Java Code Examples for org.eclipse.core.resources.IProjectDescription#setReferencedProjects()

The following examples show how to use org.eclipse.core.resources.IProjectDescription#setReferencedProjects() . 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: UserJavaProject.java    From CogniCrypt with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @param sourceProject The name of the project to be cloned
 * @param cloneName The name of the cloned project
 * @return a cloned project
 * @throws CoreException
 */

public static IProject cloneProject(final String sourceProject) throws CoreException {
	final IProgressMonitor m = new NullProgressMonitor();
	final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	final IProject project = workspaceRoot.getProject(sourceProject);
	final IProjectDescription projectDescription = project.getDescription();
	final String cloneName = sourceProject + "_copy";
	// create clone project in workspace
	final IProjectDescription cloneDescription = workspaceRoot.getWorkspace().newProjectDescription(cloneName);
	// copy project files
	project.copy(cloneDescription, true, m);
	final IProject clone = workspaceRoot.getProject(cloneName);
	// copy the project properties
	cloneDescription.setNatureIds(projectDescription.getNatureIds());
	cloneDescription.setReferencedProjects(projectDescription.getReferencedProjects());
	cloneDescription.setDynamicReferences(projectDescription.getDynamicReferences());
	cloneDescription.setBuildSpec(projectDescription.getBuildSpec());
	cloneDescription.setReferencedProjects(projectDescription.getReferencedProjects());
	clone.setDescription(cloneDescription, null);
	return clone;
}
 
Example 2
Source File: ProjectFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected IProjectDescription createProjectDescription() {
	final IProjectDescription projectDescription = workspace.newProjectDescription(projectName);
	if (location != null && !Platform.getLocation().equals(location.removeLastSegments(1))) {
		projectDescription.setLocation(location);
	}

	if (referencedProjects != null && referencedProjects.size() != 0) {
		projectDescription
				.setReferencedProjects(referencedProjects.toArray(new IProject[referencedProjects.size()]));
	}
	if (projectNatures != null)
		projectDescription.setNatureIds(projectNatures.toArray(new String[projectNatures.size()]));
	if (builderIds != null)
		setBuilder(projectDescription, builderIds.toArray(new String[builderIds.size()]));
	return projectDescription;
}
 
Example 3
Source File: ExampleImporter.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public IProject importExample(ExampleData edata, IProgressMonitor monitor) {
	try {
		IProjectDescription original = ResourcesPlugin.getWorkspace()
				.loadProjectDescription(new Path(edata.getProjectDir().getAbsolutePath()).append("/.project"));
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(edata.getProjectDir().getName());

		IProjectDescription clone = ResourcesPlugin.getWorkspace().newProjectDescription(original.getName());
		clone.setBuildSpec(original.getBuildSpec());
		clone.setComment(original.getComment());
		clone.setDynamicReferences(original.getDynamicReferences());
		clone.setNatureIds(original.getNatureIds());
		clone.setReferencedProjects(original.getReferencedProjects());
		if (project.exists()) {
			return project;
		}
		project.create(clone, monitor);
		project.open(monitor);

		@SuppressWarnings("unchecked")
		List<IFile> filesToImport = FileSystemStructureProvider.INSTANCE.getChildren(edata.getProjectDir());
		ImportOperation io = new ImportOperation(project.getFullPath(), edata.getProjectDir(),
				FileSystemStructureProvider.INSTANCE, new IOverwriteQuery() {

					@Override
					public String queryOverwrite(String pathString) {
						return IOverwriteQuery.ALL;
					}

				}, filesToImport);
		io.setOverwriteResources(true);
		io.setCreateContainerStructure(false);
		io.run(monitor);
		project.refreshLocal(IProject.DEPTH_INFINITE, monitor);
		return project;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 4
Source File: AbstractWorkbenchTestCase.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets the referenced projects for project as being the javaProject passed.
 */
protected void setProjectReference(IProgressMonitor monitor, IProject project, IJavaProject javaProject)
        throws CoreException {
    IProjectDescription description = project.getDescription();
    description.setReferencedProjects(new IProject[] { javaProject.getProject() });
    project.setDescription(description, monitor);
}
 
Example 5
Source File: PyStructureConfigHelpers.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new project resource with the entered name.
 * 
 * @param projectName The name of the project
 * @param projectLocationPath the location for the project. If null, the default location (in the workspace)
 * will be used to create the project.
 * @param references The projects that should be referenced from the newly created project
 * 
 * @return the created project resource, or <code>null</code> if the project was not created
 * @throws CoreException 
 * @throws OperationCanceledException 
 */
public static IProject createPydevProject(String projectName, IPath projectLocationPath, IProject[] references,

        IProgressMonitor monitor, String projectType, String projectInterpreter,
        ICallback<List<IContainer>, IProject> getSourceFolderHandlesCallback,
        ICallback<List<String>, IProject> getExternalSourceFolderHandlesCallback,
        ICallback<List<IPath>, IProject> getExistingSourceFolderHandlesCallback,
        ICallback<Map<String, String>, IProject> getVariableSubstitutionCallback)
        throws OperationCanceledException, CoreException {

    // get a project handle
    final IProject projectHandle = getProjectHandle(projectName);

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProjectDescription description = workspace.newProjectDescription(projectHandle.getName());
    description.setLocation(projectLocationPath);

    // update the referenced project if provided
    if (references != null && references.length > 0) {
        description.setReferencedProjects(references);
    }

    createPydevProject(description, projectHandle, monitor, projectType, projectInterpreter,
            getSourceFolderHandlesCallback, getExternalSourceFolderHandlesCallback,
            getExistingSourceFolderHandlesCallback, getVariableSubstitutionCallback);
    return projectHandle;
}
 
Example 6
Source File: TwoProjectsTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected void addProjectReference(IProject from, IProject referencedProject) throws CoreException {
	IProjectDescription description = from.getDescription();
	description.setReferencedProjects(new IProject[] { referencedProject });
	from.setDescription(description, null);
}
 
Example 7
Source File: TwoProjectsTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected void removeProjectReference(IProject from) throws CoreException {
	IProjectDescription description = from.getDescription();
	description.setReferencedProjects(new IProject[0]);
	from.setDescription(description, null);
}