Defining the Project Nature
An important aspect of creating a new artifact is defining the project nature. Project natures act as tags on a project to indicate that a certain tool is used to operate on that project. They can also be used to distinguish projects that your plug-in is interested in, from the rest of the projects in the workspace. For example, natures can be used to filter declarative extensions that operate only on projects of a particular type.
Another reason for using natures is to make use of the nature lifecycle methods when your plug-in is connected to or disconnected from a project. When a nature is added to a project for the first time, the nature’s configure method is called. When the nature is removed from the project, the de-configure method is called. This is an opportunity to initialize metadata on the project and to associate additional attributes, such as builders, with the project. Therefore, it is important that you define your own project nature in the plug-in that creates the particular artifact projects and include that nature in the .project
file of the projects created using the plug-in.
An in-built Eclipse extension point exists to introduce a project nature and can be implemented in the plugin.xml
file of your plug-in as follows:
<extension point="org.eclipse.core.resources.natures" id="org.wso2.developerstudio.eclipse.artifact.mediator.project.nature" name="Mediator Project Nature"> <runtime> <run class="org.wso2.developerstudio.eclipse.artifact.mediator.project.nature.CustomMediatorProjectNature"> </run> </runtime> </extension>
Apart from the plug-in project natures, you need make sure that it contains other relevant project natures as well, for example the custom mediator project, which is a java project, should also contain the java project nature. A sample .projec
t file which should be generated in the custom mediator project, that is created through our plugin is as follows:
<?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>SampleMediator</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.wso2.developerstudio.eclipse.artifact.mediator.project.nature</nature> <nature>org.eclipse.jdt.core.javanature</nature> </natures> </projectDescription>