DynJS Addon: Develop a JBoss Forge Addon using Javascript



As java developer I continuously searching tools that make easier my daily work. While ago i've started to use JBoss Forge and, for my job, seems the right tool in the right moment.


The tight maven integration, the lot of available wizards has immediately got my attention, but the "best of" for me was the possibility to extend it developing Addon in easy way and sharing them as maven artifacts.


Lately i'm approaching to other programming languages (i'm became a polyglot believer) and in particular i love Javascript, because it could be considered a full-stack language covering either the client-side and server-side programming. 

So i've thought to bring on javascript on JBoss Forge to allow developing an Addon using such programming language more than java, giving the possibility to developers to build, test & share an Addon in quick & easy way without need to compilation and jar packaging

For that purpose I've started a new Open Source project named dynjs-addon and, as name explain, I've chosen to use the Dynjs javascript engine because I consider it like a modernization of the ever-green and well-known Mozilla Rhino.

How to develop Addon in javascript

If you are beginner of developing JBoss Forge Addon please refer to documentation here

1. Install addon (see here)
2. Create a new javascript file myaddon.js following the template here
3. Evaluate such script  using the eval command
forge> eval --script <full script path>
4. Evaluate such script into project scope using the evalinproject command
forge/project> evalinproject --script <full script path>

Within script you have access to all classes available from forge more than the implicit variables 'self' that represent command itself (ie eval or evalinproject) and 'project' in the case that we are using evaluateinproject 

Example below show various possibilities enabled  ( find out here an updated list of  samples )


var String = java.lang.String;
var Boolean = java.lang.Boolean;

print( "addon loaded!");

var input = {};
// initialize an UIInput (String)
input.string0 = self.componentFactory.createInput("string0", String );
input.string0.label = "Give me a string";
input.string0.required = true;
// initialize an UIInput (Boolean)
input.bool0 = self.componentFactory.createInput("bool0", Boolean );
input.bool0.label = "Give me boolean";
input.bool0.DefaultValue = true;

function initializeUI( builder ) {
    for( m in input ) {
        builder.add( input[m] );
    }
}

function execute( context ) {
    return "OK " +  
         input.string0.value +
         " - " +
         input.bool0.value;
}

Finally there are also the possibility to share a javascript module using the command "installmodule" this allow to require such module from any javascript file using the famous require function (see here).

Conclusions

I'll continue to keep addon updated, currently it has been developed on top the release 2.6.0.Final. Below the addon's roadmap


  • Upgrade to Forge 2.7.2.Final
  • Install javascript module from Gist
  • Create of javascript Addon template (ie Wizard)
  • Provide packaging as maven artifact (jar)

Hope that this addon helps you.






Comments

Popular posts from this blog

Google Web Toolkit Vs AngularJS

PlantText: The new "Online" UML Editor powered by PlantUML

PlantUML & Maven - Enrich your project's documentation