Lazybones Meets NetBeans (Part 1)

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

Comments:

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
« July 2015
SunMonTueWedThuFriSat
   
4
7
11
12
20
28
29
30
31
 
       
Today