Hands-on with Eclipse Che: Simplify Command Configuration

Tyler Jewell
Eclipse Che Blog
Published in
2 min readMay 19, 2016

Eclipse Che enables users to execute an arbitrary command on Workspace Agent by creating a custom command with Run -> Edit Commands… menu item and typing an arbitrary command in multi-line text area. This process works best for simple, one-off commands, but can be painful for ones with several parameters. For the more complicated cases, Eclipse Che’s Command Configuration API allows you to describe a way of configuring your command.

This post will demonstrate how to simplify configuring commands to launch Tomcat server and deploy web applications.

Che-command-definition

CommandType

First, you need to provide general information that is common for all commands of your type. By implementing CommandType interface, you should provide:

  • Unique command type identifier which will be used internally;
  • Command type’s display name which will be shown in Commands dialog;
  • Implementation of the page for configuring command type-specific parameters;
  • Algorithm of creating (deserializing) a command from command line into CommandConfiguration object;
  • Command template that will be used for every newly created command.

Let’s create TomcatCommandType class.

CommandConfiguration

Let’s create a model object for your command by extending CommandConfiguration class.

CommandConfigurationPage

In order to allow a user to edit some part of your command, you need to create a special page that will be used in the Commands dialog for editing Tomcat command. Let’s create a page for editing only one command’s parameter — Deployment artifact.

And create a view for the page.

CommandConfigurationFactory

Now you need to describe how the serialized command should be transformed into a TomcatCommandConfiguration model object.

Registering your command type

TomcatCommandType should be registered using a GIN multibinder in order to be picked-up on loading Che.

GinMultibinder.newSetBinder(binder(), CommandType.class).addBinding().to(TomcatCommandType.class);

Now, you can build a Che assembly with this Tomcat plugin to check how it works.

Create a new project from web-java-spring sample and build it with Maven command. Then create your ‘Tomcat deploy’ command:

Che-registering-command

Executing it will copy the specified deployment artifact to Tomcat’s webapps directory and launches the Tomcat server. You can stop running the Tomcat server with the stop button and redeploy your app after modifications.

Che-deploy-command

See the full code of this Tomcat extension here.

--

--

Tyler Jewell
Eclipse Che Blog

MD @ Dell Tech Capital. BOD @ NS1, Orion Labs. Prev: CEO @ WSO2, CEO @ Codenvy (acq. by RHT). Invest @ Sauce Labs, Cloudant, ZeroTurnaround, InfoQ, Sourcegraph.