Groovy Generation of Modular Desktop Applications

I came across a rather cool blog entry today (via the always excellent http://groovyblogs.org/), ICEFaces Project Generation Using Groovy, by Rob Mayhew. Very cool that he included all his code. A few tweaks later I was able to generate a new NetBeans Platform application from Groovy:
package generators

def folder = "/home/geertjan/Desktop/wonderful";
def name = "MyWonderfulApplication";

println "Generating project ${name} in folder ${folder}";

def build = """\\
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
<!-- for some information on what you could do (e.g. targets to override). -->
<!-- If you delete this file and reopen the project it will be recreated. -->
<project name="${name}" basedir=".">
    <description>Builds the module suite ${name}.</description>
    <import file="nbproject/build-impl.xml"/>
</project>

"""
def build_impl_xml = """\\
<?xml version="1.0" encoding="UTF-8"?>
<!--
\*\*\* GENERATED FROM project.xml - DO NOT EDIT  \*\*\*
\*\*\*         EDIT ../build.xml INSTEAD         \*\*\*
-->
<project name="${name}-impl" basedir=".." xmlns:sproject="http://www.netbeans.org/ns/nb-module-suite-project/1">
    <property file="nbproject/private/platform-private.properties"/>
    <property file="nbproject/platform.properties"/>
    <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-suite-project/1">
        <attribute name="name"/>
        <attribute name="value"/>
        <sequential>
            <property name="@{name}" value="\\${@{value}}"/>
        </sequential>
    </macrodef>
    <property file="\\${user.properties.file}"/>
    <sproject:property name="harness.dir" value="nbplatform.\\${nbplatform.active}.harness.dir"/>
    <sproject:property name="netbeans.dest.dir" value="nbplatform.\\${nbplatform.active}.netbeans.dest.dir"/>
    <fail message="You must define 'nbplatform.\\${nbplatform.active}.harness.dir'">
        <condition>
            <not>
                <available file="\\${harness.dir}" type="dir"/>
            </not>
        </condition>
    </fail>
    <import file="\\${harness.dir}/suite.xml"/>
</project>

"""
def platform_properties = """\\
disabled.clusters=\\
    apisupport1,\\
    enterprise5,\\
    groovy1,\\
    gsf1,\\
    harness,\\
    ide10,\\
    java2,\\
    nb6.5,\\
    profiler3,\\
    visualweb2,\\
    webcommon1,\\
    websvccommon1,\\
    xml2
disabled.modules=\\
    org.netbeans.libs.jsr223,\\
    org.openide.compat,\\
    org.netbeans.modules.autoupdate.services,\\
    org.netbeans.api.visual,\\
    org.netbeans.core.execution,\\
    org.netbeans.core.multiview,\\
    org.openide.execution,\\
    org.openide.options,\\
    org.netbeans.modules.favorites,\\
    org.netbeans.modules.templates,\\
    org.netbeans.modules.autoupdate.ui,\\
    org.openide.util.enumerations,\\
    org.netbeans.modules.core.kit
enabled.clusters=\\
    platform9
nbplatform.active=default

"""
def project_properties = """\\

app.name=token
app.title=${name}
branding.token=\\${app.name}
modules=

"""
def project_xml = """\\
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
    <type>org.netbeans.modules.apisupport.project.suite</type>
    <configuration>
        <data xmlns="http://www.netbeans.org/ns/nb-module-suite-project/1">
            <name>${name}</name>
        </data>
    </configuration>
</project>

"""
def base = new File(folder);
base.mkdirs();
def nbproject = new File(folder + File.separator + "nbproject");
nbproject.mkdirs();
new File(folder + File.separator  +"build.xml").write(build);
new File(folder + File.separator + "nbproject" + File.separator + "build-impl.xml").write(build_impl_xml);
new File(folder + File.separator + "nbproject" + File.separator + "platform.properties").write(platform_properties);
new File(folder + File.separator + "nbproject" + File.separator + "project.properties").write(project_properties);
new File(folder + File.separator + "nbproject" + File.separator + "project.xml").write(project_xml);

println("Done.")

Rather wonderfully, running the above script will give you a NetBeans project which, when you open it, will give you this:

That's a NetBeans Platform application which, when deployed, gives you this:

Now... imagine that you were to create different Groovy scripts, each providing different starting points for developing an application on the NetBeans Platform. One Groovy script would provide the application above, i.e., the same as you get via the NetBeans Platform Application wizard in the New Project dialog. Another one, however, could include a few basic modules that provide a more fleshed out layout. Or maybe you'd like to have the Plugin Manager available by default? Simply tweak the script to include the applicable modules, which you could simulate via the ui in the IDE and then copy the generated tags over to your Groovy script. In the end, you'd never need to go through a template in the IDE again, because you could, in the blink of an eye, generate everything you need via Groovy. And the script could be run, of course, from within the IDE.

Comments:

Hey...I like that idea. I may have to give it a try. I just nabbed the latest NetBeans and am digging it. This could prove to be pretty valuable.

Thanks

Posted by lifewithryan on July 29, 2008 at 02:35 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today