Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Custom Project

Marián Labuda edited this page May 20, 2015 · 18 revisions

Custom Project

RedDeer allows you to get and work with a new Project, which is accessible via Package Explorer, Project Explorer, Resource Navigator or any other view displaying workspace. To get any project from one of those views you can use following code:

Project generalProject = new ProjectExplorer().getProject(projectName);
In some occasions it's desired to add additional functionality to a specific project. One of those cases could be having a maven project where user wants to update dependencies of a project. To accomplish this it is required to extend _AbstractProject_ class containing abstract method _getNatureIds()_. General project does not have any nature, but specific projects (Java, Maven etc.) contains specific natures. 

### Create Maven project
To create Maven project containing additional feature to update project dependencies for a specific project it's required to create MavenProject at first:
```java
public class MavenProject extends AbstractProject {

	public MavenProject(TreeItem item) {
		super(item);
	}
	
	@Override
	public String[] getNatureIds() {
		return new String[] {"org.eclipse.m2e.core.maven2Nature"};
	}

	public void updateDependencies() {
		...
	}
}
```

Once MavenProject class exists, it is possible to get such projects via Project explorer view and update its dependencies as needed:
```java
MavenProject mavenProject = 
        new ProjectExplorer().getProject(projectName, MavenProject.class);
mavenProject.updateDependencies();
```

Advantage of this approach is that if the project you are trying to get does not contain required nature, you will not be able to get such project. EclipseLayerException is going to be thrown with message to warn you that project does not contain required nature. It makes it easier to find issues with project natures much sooner and you can be fully sure that the project has a specific nature.
Clone this wiki locally