karaf shell extension with iPojo

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

karaf shell extension with iPojo

Lindley Andrew

Dear all,

 

I am using Karaf 2.1.0 and want to extend the shell with my own shell-commands.

There’s a great tutorial showing how to do this with blueprint.

http://karaf.apache.org/manual/2.1.99-SNAPSHOT/developers-guide/extending-console.html

 

I was trying to do this with iPojo but did not succeed. That’s the sample I was trying to run.

 

public interface SampleTUI {

     

      // the supported operations on the shell we're extending

      String FUNCTION_STR = "[list]";

 

      // will be used in the activator to define the namespace within the shell

      String SCOPE = "preserv";

     

      public void list();

 

}

 

@Component(name="sample.addons.api.command.KarafSampleTUI")

@Provides

public class KarafSampleTUI implements SampleTUI {

 

      // the supported operations on the shell we're extending

      @ServiceProperty(name="osgi.command.function", value=ServiceRegistryTUI.FUNCTION_STR)

      public String[] functions;

      // will be used in the activator to define the namespace within the shell

      @ServiceProperty(name="osgi.command.scope", value=ServiceRegistryTUI.SCOPE)

      public String scope;

     

      //these fields are injected

      //@Requires

      //private MyUtils mu;

 

 

      @Descriptor("some sample description")

      public void list() {

            System.out.println("testing list");

      }

}

 

<ipojo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

      xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/CURRENT/core.xsd

          org.apache.felix.ipojo.extender http://felix.apache.org/ipojo/schemas/CURRENT/extender-pattern.xsd"

      xmlns="org.apache.felix.ipojo">

 

      <instance component="sample.addons.api.command.KarafSampleTUI"/>

 

</ipojo>

 

It perfectly runs within Felix using gogo, but not in karaf (using Felix). Is this specific to gogo?

I also had a look at apache\felix\ipojo\arch\ and apache\felix\ipojo\arch\gogo but both aren’t working in karaf as well.

 

Thanks for your support,

Kr Andrew

Reply | Threaded
Open this post in threaded view
|

Re: karaf shell extension with iPojo

Guillaume Nodet
You can't invoke the command ? or the command does not appear in the
completion when you press tab ?
The former sounds like a bug, but the later is kinda expected.

On Thu, Mar 17, 2011 at 13:48, Lindley Andrew <[hidden email]> wrote:

> Dear all,
>
>
>
> I am using Karaf 2.1.0 and want to extend the shell with my own
> shell-commands.
>
> There’s a great tutorial showing how to do this with blueprint.
>
> http://karaf.apache.org/manual/2.1.99-SNAPSHOT/developers-guide/extending-console.html
>
>
>
> I was trying to do this with iPojo but did not succeed. That’s the sample I
> was trying to run.
>
>
>
> public interface SampleTUI {
>
>
>
>       // the supported operations on the shell we're extending
>
>       String FUNCTION_STR = "[list]";
>
>
>
>       // will be used in the activator to define the namespace within the
> shell
>
>       String SCOPE = "preserv";
>
>
>
>       public void list();
>
>
>
> }
>
>
>
> @Component(name="sample.addons.api.command.KarafSampleTUI")
>
> @Provides
>
> public class KarafSampleTUI implements SampleTUI {
>
>
>
>       // the supported operations on the shell we're extending
>
>       @ServiceProperty(name="osgi.command.function",
> value=ServiceRegistryTUI.FUNCTION_STR)
>
>       public String[] functions;
>
>       // will be used in the activator to define the namespace within the
> shell
>
>       @ServiceProperty(name="osgi.command.scope",
> value=ServiceRegistryTUI.SCOPE)
>
>       public String scope;
>
>
>
>       //these fields are injected
>
>       //@Requires
>
>       //private MyUtils mu;
>
>
>
>
>
>       @Descriptor("some sample description")
>
>       public void list() {
>
>             System.out.println("testing list");
>
>       }
>
> }
>
>
>
> <ipojo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
>       xsi:schemaLocation="org.apache.felix.ipojo
> http://felix.apache.org/ipojo/schemas/CURRENT/core.xsd
>
>           org.apache.felix.ipojo.extender
> http://felix.apache.org/ipojo/schemas/CURRENT/extender-pattern.xsd"
>
>       xmlns="org.apache.felix.ipojo">
>
>
>
>       <instance component="sample.addons.api.command.KarafSampleTUI"/>
>
>
>
> </ipojo>
>
>
>
> It perfectly runs within Felix using gogo, but not in karaf (using Felix).
> Is this specific to gogo?
>
> I also had a look at apache\felix\ipojo\arch\ and
> apache\felix\ipojo\arch\gogo but both aren’t working in karaf as well.
>
>
>
> Thanks for your support,
>
> Kr Andrew



