Search in sources :

Example 1 with Resource

use of org.apache.felix.bundlerepository.Resource in project karaf by apache.

the class ObrMBeanImpl method deployBundle.

public void deployBundle(String bundle, boolean start, boolean deployOptional) throws MBeanException {
    try {
        Resolver resolver = repositoryAdmin.resolver();
        String[] target = getTarget(bundle);
        Resource resource = selectNewestVersion(searchRepository(repositoryAdmin, target[0], target[1]));
        if (resource == null) {
            throw new IllegalArgumentException("Unknown bundle " + target[0]);
        }
        resolver.add(resource);
        if ((resolver.getAddedResources() != null) && (resolver.getAddedResources().length > 0)) {
            if (resolver.resolve(deployOptional ? 0 : Resolver.NO_OPTIONAL_RESOURCES)) {
                try {
                    resolver.deploy(start ? Resolver.START : 0);
                } catch (IllegalStateException ex) {
                    throw new IllegalStateException("Can't deploy using OBR", ex);
                }
            }
        }
    } catch (Exception e) {
        throw new MBeanException(null, e.toString());
    }
}
Also used : Resolver(org.apache.felix.bundlerepository.Resolver) Resource(org.apache.felix.bundlerepository.Resource) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) MBeanException(javax.management.MBeanException)

Example 2 with Resource

use of org.apache.felix.bundlerepository.Resource in project karaf by apache.

the class ObrCommandSupport method doDeploy.

protected void doDeploy(RepositoryAdmin admin, List<String> bundles, boolean start, boolean deployOptional) throws Exception {
    Resolver resolver = admin.resolver();
    for (String bundle : bundles) {
        String[] target = getTarget(bundle);
        Resource resource = selectNewestVersion(searchRepository(admin, target[0], target[1]));
        if (resource != null) {
            resolver.add(resource);
        } else {
            System.err.println("Unknown bundle - " + target[0]);
        }
    }
    if ((resolver.getAddedResources() != null) && (resolver.getAddedResources().length > 0)) {
        if (resolver.resolve(deployOptional ? 0 : Resolver.NO_OPTIONAL_RESOURCES)) {
            System.out.println("Target resource(s):");
            printUnderline(System.out, 19);
            Resource[] resources = resolver.getAddedResources();
            for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
                System.out.println("   " + getResourceId(resources[resIdx]) + " (" + resources[resIdx].getVersion() + ")");
            }
            resources = resolver.getRequiredResources();
            if ((resources != null) && (resources.length > 0)) {
                System.out.println("\nRequired resource(s):");
                printUnderline(System.out, 21);
                for (Resource resource : resources) {
                    System.out.println("   " + getResourceId(resource) + " (" + resource.getVersion() + ")");
                }
            }
            if (deployOptional) {
                resources = resolver.getOptionalResources();
                if ((resources != null) && (resources.length > 0)) {
                    System.out.println("\nOptional resource(s):");
                    printUnderline(System.out, 21);
                    for (Resource resource : resources) {
                        System.out.println("   " + getResourceId(resource) + " (" + resource.getVersion() + ")");
                    }
                }
            }
            try {
                System.out.print("\nDeploying...");
                resolver.deploy(start ? Resolver.START : 0);
                System.out.println("done.");
            } catch (IllegalStateException ex) {
                System.err.println(ex);
            }
        } else {
            Reason[] reqs = resolver.getUnsatisfiedRequirements();
            if ((reqs != null) && (reqs.length > 0)) {
                System.out.println("Unsatisfied requirement(s):");
                printUnderline(System.out, 27);
                for (Reason req : reqs) {
                    System.out.println("   " + req.getRequirement().getFilter());
                    System.out.println("      " + getResourceId(req.getResource()));
                }
            } else {
                System.out.println("Could not resolve targets.");
            }
        }
    }
}
Also used : Resolver(org.apache.felix.bundlerepository.Resolver) Resource(org.apache.felix.bundlerepository.Resource) Reason(org.apache.felix.bundlerepository.Reason)

Example 3 with Resource

use of org.apache.felix.bundlerepository.Resource in project karaf by apache.

the class ListCommand method doExecute.

@Override
void doExecute(RepositoryAdmin admin) throws Exception {
    StringBuilder substr = new StringBuilder();
    if (packages != null) {
        for (String packageName : packages) {
            substr.append(" ");
            substr.append(packageName);
        }
    }
    String query;
    if ((substr == null) || (substr.length() == 0)) {
        query = "(|(presentationname=*)(symbolicname=*))";
    } else {
        query = "(|(presentationname=*" + substr + "*)(symbolicname=*" + substr + "*))";
    }
    Resource[] resources = admin.discoverResources(query);
    ShellTable table = new ShellTable();
    table.column("Name");
    table.column("Symbolic Name");
    table.column("Version");
    table.emptyTableText("No matching bundles");
    for (Resource resource : resources) {
        table.addRow().addContent(emptyIfNull(resource.getPresentationName()), emptyIfNull(resource.getSymbolicName()), emptyIfNull(resource.getVersion()));
    }
    table.print(System.out, !noFormat);
}
Also used : ShellTable(org.apache.karaf.shell.support.table.ShellTable) Resource(org.apache.felix.bundlerepository.Resource)

Example 4 with Resource

use of org.apache.felix.bundlerepository.Resource in project felix by apache.

the class ResourceComparator method compare.

public int compare(Object o1, Object o2) {
    Resource r1 = (Resource) o1;
    Resource r2 = (Resource) o2;
    String name1 = r1.getPresentationName();
    String name2 = r2.getPresentationName();
    if (name1 == null) {
        if (name2 == null) {
            return 0;
        }
        return -1;
    } else if (name2 == null) {
        return 1;
    }
    return name1.compareToIgnoreCase(name2);
}
Also used : Resource(org.apache.felix.bundlerepository.Resource)

Example 5 with Resource

use of org.apache.felix.bundlerepository.Resource in project felix by apache.

the class RepositoryAdminTest method testResourceFilterOnCapabilities.

public void testResourceFilterOnCapabilities() throws Exception {
    URL url = getClass().getResource("/repo_for_resolvertest.xml");
    RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
    RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url);
    Resource[] resources = repoAdmin.discoverResources("(category<*dummy)");
    assertNotNull(resources);
    assertEquals(1, resources.length);
    resources = repoAdmin.discoverResources("(category*>dummy)");
    assertNotNull(resources);
    assertEquals(1, resources.length);
}
Also used : Resource(org.apache.felix.bundlerepository.Resource) URL(java.net.URL)

Aggregations

Resource (org.apache.felix.bundlerepository.Resource)45 Repository (org.apache.felix.bundlerepository.Repository)19 Capability (org.apache.felix.bundlerepository.Capability)9 Resolver (org.apache.felix.bundlerepository.Resolver)9 ArrayList (java.util.ArrayList)8 ModelledResource (org.apache.aries.application.modelling.ModelledResource)8 ModelledBundleResource (org.apache.aries.application.resolver.obr.ext.ModelledBundleResource)8 Reason (org.apache.felix.bundlerepository.Reason)7 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)7 HashMap (java.util.HashMap)6 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)6 URL (java.net.URL)5 File (java.io.File)4 DataModelHelper (org.apache.felix.bundlerepository.DataModelHelper)4 FileWriter (java.io.FileWriter)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 Requirement (org.apache.felix.bundlerepository.Requirement)3 BundleContext (org.osgi.framework.BundleContext)3