Thanks for your answer, but I think I came up with something that might fit
my setup a bit more, maybe you can tell.

I've added the dependency to

    <dependency>
      <groupId>org.apache.felix</groupId>
      <artifactId>org.apache.felix.gogo.runtime</artifactId>
      <version><timeofwriting=0.10.0></version>
    </dependency>

And then, in my component, did the following in the @Activate method:

...
    private Set<ServiceRegistration> regs = new
HashSet<ServiceRegistration>();
    protected BundleContext context;

    @Activate
    void start(BundleContext context) {
      this.context = context;

      Hashtable dict = new Hashtable();
      dict.put(CommandProcessor.COMMAND_SCOPE, "scope");
      dict.put(CommandProcessor.COMMAND_FUNCTION,
InformationRegistryCommands.commands);


regs.add(context.registerService(InformationRegistryCommands.class.getName(),
new InformationRegistryCommands(registry, log), dict));

      this.log.log(LogService.LOG_INFO, "Added Commands.");
    }

...

Where InformationRegistryCommands.commands is a static array of the
functions the class implements for the component it serves.
In that class, InformationRegistryCommands I then use the service command
annotation:

    import org.apache.felix.service.command.Descriptor;

And annotate my methods like this:

    /**
     * Functions available to the gogo shell from this registry
     */
    public static String[] commands = {"show", "last"};
    ...

    @Descriptor("shows the last seen informations for the qualified
information")
    public void last(
            @Descriptor("full qualified information in the form:
\"<namespace>.<name>:<version>\"")
            String fullQualifier) {
      ...
    }

    @Descriptor("shows all registered informations")
    public void show() {
      ...
    }

At least this works but it seems completely undocumented. I would help out
when someone would be willing to put it on the scr or gogo pages online.

:)

2012/10/15 Felix Meschberger <[email protected]>

> Hi,
>
> Am 10.10.2012 um 14:05 schrieb Kjell Otto:
>
> > I've tried to use the scr annotations with apache felix and it worked out
> > after a bit of a hassle with where to put
> > what and how to configure it(reference:
> >
> http://stackoverflow.com/questions/12642706/how-to-use-org-apache-felix-scr-annotations-for-a-bundle-from-scratch/12660778#12660778
> ).
> > But now it works and my components are running.
> >
> > Now I wanted to get started with the command line extension. I have
> googled
> > arround and found more options then I would like to have. None of them
> > seems to be applicable for my setup. I would like to provide a new
> command
> > scope for my components to live in and be able to call them from the
> > command line.
> > Since as I already read from the mailing list, the new shell will be
> gogo,
> > how would I then integrate my commands into the gogo shell with
> annotations
> > from scr? Is there a way or to I need to refactor scr out and put
> blueprint
> > in?
>
> Extending Gogo is extremely simple: You just register a service (the
> actual service type does not matter) and declare two service registration
> properties:
>
>   * osgi.command.scope defining the namespace prefix
>   * osgi.command.function defining the command functions
>
> The osgi.command.function is a String[] listing public methods turned into
> commands. These methods are analyzed through reflection.
>
> As for annotations, all that's needed is something like:
>
>   @Property(name="osgi.command.scope", value="sample")
>   @Property(name="osgi.command.function", value={"c1", "c2"})
>
> This defines two commands sample:c1 and sample:c2.
>
> As an example of such a command class you might look at the DS ScrCommand
> [1] (this uses raw OSGi API to register the service and not DS but the
> priniciple for defining commands is the same)
>
> Hope this helps.
>
> Regards
> Felix
>
> [1]
> http://svn.apache.org/repos/asf/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java
>
> >
> > There is not much documentation out there on how to integrate best now...
> > Shouldn't the old material be deleted by the time? Or flagged?
> > I would appreciate all hints and tips, thanks a lot.
> >
> > Greetings,
> > Kjellski
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to