Reputation: 2313
This basic code succeeds at making the command scopeA:test accessible in the shell:
package com.A;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.ServiceProperty;
import org.apache.felix.service.command.Descriptor;
@Component(immediate = true)
@Instantiate
@Provides(specifications = Commands.class)
public final class Commands {
@ServiceProperty(name = "osgi.command.scope", value = "scopeA")
String scope;
@ServiceProperty(name = "osgi.command.function", value = "{}")
String[] function = new String[] {
"test"
};
@Descriptor("Example")
public void test() {
System.out.println("hello");
}
}
However, if I add a constructor that depends on another OSGI component, it the command is no longer accessible and "help" doesn't list it. Yet the bundle can still be loading into an active state.
package com.A;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.ServiceProperty;
import org.apache.felix.service.command.Descriptor;
import com.B;
@Component(immediate = true)
@Instantiate
@Provides(specifications = Commands.class)
public final class Commands {
public Commands(@Requires B b) {
}
@ServiceProperty(name = "osgi.command.scope", value = "scopeA")
String scope;
@ServiceProperty(name = "osgi.command.function", value = "{}")
String[] function = new String[] {
"test"
};
@Descriptor("Example")
public void test() {
System.out.println("hello");
}
}
The contents of B is simply:
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Provides;
@Component(immediate = true)
@Instantiate
@Provides
final class B {
}
Any ideas why the command is no longer listed? Tips to find more information on the state so that I can better debug this?
Upvotes: 2
Views: 1019
Reputation: 491
also for me this needs to be changed
@ServiceProperty(name = "osgi.command.function", value = "{}")
String[] function = new String[] {
"test"
};
to
@ServiceProperty(name = "osgi.command.function", value = "{test}")
String[] function;
Upvotes: 0
Reputation: 2313
The problem is that commands needs the @Requires to be on a field rather than in the constructor.
@Requires
B b;
The constructor also must be removed.
This is because gogo has a special method of invoking the component.
Upvotes: 1