Search in sources :

Example 26 with Descriptor

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());
    }
}
Also used : Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Descriptor(org.apache.felix.service.command.Descriptor)

Example 27 with Descriptor

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;
}
Also used : IOException(java.io.IOException) File(java.io.File) URI(java.net.URI) Descriptor(org.apache.felix.service.command.Descriptor)

Example 28 with Descriptor

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());
    }
}
Also used : PrintStream(java.io.PrintStream) ExtensionDeclaration(org.apache.felix.ipojo.extender.ExtensionDeclaration) Descriptor(org.apache.felix.service.command.Descriptor)

Example 29 with Descriptor

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);
    }
}
Also used : PrintStream(java.io.PrintStream) Architecture(org.apache.felix.ipojo.architecture.Architecture) InstanceDescription(org.apache.felix.ipojo.architecture.InstanceDescription) InstanceDeclaration(org.apache.felix.ipojo.extender.InstanceDeclaration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Descriptor(org.apache.felix.service.command.Descriptor)

Example 30 with Descriptor

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());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Factory(org.apache.felix.ipojo.Factory) HandlerFactory(org.apache.felix.ipojo.HandlerFactory) TypeDeclaration(org.apache.felix.ipojo.extender.TypeDeclaration) Descriptor(org.apache.felix.service.command.Descriptor)

Aggregations

Descriptor (org.apache.felix.service.command.Descriptor)31 ArrayList (java.util.ArrayList)13 ServiceReference (org.osgi.framework.ServiceReference)8 IOException (java.io.IOException)6 Bundle (org.osgi.framework.Bundle)6 StartLevel (org.osgi.service.startlevel.StartLevel)5 URL (java.net.URL)4 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)4 PrintStream (java.io.PrintStream)3 Method (java.lang.reflect.Method)3 MalformedURLException (java.net.MalformedURLException)3 List (java.util.List)3 TreeMap (java.util.TreeMap)3 HandlerFactory (org.apache.felix.ipojo.HandlerFactory)3 TypeDeclaration (org.apache.felix.ipojo.extender.TypeDeclaration)3 BundleException (org.osgi.framework.BundleException)3 File (java.io.File)2 InputStream (java.io.InputStream)2 URI (java.net.URI)2 Factory (org.apache.felix.ipojo.Factory)2