Using the Felix Gogo Shell

Content

  1. Using the Felix Gogo Shell
    1. Content
    2. Commands
    3. Migrating from Equinox Console
    4. Defining the Command Context Class
    5. Defining the Commands
      1. Command Method and Simple Parameter Description
      2. Describing Parameter with in Detail

Commands

Commands in Gogo are provided in a so called command scope which will be used as prefix of a command, i.e. scope:command. Commands of a scope must be provided by a service component, i.e. ROOTS service components.

Migrating from Equinox Console

For migration from Equinox to Gogo Shell a supporting classes are provided in bundle biz.kachel.roots.gogo.util. It provides the classes CommandInterpreter and CommandProvider in the ROOTS way. To use them change import paths and solve remaining problems according the implementation line below.

In the constructor of the class implementing the console add the following:


    this.ci = new CommandInterpreter();

In addition remove the command interpreter parameter from each command method.
Change the method name by removing beginning underline.
Remove the getHelp() method.
Proceed with the steps in the next sections.

Feel free to extend the bundle biz.kachel.roots.gogo.util by more supporting functionality.

Defining the Command Context Class

The command context class has to be annotated:


@Component
public Class MyCommands

In the activator of the bundle the command service must be instantiated by providing a set of properties:


public class Activator extends AECPServiceActivator {

	public Activator() {
		super();
        Hashtable<String, Object> props = new Hashtable<>();
        props.put("osgi.command.scope", "myscope");
        props.put("osgi.command.function", new String[] {
            "mycommand1", "mycommand2", ... });
        this.instantiate(MyCommand.class, props);
        ...
	}
	
	...

}

Defining the Commands

Each command is a (void) method in your command class. Each command listed in the properties above must have an implemetation method with the same name. Methods and their parameters represent a commands. The mapping is done using reflection and annotation. Furthermore, the annotations provide the help text of the commands.
According this is straight forward examples will be given using one of the Gogo basic commands.

Command Method and Simple Parameter Description


    @Descriptor("set framework active start level")
    public void frameworklevel(@Descriptor("target start level") int level)

For using command method annotations the following package import is required in bundle Manifest:
org.apache.felix.service.command;status=provisional;version="0.10.0"

Describing Parameter with in Detail


    @Descriptor("set bundle start level or initial bundle start level")
    public void bundlelevel(
        @Descriptor("set the bundle's start level") @Parameter(names = { "-s",
                "--setlevel" }, presentValue = "true", absentValue = "false") boolean set,
        @Descriptor("set the initial bundle start level") @Parameter(names = { "-i",
                "--setinitial" }, presentValue = "true", absentValue = "false") boolean initial,
        @Descriptor("target level") int level,
        @Descriptor("target identifiers") Bundle[] bundles)