use of org.apache.felix.service.command.Descriptor in project karaf by apache.
the class CommandTracker method addingService.
@Override
public List<Command> addingService(final ServiceReference<Object> reference) {
final String scope = reference.getProperty(CommandProcessor.COMMAND_SCOPE).toString();
final Object function = reference.getProperty(CommandProcessor.COMMAND_FUNCTION);
final List<String> names = new ArrayList<>();
if (function.getClass().isArray()) {
for (final Object f : ((Object[]) function)) {
names.add(f.toString());
}
} else {
names.add(function.toString());
}
List<Command> commands = new ArrayList<>();
for (String name : names) {
final Function target = new CommandProxy(context, reference, name);
Command command = new Command() {
@Override
public String getScope() {
return scope;
}
@Override
public String getName() {
return name;
}
@Override
public String getDescription() {
for (Method method : getMethods()) {
Descriptor d = method.getAnnotation(Descriptor.class);
if (d != null) {
return d.value();
}
}
Object property = reference.getProperty("osgi.command.description");
if (property != null) {
return property.toString();
} else {
return getName();
}
}
@Override
public Completer getCompleter(final boolean scoped) {
return null;
}
@Override
public Parser getParser() {
return null;
}
@Override
public Object execute(Session session, List<Object> arguments) throws Exception {
// TODO: remove not really nice cast
CommandSession commandSession = (CommandSession) session.get(".commandSession");
return target.execute(commandSession, arguments);
}
private List<Method> getMethods() {
Object target = context.getService(reference);
List<Method> methods = new ArrayList<>();
String func = name.substring(name.indexOf(':') + 1).toLowerCase();
List<String> funcs = new ArrayList<>();
funcs.add("is" + func);
funcs.add("get" + func);
funcs.add("set" + func);
if (Reflective.KEYWORDS.contains(func)) {
funcs.add("_" + func);
} else {
funcs.add(func);
}
for (Method method : target.getClass().getMethods()) {
if (funcs.contains(method.getName().toLowerCase())) {
methods.add(method);
}
}
context.ungetService(reference);
return methods;
}
};
sessionFactory.getRegistry().register(command);
commands.add(command);
}
return commands;
}
use of org.apache.felix.service.command.Descriptor in project felix by apache.
the class ComponentCommands method disable.
@Descriptor("Disable an enabled component")
public boolean disable(@Descriptor("Name of the component") final String name) {
boolean changed = false;
for (ComponentDescriptionDTO comp : findComponents(name)) {
if (scr.isComponentEnabled(comp)) {
scr.disableComponent(comp);
changed = true;
}
}
return changed;
}
use of org.apache.felix.service.command.Descriptor in project felix by apache.
the class ObrGogoCommand method javadoc.
@Descriptor("retrieve resource JavaDoc from repository")
public void javadoc(@Descriptor("extract documentation") @Parameter(names = { "-x", "--extract" }, presentValue = "true", absentValue = "false") boolean extract, @Descriptor("local target directory") File localDir, @Descriptor("( <bundle-name> | <symbolic-name> | <bundle-id> )[@<version>] ...") String[] args) throws IOException, InvalidSyntaxException {
Object svcObj = getRepositoryAdmin();
if (svcObj == null) {
return;
}
RepositoryAdmin ra = (RepositoryAdmin) svcObj;
for (int argIdx = 0; argIdx < args.length; argIdx++) {
// Find the target's bundle resource.
String targetName = args[argIdx];
String targetVersion = null;
int idx = args[argIdx].indexOf(VERSION_SEPARATOR);
if (idx > 0) {
targetName = args[argIdx].substring(0, idx);
targetVersion = args[argIdx].substring(idx + 1);
}
Resource resource = selectNewestVersion(searchRepository(ra, targetName, targetVersion));
if (resource == null) {
System.err.println("Unknown bundle and/or version: " + args[argIdx]);
} else {
URL docURL = (URL) resource.getProperties().get("javadoc");
if (docURL != null) {
downloadSource(System.out, System.err, docURL, localDir, extract);
} else {
System.err.println("Missing javadoc URL: " + args[argIdx]);
}
}
}
}
use of org.apache.felix.service.command.Descriptor in project felix by apache.
the class ObrGogoCommand method source.
@Descriptor("retrieve resource source code from repository")
public void source(@Descriptor("extract source code") @Parameter(names = { "-x", "--extract" }, presentValue = "true", absentValue = "false") boolean extract, @Descriptor("local target directory") File localDir, @Descriptor("( <bundle-name> | <symbolic-name> | <bundle-id> )[@<version>] ...") String[] args) throws IOException, InvalidSyntaxException {
Object svcObj = getRepositoryAdmin();
if (svcObj == null) {
return;
}
RepositoryAdmin ra = (RepositoryAdmin) svcObj;
for (int argIdx = 0; argIdx < args.length; argIdx++) {
// Find the target's bundle resource.
String targetName = args[argIdx];
String targetVersion = null;
int idx = args[argIdx].indexOf(VERSION_SEPARATOR);
if (idx > 0) {
targetName = args[argIdx].substring(0, idx);
targetVersion = args[argIdx].substring(idx + 1);
}
Resource resource = selectNewestVersion(searchRepository(ra, targetName, targetVersion));
if (resource == null) {
System.err.println("Unknown bundle and/or version: " + args[argIdx]);
} else {
String srcURI = (String) resource.getProperties().get(Resource.SOURCE_URI);
if (srcURI != null) {
downloadSource(System.out, System.err, new URL(srcURI), localDir, extract);
} else {
System.err.println("Missing source URL: " + args[argIdx]);
}
}
}
}
use of org.apache.felix.service.command.Descriptor in project felix by apache.
the class Basic method bundlelevel.
@Descriptor("query bundle start level")
public void bundlelevel(@Descriptor("bundle to query") Bundle bundle) {
// Keep track of service references.
List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
// Get start level service.
StartLevel sl = Util.getService(m_bc, StartLevel.class, refs);
if (sl == null) {
System.out.println("Start Level service is unavailable.");
} else // Get the bundle start level.
{
if (bundle != null) {
System.out.println(bundle + " is level " + sl.getBundleStartLevel(bundle));
}
}
Util.ungetServices(m_bc, refs);
}
Aggregations