Search in sources :

Example 1 with InfoRepository

use of aQute.bnd.service.repository.InfoRepository in project bnd by bndtools.

the class LauncherTest method setUp.

@Override
protected void setUp() throws Exception {
    tmp = IO.getFile("generated/tmp");
    tmp.mkdirs();
    IO.copy(IO.getFile("testdata/ws"), tmp);
    workspace = Workspace.getWorkspace(tmp);
    workspace.refresh();
    InfoRepository repo = workspace.getPlugin(InfoRepository.class);
    t1 = create("bsn-1", new Version(1, 0, 0));
    t2 = create("bsn-2", new Version(1, 0, 0));
    repo.put(new FileInputStream(t1), null);
    repo.put(new FileInputStream(t2), null);
    t1 = repo.get("bsn-1", new Version(1, 0, 0), null);
    t2 = repo.get("bsn-2", new Version(1, 0, 0), null);
    repo.put(new FileInputStream(IO.getFile("generated/biz.aQute.remote.launcher.jar")), null);
    workspace.getPlugins().add(repo);
    File storage = IO.getFile("generated/storage-1");
    storage.mkdirs();
    configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
    configuration.put(Constants.FRAMEWORK_STORAGE, storage.getAbsolutePath());
    configuration.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.2");
    framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration);
    framework.init();
    framework.start();
    context = framework.getBundleContext();
    location = "reference:" + IO.getFile("generated/biz.aQute.remote.agent.jar").toURI().toString();
    agent = context.installBundle(location);
    agent.start();
    thread = new Thread() {

        @Override
        public void run() {
            try {
                Main.main(new String[] { "-s", "generated/storage", "-c", "generated/cache", "-p", "1090", "-et" });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    thread.setDaemon(true);
    thread.start();
    super.setUp();
}
Also used : InfoRepository(aQute.bnd.service.repository.InfoRepository) FileInputStream(java.io.FileInputStream) Version(aQute.bnd.version.Version) File(java.io.File)

Example 2 with InfoRepository

use of aQute.bnd.service.repository.InfoRepository in project bnd by bndtools.

the class bnd method _bsn2url.

public void _bsn2url(Bsn2UrlOptions opts) throws Exception {
    Project p = getProject(opts.project());
    if (p == null) {
        error("You need to be in a project or specify the project with -p/--project");
        return;
    }
    MultiMap<String, Version> revisions = new MultiMap<String, Version>();
    for (RepositoryPlugin repo : p.getPlugins(RepositoryPlugin.class)) {
        if (!(repo instanceof InfoRepository))
            continue;
        for (String bsn : repo.list(null)) {
            revisions.addAll(bsn, repo.versions(bsn));
        }
    }
    for (List<Version> versions : revisions.values()) {
        Collections.sort(versions, Collections.reverseOrder());
    }
    List<String> files = opts._arguments();
    for (String f : files) {
        try (BufferedReader r = IO.reader(getFile(f))) {
            String line;
            nextLine: while ((line = r.readLine()) != null) {
                Matcher matcher = LINE_P.matcher(line);
                if (!matcher.matches())
                    continue nextLine;
                line = matcher.group(1);
                Parameters bundles = new Parameters(line, this);
                for (Map.Entry<String, Attrs> entry : bundles.entrySet()) {
                    String bsn = entry.getKey();
                    VersionRange range = new VersionRange(entry.getValue().getVersion());
                    List<Version> versions = revisions.get(bsn);
                    if (versions == null) {
                        error("No for versions for %s", bsn);
                        break nextLine;
                    }
                    for (Version version : versions) {
                        if (range.includes(version)) {
                            for (RepositoryPlugin repo : p.getPlugins(RepositoryPlugin.class)) {
                                if (!(repo instanceof InfoRepository))
                                    continue;
                                InfoRepository rp = (InfoRepository) repo;
                                ResourceDescriptor descriptor = rp.getDescriptor(bsn, version);
                                if (descriptor == null) {
                                    error("Found bundle, but no descriptor %s;version=%s", bsn, version);
                                    return;
                                }
                                out.println(descriptor.url + " #" + descriptor.bsn + ";version=" + descriptor.version);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            error("failed to create url list from file %s : %s", f, e);
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Matcher(java.util.regex.Matcher) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) VersionRange(aQute.bnd.version.VersionRange) InfoRepository(aQute.bnd.service.repository.InfoRepository) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ZipException(java.util.zip.ZipException) Project(aQute.bnd.build.Project) MultiMap(aQute.lib.collections.MultiMap) Entry(java.util.Map.Entry) Version(aQute.bnd.version.Version) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) ExtList(aQute.lib.collections.ExtList) List(java.util.List) SortedList(aQute.lib.collections.SortedList) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 3 with InfoRepository

use of aQute.bnd.service.repository.InfoRepository in project bnd by bndtools.

the class InfoRepositoryWrapper method init.

boolean init() {
    try {
        if (System.currentTimeMillis() < lastTime + 10000)
            return true;
    } finally {
        lastTime = System.currentTimeMillis();
    }
    Set<String> errors = new LinkedHashSet<String>();
    try {
        //
        // Get the current repo contents
        //
        Set<String> toBeDeleted = new HashSet<String>(persistent.keySet());
        Map<String, DownloadBlocker> blockers = new HashMap<String, DownloadBlocker>();
        for (InfoRepository repo : repos) {
            Map<String, ResourceDescriptor> map = collectKeys(repo);
            for (final Map.Entry<String, ResourceDescriptor> entry : map.entrySet()) {
                final String id = entry.getKey();
                toBeDeleted.remove(id);
                if (persistent.containsKey(id))
                    continue;
                final ResourceDescriptor rd = entry.getValue();
                DownloadBlocker blocker = new DownloadBlocker(null) {

                    //
                    // We steal the thread of the downloader to index
                    //
                    @Override
                    public void success(File file) throws Exception {
                        IndexResult index = null;
                        try {
                            index = repoIndexer.indexFile(file);
                            ResourceBuilder rb = new ResourceBuilder();
                            for (org.osgi.service.indexer.Capability capability : index.capabilities) {
                                CapReqBuilder cb = new CapReqBuilder(capability.getNamespace());
                                cb.addAttributes(capability.getAttributes());
                                cb.addDirectives(capability.getDirectives());
                                rb.addCapability(cb.buildSyntheticCapability());
                            }
                            for (org.osgi.service.indexer.Requirement requirement : index.requirements) {
                                CapReqBuilder cb = new CapReqBuilder(requirement.getNamespace());
                                cb.addAttributes(requirement.getAttributes());
                                cb.addDirectives(requirement.getDirectives());
                                rb.addRequirement(cb.buildSyntheticRequirement());
                            }
                            Resource resource = rb.build();
                            PersistentResource pr = new PersistentResource(resource);
                            persistent.put(id, pr);
                        } finally {
                            super.success(file);
                            if (index != null) {
                                index.resource.close();
                            }
                        }
                    }
                };
                blockers.put(entry.getKey(), blocker);
                repo.get(rd.bsn, rd.version, null, blocker);
            }
        }
        for (Entry<String, DownloadBlocker> entry : blockers.entrySet()) {
            String key = entry.getKey();
            DownloadBlocker blocker = entry.getValue();
            String reason = blocker.getReason();
            if (reason != null) {
                errors.add(key + ": " + reason);
            }
        }
        persistent.keySet().removeAll(toBeDeleted);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    if (!errors.isEmpty())
        throw new IllegalStateException("Cannot index " + repos + " due to " + errors);
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) IndexResult(org.osgi.service.indexer.ResourceIndexer.IndexResult) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) PersistentResource(aQute.bnd.osgi.resource.PersistentResource) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) PersistentResource(aQute.bnd.osgi.resource.PersistentResource) Resource(org.osgi.resource.Resource) DownloadBlocker(aQute.bnd.build.DownloadBlocker) InfoRepository(aQute.bnd.service.repository.InfoRepository) IOException(java.io.IOException) HashMap(java.util.HashMap) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map) PersistentMap(aQute.lib.persistentmap.PersistentMap) File(java.io.File) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 4 with InfoRepository

use of aQute.bnd.service.repository.InfoRepository in project bnd by bndtools.

the class Plugin method init.

/**
	 * This is called when all initialization is done for the plugins, now we
	 * can obtain a list of appropriate repos.
	 */
public void init() {
    if (init)
        return;
    init = true;
    try {
        //
        // Get the list if repos registered, repos that we can handle
        //
        List<InfoRepository> irs = new ArrayList<InfoRepository>();
        for (InfoRepository ir : registry.getPlugins(InfoRepository.class)) {
            irs.add(ir);
        }
        this.wrapper = new InfoRepositoryWrapper(dir, irs);
        if (config.reindex())
            this.wrapper.clear();
        if (config.augments() != null) {
            Workspace workspace = registry.getPlugin(Workspace.class);
            try (Processor p = new Processor(workspace)) {
                if (!config.augments().equals("WORKSPACE")) {
                    File f = IO.getFile(workspace.getBuildDir(), config.augments());
                    if (!f.isFile()) {
                        if (reporter != null)
                            reporter.error("No augment file found at %s", f.getAbsolutePath());
                        return;
                    }
                    //
                    // We read this in a processor that extends the
                    // workspace so
                    // we
                    // can use workspace properties
                    //
                    p.setProperties(f);
                    this.wrapper.clear(f.lastModified());
                }
                //
                // And then add it to the indexer to use.
                //
                this.wrapper.addAugment(p.getFlattenedProperties());
                this.wrapper.clear(workspace.getPropertiesFile().lastModified());
            }
        }
    } catch (Exception e) {
        throw Exceptions.duck(e);
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) ArrayList(java.util.ArrayList) InfoRepository(aQute.bnd.service.repository.InfoRepository) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

Example 5 with InfoRepository

use of aQute.bnd.service.repository.InfoRepository in project bnd by bndtools.

the class JpmRepoTest method testWrapper.

public void testWrapper() throws Exception {
    ws.setProperty("-fixupmessages.jpmdeprecated", "aQute.bnd.jpm.Repository is deprecated");
    assertNotNull(ws.getRepositories());
    assertNotNull(ws.getPlugin(InfoRepository.class));
    assertNotNull(ws.getPlugin(Repository.class));
    assertTrue(ws.check());
    // cache + jpm
    assertEquals(2, ws.getRepositories().size());
    InfoRepository plugin = ws.getPlugin(InfoRepository.class);
    for (String bsn : plugin.list(null)) {
        for (aQute.bnd.version.Version version : plugin.versions(bsn)) {
            System.out.println(bsn + ";version=" + version);
        }
    }
}
Also used : InfoRepository(aQute.bnd.service.repository.InfoRepository) Repository(org.osgi.service.repository.Repository) InfoRepository(aQute.bnd.service.repository.InfoRepository)

Aggregations

InfoRepository (aQute.bnd.service.repository.InfoRepository)8 Version (aQute.bnd.version.Version)5 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Parameters (aQute.bnd.header.Parameters)2 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)2 MultiMap (aQute.lib.collections.MultiMap)2 SortedList (aQute.lib.collections.SortedList)2 IOException (java.io.IOException)2 DownloadBlocker (aQute.bnd.build.DownloadBlocker)1 Project (aQute.bnd.build.Project)1 Workspace (aQute.bnd.build.Workspace)1 Baseline (aQute.bnd.differ.Baseline)1 BundleInfo (aQute.bnd.differ.Baseline.BundleInfo)1 Info (aQute.bnd.differ.Baseline.Info)1 Instructions (aQute.bnd.osgi.Instructions)1 Jar (aQute.bnd.osgi.Jar)1 Processor (aQute.bnd.osgi.Processor)1 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)1