--
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com
Reply | Threaded
Open this post in threaded view
|

RE: karaf shell extension with iPojo

Lindley Andrew
Ah! Thanks for clarification. As the command didn't show up in the completion I was expecting that it didn't came up properly.

Why exactly doesn't it appear in the completion or how could I fix that?

Tnx
Kr Andrew

-----Original Message-----
From: Guillaume Nodet [mailto:[hidden email]]
Sent: Thursday, March 17, 2011 1:53 PM
To: [hidden email]
Subject: Re: karaf shell extension with iPojo

You can't invoke the command ? or the command does not appear in the
completion when you press tab ?
The former sounds like a bug, but the later is kinda expected.

On Thu, Mar 17, 2011 at 13:48, Lindley Andrew <[hidden email]> wrote:

> Dear all,
>
>
>
> I am using Karaf 2.1.0 and want to extend the shell with my own
> shell-commands.
>
> There's a great tutorial showing how to do this with blueprint.
>
> http://karaf.apache.org/manual/2.1.99-SNAPSHOT/developers-guide/extending-console.html
>
>
>
> I was trying to do this with iPojo but did not succeed. That's the sample I
> was trying to run.
>
>
>
> public interface SampleTUI {
>
>
>
>       // the supported operations on the shell we're extending
>
>       String FUNCTION_STR = "[list]";
>
>
>
>       // will be used in the activator to define the namespace within the
> shell
>
>       String SCOPE = "preserv";
>
>
>
>       public void list();
>
>
>
> }
>
>
>
> @Component(name="sample.addons.api.command.KarafSampleTUI")
>
> @Provides
>
> public class KarafSampleTUI implements SampleTUI {
>
>
>
>       // the supported operations on the shell we're extending
>
>       @ServiceProperty(name="osgi.command.function",
> value=ServiceRegistryTUI.FUNCTION_STR)
>
>       public String[] functions;
>
>       // will be used in the activator to define the namespace within the
> shell
>
>       @ServiceProperty(name="osgi.command.scope",
> value=ServiceRegistryTUI.SCOPE)
>
>       public String scope;
>
>
>
>       //these fields are injected
>
>       //@Requires
>
>       //private MyUtils mu;
>
>
>
>
>
>       @Descriptor("some sample description")
>
>       public void list() {
>
>             System.out.println("testing list");
>
>       }
>
> }
>
>
>
> <ipojo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
>       xsi:schemaLocation="org.apache.felix.ipojo
> http://felix.apache.org/ipojo/schemas/CURRENT/core.xsd
>
>           org.apache.felix.ipojo.extender
> http://felix.apache.org/ipojo/schemas/CURRENT/extender-pattern.xsd"
>
>       xmlns="org.apache.felix.ipojo">
>
>
>
>       <instance component="sample.addons.api.command.KarafSampleTUI"/>
>
>
>
> </ipojo>
>
>
>
> It perfectly runs within Felix using gogo, but not in karaf (using Felix).
> Is this specific to gogo?
>
> I also had a look at apache\felix\ipojo\arch\ and
> apache\felix\ipojo\arch\gogo but both aren't working in karaf as well.
>
>
>
> Thanks for your support,
>
> Kr Andrew



--
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com
Reply | Threaded
Open this post in threaded view
|

Re: karaf shell extension with iPojo

Guillaume Nodet
That's not really a bug, it's a feature ;-)

