Package org.apache.felix.bundlerepository

Examples of org.apache.felix.bundlerepository.Resolver


    public void testMandatoryPackages() throws Exception
    {
        RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
        repoAdmin.addRepository(getClass().getResource("/repo_for_mandatory.xml"));

        Resolver resolver = repoAdmin.resolver();
        resolver.add(repoAdmin.getHelper().requirement("bundle", "(symbolicname=res2)"));
        assertFalse(resolver.resolve());

        resolver = repoAdmin.resolver();
        resolver.add(repoAdmin.getHelper().requirement("bundle", "(symbolicname=res3)"));
        assertTrue(resolver.resolve());

        resolver = repoAdmin.resolver();
        resolver.add(repoAdmin.getHelper().requirement("bundle", "(symbolicname=res4)"));
        assertFalse(resolver.resolve());

    }
View Full Code Here


        }

        String bundleId = event.getBundleId();
        try {
            if (isAllowed(event.getSourceGroup(), Constants.BUNDLES_CONFIG_CATEGORY, bundleId, EventType.INBOUND)) {
                Resolver resolver = obrService.resolver();
                String[] target = getTarget(bundleId);
                Resource resource = selectNewestVersion(searchRepository(target[0], target[1]));
                if (resource != null) {
                    resolver.add(resource);
                } else {
                    LOGGER.warn("CELLAR OBR: bundle {} unknown", target[0]);
                }
                if ((resolver.getAddedResources() != null) &&
                        (resolver.getAddedResources().length > 0)) {
                    if (resolver.resolve()) {
                        if (event.getType() == Constants.BUNDLE_START_EVENT_TYPE)
                            resolver.deploy(Resolver.START);
                        else resolver.deploy(0);
                    }
                } else {
                    Reason[] reqs = resolver.getUnsatisfiedRequirements();
                    if (reqs != null && reqs.length > 0) {
                        LOGGER.warn("CELLAR OBR: unsatisfied requirement(s): ");
                        for (Reason reason : reqs) {
                            LOGGER.warn("CELLAR OBR:    {}", reason.getRequirement().getFilter());
                            LOGGER.warn("CELLAR OBR:      {}", reason.getResource().getPresentationName());
View Full Code Here

    @Override
    public void handle(ObrBundleEvent event) {
        String bundleId = event.getBundleId();
        try {
            if (isAllowed(event.getSourceGroup(), Constants.BUNDLES_CONFIG_CATEGORY, bundleId, EventType.INBOUND)) {
                Resolver resolver = obrService.resolver();
                String[] target = getTarget(bundleId);
                Resource resource = selectNewestVersion(searchRepository(target[0], target[1]));
                if (resource != null) {
                    resolver.add(resource);
                } else {
                    LOGGER.warn("CELLAR OBR: bundle {} unknown", target[0]);
                }
                if ((resolver.getAddedResources() != null) &&
                        (resolver.getAddedResources().length > 0)) {
                    if (resolver.resolve()) {
                        if (event.getType() == Constants.BUNDLE_START_EVENT_TYPE)
                            resolver.deploy(Resolver.START);
                        else resolver.deploy(0);
                    }
                } else {
                    Reason[] reqs = resolver.getUnsatisfiedRequirements();
                    if (reqs != null && reqs.length > 0) {
                        LOGGER.warn("CELLAR OBR: unsatisfied requirement(s): ");
                        for (Reason reason : reqs) {
                            LOGGER.warn("CELLAR OBR:    {}", reason.getRequirement().getFilter());
                            LOGGER.warn("CELLAR OBR:      {}", reason.getResource().getPresentationName());
View Full Code Here

        final org.apache.karaf.features.internal.model.Feature f = new org.apache.karaf.features.internal.model.Feature("f1", "1.0");
        f.setResolver("obr");
        f.getBundle().add(new Bundle(requirement));
        final RepositoryAdmin admin = createMock(RepositoryAdmin.class);
        final Resolver resolver = createMock(Resolver.class);
        final Resource resource = createMock(Resource.class);
        final ObrResolver obrResolver = new ObrResolver();
        obrResolver.setRepositoryAdmin(admin);

        final Capture<Requirement> captureReq = new Capture<Requirement>();

        expect(admin.getHelper()).andReturn(new DataModelHelperImpl()).anyTimes();
        expect(admin.getSystemRepository()).andReturn(createMock(org.apache.felix.bundlerepository.Repository.class));
        expect(admin.getLocalRepository()).andReturn(createMock(org.apache.felix.bundlerepository.Repository.class));
        expect(admin.listRepositories()).andReturn(new org.apache.felix.bundlerepository.Repository[0]);
        expect(admin.resolver(EasyMock.<org.apache.felix.bundlerepository.Repository[]>anyObject())).andReturn(resolver);
        resolver.add(EasyMock.capture(captureReq));
        expect(resolver.resolve(Resolver.NO_OPTIONAL_RESOURCES)).andReturn(true);
        expect(resolver.getAddedResources()).andReturn(new Resource[] { });
        expect(resolver.getRequiredResources()).andReturn(new Resource[] { resource });
        expect(resolver.getReason(resource)).andAnswer(new IAnswer<Reason[]>() {
            public Reason[] answer() throws Throwable {
                return new Reason[] { new ReasonImpl( resource, captureReq.getValue()) };
            }
        });
        expect(resource.getURI()).andReturn("foo:bar");
View Full Code Here

        final org.apache.karaf.features.internal.model.Feature f = new org.apache.karaf.features.internal.model.Feature("f1", "1.0");
        f.setResolver("obr");
        f.getBundle().add(new Bundle(requirement));
        final RepositoryAdmin admin = createMock(RepositoryAdmin.class);
        final Resolver resolver = createMock(Resolver.class);
        final Resource resource = createMock(Resource.class);
        final Resource optionalResource = createMock(Resource.class);
        final ObrResolver obrResolver = new ObrResolver();
        obrResolver.setRepositoryAdmin(admin);
        obrResolver.setResolveOptionalImports(true);

        final Capture<Requirement> captureReq = new Capture<Requirement>();

        expect(admin.getHelper()).andReturn(new DataModelHelperImpl()).anyTimes();
        expect(admin.getSystemRepository()).andReturn(createMock(org.apache.felix.bundlerepository.Repository.class));
        expect(admin.getLocalRepository()).andReturn(createMock(org.apache.felix.bundlerepository.Repository.class));
        expect(admin.listRepositories()).andReturn(new org.apache.felix.bundlerepository.Repository[0]);
        expect(admin.resolver(EasyMock.<org.apache.felix.bundlerepository.Repository[]>anyObject())).andReturn(resolver);
        resolver.add(EasyMock.capture(captureReq));
        expect(resolver.resolve()).andReturn(true);
        expect(resolver.getAddedResources()).andReturn(new Resource[] { });
        expect(resolver.getRequiredResources()).andReturn(new Resource[] { resource });
        expect(resolver.getOptionalResources()).andReturn(new Resource[] { optionalResource});
        expect(resolver.getReason(resource)).andAnswer(new IAnswer<Reason[]>() {
            public Reason[] answer() throws Throwable {
                return new Reason[] { new ReasonImpl( resource, captureReq.getValue()) };
            }
        });
        expect(resolver.getReason(optionalResource)).andAnswer(new IAnswer<Reason[]>() {
            public Reason[] answer() throws Throwable {
                return new Reason[] { new ReasonImpl( optionalResource, captureReq.getValue()) };
            }
        });
        expect(resource.getURI()).andReturn("foo:bar");
View Full Code Here

        f.setResolver("obr");
        // Using file instead of mvn: as we do not want to mess with URL handlers
        f.getBundle().add(new Bundle("file:org.foo/foo/1.0"));

        final RepositoryAdmin admin = createMock(RepositoryAdmin.class);
        final Resolver resolver = createMock(Resolver.class);
        final Resource resource = createMock(Resource.class);
        final ObrResolver obrResolver = new ObrResolver();
        obrResolver.setRepositoryAdmin(admin);

        expect(admin.getHelper()).andReturn(new DummyDataModelHelper()).anyTimes();
View Full Code Here

        }
    }

    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);
                    }
                }
            }
View Full Code Here

        }
        out.println("");
    }

    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("   " + resources[resIdx].getPresentationName()
                            + " (" + resources[resIdx].getVersion() + ")");
                }
                resources = resolver.getRequiredResources();
                if ((resources != null) && (resources.length > 0)) {
                    System.out.println("\nRequired resource(s):");
                    printUnderline(System.out, 21);
                    for (int resIdx = 0; resIdx < resources.length; resIdx++) {
                        System.out.println("   " + resources[resIdx].getPresentationName()
                                + " (" + resources[resIdx].getVersion() + ")");
                    }
                }
                if (deployOptional) {
                    resources = resolver.getOptionalResources();
                    if ((resources != null) && (resources.length > 0)) {
                        System.out.println("\nOptional resource(s):");
                        printUnderline(System.out, 21);
                        for (int resIdx = 0; resIdx < resources.length; resIdx++) {
                            System.out.println("   " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].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 (int reqIdx = 0; reqIdx < reqs.length; reqIdx++) {
                        System.out.println("   " + reqs[reqIdx].getRequirement().getFilter());
View Full Code Here

            repositories.add(admin.getLocalRepository());
        }
        if (!noRemote) {
            repositories.addAll(Arrays.asList(admin.listRepositories()));
        }
        Resolver resolver = admin.resolver(repositories.toArray(new Repository[repositories.size()]));
        for (Requirement requirement : parseRequirements(admin, requirements)) {
            resolver.add(requirement);
        }
        if (resolver.resolve(optional ? 0 : Resolver.NO_OPTIONAL_RESOURCES)) {
            Resource[] resources;
            resources = resolver.getRequiredResources();
            if ((resources != null) && (resources.length > 0)) {
                System.out.println("Required resource(s):");
                printUnderline(System.out, 21);
                for (int resIdx = 0; resIdx < resources.length; resIdx++) {
                    System.out.println("   " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
                    if (why) {
                        Reason[] req = resolver.getReason(resources[resIdx]);
                        for (int reqIdx = 0; req != null && reqIdx < req.length; reqIdx++) {
                            if (!req[reqIdx].getRequirement().isOptional()) {
                                Resource r = req[reqIdx].getResource();
                                if (r != null) {
                                    System.out.println("      - " + r.getPresentationName() + " / " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
                                } else {
                                    System.out.println("      - " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
                                }
                            }
                        }
                    }
                }
            }
            resources = resolver.getOptionalResources();
            if ((resources != null) && (resources.length > 0)) {
                System.out.println();
                System.out.println("Optional resource(s):");
                printUnderline(System.out, 21);
                for (int resIdx = 0; resIdx < resources.length; resIdx++) {
                    System.out.println("   " + resources[resIdx].getPresentationName()
                        + " (" + resources[resIdx].getVersion() + ")");
                    if (why) {
                        Reason[] req = resolver.getReason(resources[resIdx]);
                        for (int reqIdx = 0; req != null && reqIdx < req.length; reqIdx++) {
                            if (!req[reqIdx].getRequirement().isOptional()) {
                                Resource r = req[reqIdx].getResource();
                                if (r != null) {
                                    System.out.println("      - " + r.getPresentationName() + " / " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
                                } else {
                                    System.out.println("      - " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
                                }
                            }
                        }
                    }
                }
            }
            if (deploy || start) {
                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 (int reqIdx = 0; reqIdx < reqs.length; reqIdx++) {
                    System.out.println("   " + reqs[reqIdx].getRequirement().getName() + ":" + reqs[reqIdx].getRequirement().getFilter());
View Full Code Here

        }
        out.println("");
    }

    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("   " + resources[resIdx].getPresentationName()
                            + " (" + resources[resIdx].getVersion() + ")");
                }
                resources = resolver.getRequiredResources();
                if ((resources != null) && (resources.length > 0)) {
                    System.out.println("\nRequired resource(s):");
                    printUnderline(System.out, 21);
                    for (int resIdx = 0; resIdx < resources.length; resIdx++) {
                        System.out.println("   " + resources[resIdx].getPresentationName()
                                + " (" + resources[resIdx].getVersion() + ")");
                    }
                }
                if (deployOptional) {
                    resources = resolver.getOptionalResources();
                    if ((resources != null) && (resources.length > 0)) {
                        System.out.println("\nOptional resource(s):");
                        printUnderline(System.out, 21);
                        for (int resIdx = 0; resIdx < resources.length; resIdx++) {
                            System.out.println("   " + resources[resIdx].getPresentationName()
                                    + " (" + resources[resIdx].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 (int reqIdx = 0; reqIdx < reqs.length; reqIdx++) {
                        System.out.println("   " + reqs[reqIdx].getRequirement().getFilter());
View Full Code Here

TOP

Related Classes of org.apache.felix.bundlerepository.Resolver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.