Skip to content

Custom Project

Marián Labuda edited this page Mar 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 general 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 org.jboss.reddeer.eclipse.core.resources.AbstractProject class containing abstract method getNatureIds. General project does not have any nature, but specific projects (Java, Maven etc.) contains specific natures. Once you implement your own specific project class and add methods which are available only for such project containing the nature, you can be sure that once you get such project via API, it's correct. Imagine, we have implemented MavenProject class and now we want to update dependencies for a specific project:

MavenProject mavenProject = new ProjectExplorer().getProject(projectName, MavenProject.class);
maven.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 and 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.

Clone this wiki locally