Package org.apache.felix.bundlerepository

Examples of org.apache.felix.bundlerepository.Resource


        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");
        expect(optionalResource.getURI()).andReturn("foo:optional:baz");
        replay(admin, resolver, resource, optionalResource);

        List<BundleInfo> bundles = obrResolver.resolve(f);
        assertNotNull(bundles);
        assertEquals(2, bundles.size());
View Full Code Here


        // 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();
        replay(admin, resolver, resource);
View Full Code Here

                Requirement req = parseRequirement(bundleInfo.getLocation());
                reqs.add(req);
                infos.put(req, bundleInfo);
            }
            if (url != null) {
              Resource res = repositoryAdmin.getHelper().createResource(url);
              ress.add(res);
              infos.put(res, bundleInfo);
            }
        }

        Repository repository = repositoryAdmin.getHelper().repository(ress.toArray(new Resource[ress.size()]));
        List<Repository> repos = new ArrayList<Repository>();
        repos.add(repositoryAdmin.getSystemRepository());
        repos.add(repositoryAdmin.getLocalRepository());
        repos.add(repository);
        repos.addAll(Arrays.asList(repositoryAdmin.listRepositories()));
        org.apache.felix.bundlerepository.Resolver resolver = repositoryAdmin.resolver(repos.toArray(new Repository[repos.size()]));

        for (Resource res : ress) {
            if (!infos.get(res).isDependency()) {
                resolver.add(res);
            }
        }
        for (Requirement req : reqs) {
            resolver.add(req);
        }

        if (!doResolve(resolver)) {
            StringWriter w = new StringWriter();
            PrintWriter out = new PrintWriter(w);
            Reason[] failedReqs = resolver.getUnsatisfiedRequirements();
            if ((failedReqs != null) && (failedReqs.length > 0)) {
                out.println("Unsatisfied requirement(s):");
                printUnderline(out, 27);
                for (Reason r : failedReqs) {
                    out.println("   " + r.getRequirement().getName() + ":" + r.getRequirement().getFilter());
                    out.println("      " + r.getResource().getPresentationName());
                }
            } else {
                out.println("Could not resolve targets.");
            }
            out.flush();
            throw new Exception("Can not resolve feature:\n" + w.toString());
        }

        List<BundleInfo> bundles = new ArrayList<BundleInfo>();
        List<Resource> deploy = new ArrayList<Resource>();
        Collections.addAll(deploy, resolver.getRequiredResources());
        if (resolveOptionalImports) {
            Collections.addAll(deploy, resolver.getOptionalResources());
        }
        Collections.addAll(deploy, resolver.getAddedResources());
        deploy.addAll(featureDeploy);
        for (Resource res : deploy) {
            BundleInfo info = infos.get(res);
            if (info == null) {
                Reason[] reasons = resolver.getReason(res);
                if (reasons != null) {
                    for (Reason r : reasons) {
                        info = infos.get(r);
                        if (info != null) {
                            break;
                        }
                    }
                }
            }
            if (info == null) {
                info = new BundleInfoImpl(res.getURI(), this.startLevel, this.startByDefault, false);
            }
            bundles.add(info);
        }
        return bundles;
    }
View Full Code Here

    List<String> bundles;

    protected void doExecute(RepositoryAdmin admin) throws Exception {
        for (String bundle : bundles) {
            String[] target = getTarget(bundle);
            Resource resource = selectNewestVersion(searchRepository(admin, target[0], target[1]));
            if (resource == null)
            {
                System.err.println("Unknown bundle and/or version: " + target[0]);
            }
            else
            {
                URI srcURL = (URI) resource.getProperties().get(Resource.SOURCE_URI);
                if (srcURL != null)
                {
                    FileUtil.downloadSource(System.out, System.err, srcURL.toURL(), localDir, extract);
                }
                else
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) &&
View Full Code Here

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

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

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

       
        Set<Resource> requiredFragments = new HashSet<Resource>();
        Set<Resource> optionalFragments = new HashSet<Resource>();
       
        for (Resource resource : obrResolver.getRequiredResources()) {
            Resource fragmentResource = findFragmentResource(resource);
            if (fragmentResource != null) {
                requiredFragments.add(fragmentResource);
            }
        }
        if (returnOptionalResources) {
            for (Resource resource : obrResolver.getOptionalResources()) {
                Resource fragmentResource = findFragmentResource(resource);
                if (fragmentResource != null) {
                    optionalFragments.add(fragmentResource);
                }
            }
        }
View Full Code Here

            int candiates = candidateFragments.size();
            if (candiates == 0) {
                log.debug("No matching fragments found for {}", hostResource);
                return null;
            } else if (candiates == 1) {
                Resource fragmentResource = candidateFragments.get(0);
                log.debug("Single matching fragment found for {}: {}", new Object[] { hostResource, fragmentResource });
                return fragmentResource;
            } else {
                Collections.sort(candidateFragments, new Comparator<Resource>() {
                    @Override
                    public int compare(Resource object1, Resource object2) {
                        Version version1 = object1.getVersion();
                        Version version2 = object2.getVersion();
                        return version2.compareTo(version1);
                    }
                });
                Resource fragmentResource = candidateFragments.get(0);
                log.debug("Multiple matching fragments found for {}. Fragment selected: {}", new Object[] { hostResource, fragmentResource });
                return fragmentResource;
            }

        } else {
View Full Code Here

TOP

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

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.