Search in sources :

Example 21 with Repository

use of org.osgi.service.repository.Repository in project bnd by bndtools.

the class DebugReporter method doRepos.

private void doRepos() {
    header("OSGi REPOSITORIES");
    for (Repository repo : context.getRepositories()) {
        out.printf("%s%n", repo.toString());
    }
    nl();
}
Also used : Repository(org.osgi.service.repository.Repository)

Example 22 with Repository

use of org.osgi.service.repository.Repository in project bnd by bndtools.

the class XMLResourceGeneratorTest method testBasic.

public void testBasic() throws URISyntaxException, Exception {
    Repository repository = getTestRepository();
    File location = new File(tmp, "index.xml");
    new XMLResourceGenerator().name("test").repository(repository).save(location);
    Repository other = getRepository(location.toURI());
    Map<Requirement, Collection<Capability>> findProviders = other.findProviders(Collections.singleton(WILDCARD));
    Set<Resource> resources = ResourceUtils.getResources(findProviders.get(WILDCARD));
    assertEquals(1, resources.size());
    Resource r = resources.iterator().next();
    assertEquals("http://macbadge-updates.s3.amazonaws.com/plugins/name.njbartlett.eclipse.macbadge_1.0.0.201110100042.jar", ResourceUtils.getContentCapability(r).url().toString());
}
Also used : Requirement(org.osgi.resource.Requirement) Repository(org.osgi.service.repository.Repository) Resource(org.osgi.resource.Resource) Collection(java.util.Collection) File(java.io.File)

Example 23 with Repository

use of org.osgi.service.repository.Repository in project bndtools by bndtools.

the class RepositoryTreeContentProvider method getRepositoryBundles.

Object[] getRepositoryBundles(final RepositoryPlugin repoPlugin) {
    Object[] result = null;
    if (requirementFilter != null) {
        if (repoPlugin instanceof Repository) {
            result = searchR5Repository(repoPlugin, (Repository) repoPlugin);
        } else if (repoPlugin instanceof WorkspaceRepository) {
            try {
                WorkspaceR5Repository workspaceRepo = Central.getWorkspaceR5Repository();
                result = searchR5Repository(repoPlugin, workspaceRepo);
            } catch (Exception e) {
                logger.logError("Error querying workspace repository", e);
            }
        }
        return result;
    }
    /*
         * We can't directly call repoPlugin.list() since we are on the UI thread
         * so the plan is to first check to see if we have cached the list results
         * already from a previous job, if so, return those results directly
         * If not, then we need to create a background job that will call list()
         * and once it is finished, we tell the Viewer to refresh this node and the
         * next time this method gets called the 'results' will be available in the cache
         */
    Map<String, Object[]> listResults = repoPluginListResults.get(repoPlugin);
    if (listResults == null) {
        listResults = new HashMap<>();
        repoPluginListResults.put(repoPlugin, listResults);
    }
    result = listResults.get(wildcardFilter);
    if (result == null) {
        Job job = new Job("Loading " + repoPlugin.getName() + " content...") {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                IStatus status = Status.OK_STATUS;
                Object[] jobresult;
                List<String> bsns = null;
                try {
                    bsns = repoPlugin.list(wildcardFilter);
                } catch (Exception e) {
                    String message = MessageFormat.format("Error querying repository {0}.", repoPlugin.getName());
                    logger.logError(message, e);
                    status = new Status(IStatus.ERROR, Plugin.PLUGIN_ID, message, e);
                }
                if (bsns != null) {
                    Collections.sort(bsns);
                    jobresult = new RepositoryBundle[bsns.size()];
                    int i = 0;
                    for (String bsn : bsns) {
                        jobresult[i++] = new RepositoryBundle(repoPlugin, bsn);
                    }
                    Map<String, Object[]> listResults = repoPluginListResults.get(repoPlugin);
                    listResults.put(wildcardFilter, jobresult);
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            structuredViewer.refresh(repoPlugin, true);
                        }
                    });
                }
                return status;
            }
        };
        job.schedule();
        // wait 100 ms and see if the job will complete fast (likely already cached)
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
        IStatus status = job.getResult();
        if (status != null && status.isOK()) {
            Map<String, Object[]> fastResults = repoPluginListResults.get(repoPlugin);
            result = fastResults.get(wildcardFilter);
        } else {
            Object[] loading = new Object[] { new LoadingContentElement() };
            listResults.put(wildcardFilter, loading);
            result = loading;
        }
    }
    return result;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) WorkspaceR5Repository(bndtools.central.WorkspaceR5Repository) WorkspaceRepository(aQute.bnd.build.WorkspaceRepository) Repository(org.osgi.service.repository.Repository) WorkspaceR5Repository(bndtools.central.WorkspaceR5Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkspaceRepository(aQute.bnd.build.WorkspaceRepository) Job(org.eclipse.core.runtime.jobs.Job)

Example 24 with Repository

use of org.osgi.service.repository.Repository in project bnd by bndtools.

the class JpmRepoTest method testSimpleResolve.

// public void testResolveProviderWithRunpath() throws Exception {
// try {
// Project provider = ws.getProject("provider");
// provider.build();
// assertTrue(provider.check());
//
// Project requirer = ws.getProject("requirer");
// requirer.build();
// assertTrue(requirer.check());
//
// BndEditModel model = new BndEditModel();
// model.setProject(requirer);
// BndrunResolveContext context = new BndrunResolveContext(model, ws, log);
//
// Resolver resolver = new ResolverImpl(new
// org.apache.felix.resolver.Logger(4), null);
//
// Map<Resource,List<Wire>> resolved = resolver.resolve(context);
// Set<Resource> resources = resolved.keySet();
// Resource resource = getResource(resources, "requirer", "0");
// assertNotNull(resource);
// }
// catch (ResolutionException e) {
// fail("Resolve failed " + e);
// }
// }
public void testSimpleResolve() {
    Repository repo = ws.getPlugin(Repository.class);
    BndEditModel model = new BndEditModel();
    model.setRunFw("org.apache.felix.framework");
    List<Requirement> requires = new ArrayList<Requirement>();
    CapReqBuilder capReq = CapReqBuilder.createBundleRequirement("org.apache.felix.gogo.shell", "[0,1)");
    requires.add(capReq.buildSyntheticRequirement());
    Map<Requirement, Collection<Capability>> shell = repo.findProviders(requires);
    assertNotNull(shell);
    assertEquals(1, shell.size());
    model.setRunRequires(requires);
    BndrunResolveContext context = new BndrunResolveContext(model, ws, log);
    Resolver resolver = new BndResolver(new org.apache.felix.resolver.Logger(4));
    try {
        Map<Resource, List<Wire>> resolved = resolver.resolve(context);
        Set<Resource> resources = resolved.keySet();
        Resource resource = getResource(resources, "org.apache.felix.gogo.runtime", "0.12");
        assertNotNull(resource);
    } catch (ResolutionException e) {
        fail("Resolve failed");
    }
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) BndResolver(biz.aQute.resolve.BndResolver) Resolver(org.osgi.service.resolver.Resolver) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) ResolutionException(org.osgi.service.resolver.ResolutionException) Requirement(org.osgi.resource.Requirement) InfoRepository(aQute.bnd.service.repository.InfoRepository) Repository(org.osgi.service.repository.Repository) BndrunResolveContext(biz.aQute.resolve.BndrunResolveContext) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) BndResolver(biz.aQute.resolve.BndResolver) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 25 with Repository

