-
Notifications
You must be signed in to change notification settings - Fork 43
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.
To create Maven project containing additional feature to update project dependencies for a specific project it's required to create MavenProject at first:
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:
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.