You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Lindley Andrew <An...@ait.ac.at> on 2011/03/17 13:48:56 UTC

karaf shell extension with iPojo

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

Re: karaf shell extension with iPojo

Posted by Guillaume Nodet <gn...@gmail.com>.
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 <An...@ait.ac.at> 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:gnodet@gmail.com]
> Sent: Thursday, March 17, 2011 1:53 PM
> To: user@karaf.apache.org
> 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 <An...@ait.ac.at> 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

RE: karaf shell extension with iPojo

Posted by Lindley Andrew <An...@ait.ac.at>.
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:gnodet@gmail.com] 
Sent: Thursday, March 17, 2011 1:53 PM
To: user@karaf.apache.org
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 <An...@ait.ac.at> 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

Re: karaf shell extension with iPojo

Posted by Guillaume Nodet <gn...@gmail.com>.
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 <An...@ait.ac.at> 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