Project Extensions (natures) Wizard for NetBeans 5.0

Project Extensions plugin is implementation of project natures for NetBeans 5.0. Project natures extends functionality of NetBeans projects. Currently it consists of these features:

  • Adding new ant tasks to project's build script
  • Specification of ant tasks dependencies in project's build script, for example the ant task is executed before -post-compile task.
  • Extending the classpatpath of project.
  • Allow to either download libraries from remote library repository (for example maven1) or specify root of repository on local filesystem (for example hibernate installation).
  • A project extension is represented with a node in Project Extensions window.
  • Customizer for Project extension
I've already blogged about few Project Extensions ( Test NG, Java HelpSet validation, Emma code coverage). All these extensions were created with Project Extension Wizard.

To create new project extension is very simple with Project Extension Wizard. It will be demonstrated on creating RMI project extension for J2SE project. The Java RMI (Remote Method Invocation) system allows an object running in one Java Virtual Machine (VM) to invoke methods on an object running in another Java VM. It is necessary to generate stub and skeleton classes using rmic compiler to establish connection between client and server parts. The rmic compiler must to be run on compiled class of implementation of RMI object.

At first we create simple J2SE project with modified build script. We add two new ant's tasks to main build script (build.xml in root folder of project) :

  <target name  = "-post-compile" depends  = "rmi-post-compile"/> 
    
     <target name  = "rmi-post-compile" depends  = "-do-compile"> 
         <property name  = "remote.impl.filter" value  = "\*\*/\*RemoteImpl.class"/> 
         <rmic base  = "${build.classes.dir}" includes  = "${remote.impl.filter}"/> 
     </target> 
   
    

The -post-compile ant task is empty because the project extension wizard doesn't copy the standard project ant tasks to the project extension template. We can to create implementation of a RMI service and test it now. We expect that everything is alright.

Now it's time start to create a project extension using project extension wizard:

In the second Panel select the project with modified build script and clicked to Next button. After clicking to Next button Customize Project Extension Panel is shown.

The wizard automatically parses the modified build script and shows all new targets. The -post-compile is not added to table with available ant tasks because more project extensions cannot override the same target. Only dependencies between targets are stored to dependencies table.

If we assign to ant target display name the target will be represented by action in popup of project extension node in Project Extensions window. There is not necessary to change dependencies between targets. It will be usefull for example when dependencies between different Project extensions are defined. Click to next button you can specify classpath for the project extension. The libraries are got from Library manager.

RMI doesn't need extra library on the classpath. Click to Next button to show the last panel of wizard. There can be specified the name, display name, icon, post create action and customizer. The post create action is invoked after adding project extension to project. It is useful for example when it is necessary to initialize some properties. The customizer panel is shown in JDialog when is performed Properties action from project extension node.

After clicking to "Finish" button the Project extension template will be generated.

rmiext.xml - descriptor

 <featuredefs> 
     <featuredef  name =  "RMICompiler"customizerClassRef = "rmiext-RmiextCustomizer.instance"> 
         <title>RMICompiler</title> 
         <icon>rmiext/rmi.png</icon> 
         <project> 
             <type>org.netbeans.modules.java.j2seproject</type> 
         </project> 
         <actions> 
             <anttask> 
                 <name>rmi-post-compile</name> 
                 <title>RMI Compiler</title> 
             </anttask> 
         </actions> 
         <dependsOn> 
             <anttask>rmi-post-compile</anttask> 
             <featureName>org.netbeans.modules.java.j2seproject</featureName> 
             <anttaskInFeature>-do-compile</anttaskInFeature> 
         </dependsOn> 
         <dependsFrom> 
             <anttask>rmi-post-compile</anttask> 
             <featureName>org.netbeans.modules.java.j2seproject</featureName> 
             <anttaskInFeature>-post-compile</anttaskInFeature> 
         </dependsFrom> 
         <usedtargets> 
             <usedtarget>rmi-post-compile</usedtarget> 
         </usedtargets> 
         <velocityTemplate vmFile = "Rmiext.vm"/> 
     </featuredef> 
 </featuredefs> 

rmiext.vm - velocity template
<target name="rmi-post-compile">
  <property name="remote.impl.filter" value="\*\*/\*RemoteImpl.class"/>
  <rmic base="${build.classes.dir}" includes="${remote.impl.filter}"/>
</target>
And references are added to layer.xml
<filesystem> 
     <folder name = "velocity"> 
         <folder name = "build"> 
             <file name = "Rmiext.xml"url = "Rmiext.xml"/> 
         </folder > 
         <folder name = "customizers"> 
             <file name = "rmiext-RmiextCustomizer.instance"/> 
         </folder > 
         <folder name = "templates"> 
             <file name = "Rmiext.vm" url = "Rmiext.vm"/> 
         </folder> 
     </folder> 
 </filesystem>

The project extension was created. No line of of code was written. So we can try to run the module. And Test the nature. The Nature can be added to project from popup in Project Extensions window.

The project extension node is shown bellow.

The RMIC compile is not run either on project building or from RMI Project extension popup.

This wizard is available in NBXdoclet Modules Development plugin. The plugin available on my update center. The NBXdoclet Modules Development plugin depends on NetBeans Module Development Environment U1.

Comments:

Post a Comment:
Comments are closed for this entry.
About

xzajo

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today