use of org.osgi.service.repository.Repository in project aries by apache.

the class RepositoryServiceRepository method findProviders.

@SuppressWarnings("unchecked")
public Collection<Capability> findProviders(Requirement requirement) {
    Set<Capability> result = new HashSet<Capability>();
    ServiceReference<?>[] references;
    try {
        references = context.getAllServiceReferences("org.osgi.service.repository.Repository", null);
        if (references == null)
            return result;
    } catch (InvalidSyntaxException e) {
        throw new IllegalStateException(e);
    }
    for (ServiceReference<?> reference : references) {
        Object repository = context.getService(reference);
        if (repository == null)
            continue;
        try {
            // Reflection is used here to allow the service to work with a mixture of
            // Repository services implementing different versions of the API.
            Class<?> clazz = repository.getClass();
            Class<?> repoInterface = null;
            while (clazz != null && repoInterface == null) {
                for (Class<?> intf : clazz.getInterfaces()) {
                    if (Repository.class.getName().equals(intf.getName())) {
                        // Compare interfaces by name so that we can work with different versions of the
                        // interface.
                        repoInterface = intf;
                        break;
                    }
                }
                clazz = clazz.getSuperclass();
            }
            if (repoInterface == null) {
                continue;
            }
            Map<Requirement, Collection<Capability>> map;
            try {
                Method method = repoInterface.getMethod("findProviders", Collection.class);
                map = (Map<Requirement, Collection<Capability>>) method.invoke(repository, Collections.singleton(requirement));
            } catch (Exception e) {
                throw new SubsystemException(e);
            }
            Collection<Capability> capabilities = map.get(requirement);
            if (capabilities == null)
                continue;
            result.addAll(capabilities);
        } finally {
            context.ungetService(reference);
        }
    }
    return result;
}
Also used : Capability(org.osgi.resource.Capability) SubsystemException(org.osgi.service.subsystem.SubsystemException) Method(java.lang.reflect.Method) SubsystemException(org.osgi.service.subsystem.SubsystemException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference) Requirement(org.osgi.resource.Requirement) Repository(org.osgi.service.repository.Repository) Collection(java.util.Collection) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) HashSet(java.util.HashSet)

Aggregations

Repository (org.osgi.service.repository.Repository)35 Requirement (org.osgi.resource.Requirement)18 Capability (org.osgi.resource.Capability)16 ArrayList (java.util.ArrayList)11 Collection (java.util.Collection)11 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)9 File (java.io.File)9 Resource (org.osgi.resource.Resource)8 Run (aQute.bnd.build.Run)5 OSGiRepository (aQute.bnd.repository.osgi.OSGiRepository)5 List (java.util.List)5 Resolver (org.osgi.service.resolver.Resolver)5 BndEditModel (aQute.bnd.build.model.BndEditModel)4 ResourcesRepository (aQute.bnd.osgi.repository.ResourcesRepository)4 Processor (aQute.bnd.osgi.Processor)3 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)3 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)3 InfoRepository (aQute.bnd.service.repository.InfoRepository)3 WorkspaceR5Repository (bndtools.central.WorkspaceR5Repository)3 Map (java.util.Map)3