Gogo Shell Command

The Gogo Shell Command sample demonstrates adding a custom command to Liferay DXP’s Gogo shell environment. All Liferay DXP installations have a Gogo shell environment, which lets system administrators interact with Liferay DXP’s module framework on a local server machine.

This example adds a new custom Gogo shell command called usercount under the blade scope. It prints out the number of registered users on your Liferay DXP installation.

To test this sample, follow the instructions below:

  1. Start a Liferay DXP installation.

  2. Navigate to the Control Panel → ConfigurationGogo Shell.

  3. Execute help to view all the available commands. The sample Gogo shell command is listed.

    Figure 1: The sample Gogo shell command is listed with all the available commands.

    Figure 1: The sample Gogo shell command is listed with all the available commands.

  4. Execute usercount to execute the new custom command. The number of users on your running Liferay Portal installation is printed.

    Figure 2: The outcome of executing the usercount command.

    Figure 2: The outcome of executing the `usercount` command.

What API(s) and/or code components does this sample highlight?

This sample demonstrates creating a new Gogo shell command by leveraging osgi.command.* properties in a Java class.

How does this sample leverage the API(s) and/or code component?

To add this new Gogo shell command, you must implement the logic in a Java class with the following two properties:

  • osgi.command.function: the command’s name, which must match the method name in the registered service implementation.
  • osgi.command.scope: the general scope or namespace for the command.

These properties are set in your class’s @Component annotation like this:

    property = {"osgi.command.function=usercount", "osgi.command.scope=blade"},
    service = Object.class

The logic for the usercount command is specified in the method with the same name:

public void usercount() {
        "# of users: " + getUserLocalService().getUsersCount());

This method uses Declarative Services to get a reference for the UserLocalService to invoke the getUsersCount method. This lets you find the number of users currently in the system.

For more information on using the Gogo shell, see the Using the Felix Gogo Shell tutorial.

Where Is This Sample?

There are three different versions of this sample, each built with a different build tool:

« Document ActionIndex Settings Contributor »
¿Fue útil este artículo?
Usuarios a los que les pareció útil: 0 de 0