use of org.apache.felix.service.command.Descriptor in project felix by apache.
the class Basic method install.
@Descriptor("install bundle using URLs")
public void install(@Descriptor("command session") CommandSession session, @Descriptor("target URLs") String[] urls) throws IOException {
StringBuffer sb = new StringBuffer();
for (String url : urls) {
String location = Util.resolveUri(session, url.trim());
Bundle bundle = null;
try {
bundle = m_bc.installBundle(location, null);
} catch (IllegalStateException ex) {
System.err.println(ex.toString());
} catch (BundleException ex) {
if (ex.getNestedException() != null) {
System.err.println(ex.getNestedException().toString());
} else {
System.err.println(ex.toString());
}
} catch (Exception ex) {
System.err.println(ex.toString());
}
if (bundle != null) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(bundle.getBundleId());
}
}
if (sb.toString().indexOf(',') > 0) {
System.out.println("Bundle IDs: " + sb.toString());
} else if (sb.length() > 0) {
System.out.println("Bundle ID: " + sb.toString());
}
}
use of org.apache.felix.service.command.Descriptor in project felix by apache.
the class Files method cd.
@Descriptor("change current directory")
public File cd(@Descriptor("automatically supplied shell session") CommandSession session, @Descriptor("target directory") String dir) throws IOException {
File cwd = (File) session.get(CWD);
if (cwd == null) {
cwd = new File(".").getCanonicalFile();
session.put(CWD, cwd);
}
if ((dir == null) || (dir.length() == 0)) {
return cwd;
}
URI curUri = cwd.toURI();
URI newUri = curUri.resolve(dir);
cwd = new File(newUri);
if (!cwd.exists()) {
throw new IOException("Directory does not exist");
} else if (!cwd.isDirectory()) {
throw new IOException("Target is not a directory");
}
session.put(CWD, cwd.getCanonicalFile());
return cwd;
}
use of org.apache.felix.service.command.Descriptor in project felix by apache.
the class Arch method extensions.
/**
* Displays the list of available extensions.
*/
@Descriptor("Display iPOJO extensions")
public void extensions() {
PrintStream out = System.out;
out.println("Available extensions:");
for (ExtensionDeclaration extension : m_extensions) {
out.println(" * " + extension.getExtensionName());
}
}
use of org.apache.felix.service.command.Descriptor in project felix by apache.
the class Arch method instance.
/**
* Displays the architecture of a specific instance.
* @param instance the instance name
*/
@Descriptor("Display the architecture of a specific instance")
public void instance(@Descriptor("target instance name") String instance) {
StringBuilder sb = new StringBuilder();
for (Architecture m_arch : m_archs) {
InstanceDescription id = m_arch.getInstanceDescription();
if (id.getName().equalsIgnoreCase(instance)) {
sb.append(id.getDescription());
sb.append('\n');
}
}
for (InstanceDeclaration instanceDeclaration : m_instances) {
if (!instanceDeclaration.getStatus().isBound()) {
if (instance.equals(name(instanceDeclaration.getConfiguration()))) {
sb.append(format("InstanceDeclaration %s not bound to its factory%n", instance));
sb.append(format(" type: %s%n", instanceDeclaration.getComponentName()));
sb.append(format(" reason: %s%n", instanceDeclaration.getStatus().getMessage()));
Throwable throwable = instanceDeclaration.getStatus().getThrowable();
if (throwable != null) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
throwable.printStackTrace(new PrintStream(os));
sb.append(" throwable: ");
sb.append(os.toString());
}
}
}
}
if (sb.length() == 0) {
System.err.printf("Instance named '%s' not found", instance);
} else {
System.out.print(sb);
}
}
use of org.apache.felix.service.command.Descriptor in project felix by apache.
the class Arch method factory.
/**
* Displays the information about a specific factory.
* Note that factory name are not unique, so all matching
* factories are displayed.
* @param name the factory name
*/
@Descriptor("Display the information about a specific factory")
public void factory(@Descriptor("target factory name") String name) {
List<Factory> factories = new ArrayList<Factory>();
List<TypeDeclaration> types = new ArrayList<TypeDeclaration>();
// Looking for public factories
for (Factory factory : m_factories) {
if (factory.getName().equalsIgnoreCase(name)) {
factories.add(factory);
}
}
// Looking for all unbound or private bound types
for (TypeDeclaration type : m_types) {
if (name.equalsIgnoreCase(type.getComponentName())) {
// (Public + Unbound) or private types have no exported factories
if (!type.isPublic() || (!type.getStatus().isBound() && type.isPublic())) {
types.add(type);
}
}
}
if (factories.isEmpty() && types.isEmpty()) {
System.err.println("Factory " + name + " not found");
return;
}
// Display found factories and types
for (Factory factory : factories) {
System.out.println(factory.getComponentDescription());
}
for (TypeDeclaration type : types) {
if (!type.getStatus().isBound()) {
// Unbound: maybe private or public type
System.out.printf("Factory %s is not bound%n", type.getComponentName());
System.out.printf(" reason: %s%n", type.getStatus().getMessage());
Throwable throwable = type.getStatus().getThrowable();
if (throwable != null) {
System.out.print(" throwable: ");
throwable.printStackTrace(System.out);
}
} else {
// Bound, this is only a private factory
System.out.printf("Factory %s is bound - Private%n", type.getComponentName());
}
}
}
Aggregations