X

Geertjan's Blog

  • August 30, 2014

Lazybones Meets NetBeans (Part 1)

Geertjan Wielenga
Product Manager

One of the things I learned about at JCrete is Lazybones, which is a command-line tool, similar to what Grails, Gradle, and Play provide, for bootstrapping new projects.

In particular, Andres Almiray (@aalmiray) is interested in seeing a NetBeans plugin for Lazybones. The starting point for creating such a plugin is to install Lazybones and run it from the command-line, to make sure everything is set up correctly. Once you've done that, the next step is to call the Lazybones command from within NetBeans IDE, i.e., using NetBeans APIs to do so.

Here's how.

import java.io.File;
import org.netbeans.api.extexecution.ExecutionDescriptor;
import org.netbeans.api.extexecution.ExecutionService;
import org.netbeans.api.extexecution.ExternalProcessBuilder;

public class LNBUtils {

    public static void command(String name) {
        ExecutionDescriptor executionDescriptor = new ExecutionDescriptor().
                frontWindow(true).
                controllable(true).
                showProgress(true);
        File userdir = new File(System.getProperty("netbeans.user"));
        ExternalProcessBuilder externalProcessBuilder = new ExternalProcessBuilder("lazybones").
                workingDirectory(userdir).
                addArgument("create").
                addArgument("ratpack-lite").
                addArgument(name);
        ExecutionService service = ExecutionService.newService(
                externalProcessBuilder,
                executionDescriptor,
                "lazybones create ratpack-lite" + name
        );
        service.run();
    }

}

The above has all the commands hard coded. That's a starting point. Later we'll create a wizard so the user can fill in the values and start the process of creating the selected template.

For starters, here's an ActionListener, registered to appear in the File menu, for invoking the above code:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle.Messages;

@ActionID(
        category = "File",
        id = "org.netbeans.lnb.RunLazybones"
)
@ActionRegistration(
        asynchronous = true,
        displayName = "#CTL_RunLazybones"
)
@ActionReference(path = "Menu/File", position = 0)
@Messages("CTL_RunLazybones=Run Lazybones")
public final class RunLazybones implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        String name = "my-rat-app-1";
        LNBUtils.command(name);
    }

}

The result is shown in the Output window:


In the next blog entry in this series, we'll hook the above code into a wizard so the user can fill in the values and start the process of creating new Lazybones projects from a more complex GUI than the menu item defined above.

Want to contribute or follow the project as it develops? Go here:

https://java.net/projects/nb-api-samples/sources/api-samples/show/versions/8.0/LazyNetBeansBones

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.