Completion only displays commands that inherit the
org.apache.felix.gogo.commands.basic.AbstractCommand (which is now
defined in Karaf, but the package hasn't been renamed in case your
wonder about the name).  You'd usually implement
org.apache.karaf.shell.console.CompletableFunction too in order to
provide argument completers and also use the annotations defined in
org.apache.felix.gogo.commands in order to have argument conversion.

On Thu, Mar 17, 2011 at 14:02, Lindley Andrew <[hidden email]> wrote:

> Ah! Thanks for clarification. As the command didn't show up in the completion I was expecting that it didn't came up properly.
>
> Why exactly doesn't it appear in the completion or how could I fix that?
>
> Tnx
> Kr Andrew
>
> -----Original Message-----
> From: Guillaume Nodet [mailto:[hidden email]]
> Sent: Thursday, March 17, 2011 1:53 PM
> To: [hidden email]
> Subject: Re: karaf shell extension with iPojo
>
> You can't invoke the command ? or the command does not appear in the
> completion when you press tab ?
> The former sounds like a bug, but the later is kinda expected.
>
> On Thu, Mar 17, 2011 at 13:48, Lindley Andrew <[hidden email]> wrote:
>> Dear all,
>>
>>
>>
>> I am using Karaf 2.1.0 and want to extend the shell with my own
>> shell-commands.
>>
>> There's a great tutorial showing how to do this with blueprint.
>>
>> http://karaf.apache.org/manual/2.1.99-SNAPSHOT/developers-guide/extending-console.html
>>
>>
>>
>> I was trying to do this with iPojo but did not succeed. That's the sample I
>> was trying to run.
>>
>>
>>
>> public interface SampleTUI {
>>
>>
>>
>>       // the supported operations on the shell we're extending
>>
>>       String FUNCTION_STR = "[list]";
>>
>>
>>
>>       // will be used in the activator to define the namespace within the
>> shell
>>
>>       String SCOPE = "preserv";
>>
>>
>>
>>       public void list();
>>
>>
>>
>> }
>>
>>
>>
>> @Component(name="sample.addons.api.command.KarafSampleTUI")
>>
>> @Provides
>>
>> public class KarafSampleTUI implements SampleTUI {
>>
>>
>>
>>       // the supported operations on the shell we're extending
>>
>>       @ServiceProperty(name="osgi.command.function",
>> value=ServiceRegistryTUI.FUNCTION_STR)
>>
>>       public String[] functions;
>>
>>       // will be used in the activator to define the namespace within the
>> shell
>>
>>       @ServiceProperty(name="osgi.command.scope",
>> value=ServiceRegistryTUI.SCOPE)
>>
>>       public String scope;
>>
>>
>>
>>       //these fields are injected
>>
>>       //@Requires
>>
>>       //private MyUtils mu;
>>
>>
>>
>>
>>
>>       @Descriptor("some sample description")
>>
>>       public void list() {
>>
>>             System.out.println("testing list");
>>
>>       }
>>
>> }
>>
>>
>>
>> <ipojo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>
>>       xsi:schemaLocation="org.apache.felix.ipojo
>> http://felix.apache.org/ipojo/schemas/CURRENT/core.xsd
>>
>>           org.apache.felix.ipojo.extender
>> http://felix.apache.org/ipojo/schemas/CURRENT/extender-pattern.xsd"
>>
>>       xmlns="org.apache.felix.ipojo">
>>
>>
>>
>>       <instance component="sample.addons.api.command.KarafSampleTUI"/>
>>
>>
>>
>> </ipojo>
>>
>>
>>
>> It perfectly runs within Felix using gogo, but not in karaf (using Felix).
>> Is this specific to gogo?
>>
>> I also had a look at apache\felix\ipojo\arch\ and
>> apache\felix\ipojo\arch\gogo but both aren't working in karaf as well.
>>
>>
>>
>> Thanks for your support,
>>
>> Kr Andrew
>
>
>
> --
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> ------------------------
> Open Source SOA
> http://fusesource.com
>



--
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com