Search in sources :

Example 6 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class AgentTest method testAgentUpdateBundleFromURL.

public void testAgentUpdateBundleFromURL() throws Exception {
    BundleDTO t2Bundle = supervisor.getAgent().getBundles(2).get(0);
    assertEquals("bsn-2", t2Bundle.symbolicName);
    assertEquals("2.0.0", t2Bundle.version);
    long previousModified = t2Bundle.lastModified;
    File t2prime = create("bsn-2", new Version(2, 0, 1));
    assertNull(supervisor.getAgent().updateFromURL(t2Bundle.id, t2prime.toURI().toURL().toExternalForm()));
    t2Bundle = supervisor.getAgent().getBundles(2).get(0);
    assertTrue(previousModified != t2Bundle.lastModified);
}
Also used : Version(aQute.bnd.version.Version) BundleDTO(org.osgi.framework.dto.BundleDTO) File(java.io.File)

Example 7 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class OSGiRepositoryTest method testPolling.

public void testPolling(Workspace workspace) throws Exception {
    try (OSGiRepository r = new OSGiRepository()) {
        Map<String, String> map = new HashMap<>();
        map.put("locations", fnx.getBaseURI("/repo/minir5.xml").toString());
        map.put("cache", cache.getPath());
        map.put("max.stale", "10000");
        map.put("name", "test");
        map.put("poll.time", "1");
        r.setProperties(map);
        Processor p = new Processor();
        HttpClient httpClient = new HttpClient();
        httpClient.setCache(cache);
        httpClient.setRegistry(p);
        p.addBasicPlugin(httpClient);
        p.setBase(ws);
        p.addBasicPlugin(workspace);
        r.setRegistry(p);
        final AtomicReference<RepositoryPlugin> refreshed = new AtomicReference<>();
        p.addBasicPlugin(new RepositoryListenerPlugin() {

            @Override
            public void repositoryRefreshed(RepositoryPlugin repository) {
                refreshed.set(repository);
            }

            @Override
            public void repositoriesRefreshed() {
            // TODO Auto-generated method stub
            }

            @Override
            public void bundleRemoved(RepositoryPlugin repository, Jar jar, File file) {
            // TODO Auto-generated method stub
            }

            @Override
            public void bundleAdded(RepositoryPlugin repository, Jar jar, File file) {
            // TODO Auto-generated method stub
            }
        });
        File file = r.get("dummybundle", new Version("0"), null);
        assertNotNull(file);
        // not stale, default name
        assertNull(r.title(new Object[0]));
        System.out.println("1");
        Thread.sleep(3000);
        System.out.println("2");
        assertEquals(null, refreshed.get());
        System.out.println("3");
        // update the index file
        File index = IO.getFile(remote, "minir5.xml");
        long time = index.lastModified();
        String s = IO.collect(index);
        // change the sha
        s += " ";
        IO.store(s, index);
        System.out.println("5 " + index + " " + (index.lastModified() - time));
        // give the poller a chance
        Thread.sleep(3000);
        System.out.println("6");
        assertEquals(r, refreshed.get());
        assertEquals("test [stale]", r.title(new Object[0]));
        System.out.println(r.tooltip(new Object[0]));
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) RepositoryListenerPlugin(aQute.bnd.service.RepositoryListenerPlugin) HashMap(java.util.HashMap) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) AtomicReference(java.util.concurrent.atomic.AtomicReference) Version(aQute.bnd.version.Version) HttpClient(aQute.bnd.http.HttpClient) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 8 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class OSGiIndexTest method testIndex.

public void testIndex() throws Exception {
    HttpClient client = new HttpClient();
    client.setCache(tmp);
    OSGiIndex oi = getIndex(client);
    List<String> list = oi.getBridge().list("osgi.enroute.*");
    assertNotNull(list);
    assertEquals(32, list.size());
    oi = getIndex(client);
    list = oi.getBridge().list("osgi.enroute.*");
    assertNotNull(list);
    assertEquals(32, list.size());
    System.out.println(list);
    SortedSet<Version> versions = oi.getBridge().versions("osgi.enroute.rest.simple.provider");
    assertEquals(1, versions.size());
    System.out.println(versions);
    File f = new File(tmp, "f");
    Promise<File> promise = oi.get("osgi.enroute.rest.simple.provider", new Version("2.0.2.201509211431"), f);
    assertNotNull(promise);
    File value = promise.getValue();
    assertEquals(value, f);
    promise = oi.get("osgi.enroute.rest.simple.provider", new Version("2.0.2.201509211431"), f);
    assertNotNull(promise);
}
Also used : Version(aQute.bnd.version.Version) HttpClient(aQute.bnd.http.HttpClient) File(java.io.File)

Example 9 with Version

use of aQute.bnd.version.Version in project bndtools by bndtools.

the class Auxiliary method doImport.

/*
    * Parse the exports and see
     *
     */
private boolean doImport(String exports) {
    if (closed.get() || exports == null || exports.isEmpty())
        return false;
    Parameters out = new Parameters();
    Parameters p = new Parameters(exports);
    for (Entry<String, Attrs> e : p.entrySet()) {
        Attrs attrs = e.getValue();
        if (attrs == null)
            continue;
        String plugins = attrs.get("bnd-plugins");
        if (plugins == null)
            continue;
        if (!(plugins.isEmpty() || "true".equalsIgnoreCase(plugins))) {
            if (Verifier.isVersionRange(plugins)) {
                VersionRange range = new VersionRange(plugins);
                if (// TODO
                !range.includes(About._3_0))
                    continue;
            }
        }
        //
        // Ok, matched
        //
        String v = attrs.getVersion();
        if (v == null)
            v = "0";
        for (Iterator<String> i = attrs.keySet().iterator(); i.hasNext(); ) {
            String key = i.next();
            if (key.endsWith(":"))
                i.remove();
        }
        if (Verifier.isVersion(v)) {
            Version version = new Version(v);
            attrs.put("version", new VersionRange(true, version, version, true).toString());
        }
        out.put(e.getKey(), attrs);
    }
    if (out.isEmpty())
        return false;
    String imports = out.toString();
    synchronized (this) {
        if (delta == null)
            delta = new ArrayList<>();
        delta.add(imports);
    }
    return true;
}
Also used : Parameters(aQute.bnd.header.Parameters) Version(aQute.bnd.version.Version) Attrs(aQute.bnd.header.Attrs) ArrayList(java.util.ArrayList) VersionRange(aQute.bnd.version.VersionRange)

Example 10 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class RemoteCommand method _distro.

public void _distro(DistroOptions opts) throws Exception {
    List<String> args = opts._arguments();
    String bsn;
    String version;
    bsn = args.remove(0);
    if (!Verifier.isBsn(bsn)) {
        error("Not a bundle symbolic name %s", bsn);
    }
    if (args.isEmpty())
        version = "0";
    else {
        version = args.remove(0);
        if (!Version.isVersion(version)) {
            error("Invalid version %s", version);
        }
    }
    File output = getFile(opts.output("distro.jar"));
    if (output.getParentFile() == null || !output.getParentFile().isDirectory()) {
        error("Cannot write to %s because parent not a directory", output);
    }
    if (output.isFile() && !output.canWrite()) {
        error("Cannot write to %s", output);
    }
    logger.debug("Starting distro {};{}", bsn, version);
    List<BundleRevisionDTO> bundleRevisons = agent.getBundleRevisons();
    logger.debug("Found {} bundle revisions", bundleRevisons.size());
    Parameters packages = new Parameters();
    List<Parameters> provided = new ArrayList<>();
    for (BundleRevisionDTO brd : bundleRevisons) {
        for (CapabilityDTO c : brd.capabilities) {
            CapabilityBuilder cb = new CapabilityBuilder(c.namespace);
            for (Entry<String, Object> e : c.attributes.entrySet()) {
                String key = e.getKey();
                Object value = e.getValue();
                if (key.equals("version")) {
                    if (value instanceof Collection || value.getClass().isArray())
                        value = Converter.cnv(tref, value);
                    else
                        value = new Version((String) value);
                }
                cb.addAttribute(key, value);
            }
            cb.addDirectives(c.directives);
            Attrs attrs = cb.toAttrs();
            if (cb.isPackage()) {
                attrs.remove(Constants.BUNDLE_SYMBOLIC_NAME_ATTRIBUTE);
                attrs.remove(Constants.BUNDLE_VERSION_ATTRIBUTE);
                String pname = attrs.remove(PackageNamespace.PACKAGE_NAMESPACE);
                if (pname == null) {
                    warning("Invalid package capability found %s", c);
                } else
                    packages.put(pname, attrs);
                logger.debug("P: {};{}", pname, attrs);
            } else if (NativeNamespace.NATIVE_NAMESPACE.equals(c.namespace)) {
                Attrs newAttrs = new Attrs();
                for (Entry<String, String> entry : attrs.entrySet()) {
                    if (entry.getKey().startsWith(NativeNamespace.NATIVE_NAMESPACE)) {
                        newAttrs.put(entry.getKey(), entry.getValue());
                    }
                }
                Parameters p = new Parameters();
                p.put(c.namespace, newAttrs);
                provided.add(p);
            } else if (!IGNORED_NAMESPACES.contains(c.namespace)) {
                logger.debug("C {};{}", c.namespace, attrs);
                Parameters p = new Parameters();
                p.put(c.namespace, attrs);
                provided.add(p);
            }
        }
    }
    if (isOk()) {
        Manifest m = new Manifest();
        Attributes main = m.getMainAttributes();
        main.putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
        main.putValue(Constants.BUNDLE_SYMBOLICNAME, bsn);
        main.putValue(Constants.BUNDLE_VERSION, version);
        main.putValue(Constants.EXPORT_PACKAGE, packages.toString());
        // Make distro unresolvable
        Parameters unresolveable = new Parameters("osgi.unresolvable; filter:='(&(must.not.resolve=*)(!(must.not.resolve=*)))'");
        main.putValue(Constants.REQUIRE_CAPABILITY, unresolveable.toString());
        provided.add(new Parameters("osgi.unresolvable"));
        StringBuilder sb = new StringBuilder();
        for (Parameters parameter : provided) {
            sb.append(parameter.toString());
            sb.append(",");
        }
        String capabilities = sb.toString().substring(0, sb.length() - 1);
        main.putValue(Constants.PROVIDE_CAPABILITY, capabilities);
        if (opts.description() != null)
            main.putValue(Constants.BUNDLE_DESCRIPTION, opts.description());
        if (opts.license() != null)
            main.putValue(Constants.BUNDLE_LICENSE, opts.license());
        if (opts.copyright() != null)
            main.putValue(Constants.BUNDLE_COPYRIGHT, opts.copyright());
        if (opts.vendor() != null)
            main.putValue(Constants.BUNDLE_VENDOR, opts.vendor());
        Jar jar = new Jar("distro");
        jar.setManifest(m);
        Verifier v = new Verifier(jar);
        v.setProperty(Constants.FIXUPMESSAGES, "osgi.* namespace must not be specified with generic capabilities");
        v.verify();
        v.getErrors();
        if (isFailOk() || v.isOk()) {
            jar.updateModified(System.currentTimeMillis(), "Writing distro jar");
            jar.write(output);
        } else
            getInfo(v);
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) BundleRevisionDTO(org.osgi.framework.wiring.dto.BundleRevisionDTO) ArrayList(java.util.ArrayList) Attrs(aQute.bnd.header.Attrs) Attributes(java.util.jar.Attributes) CapabilityBuilder(aQute.bnd.osgi.resource.CapabilityBuilder) Manifest(java.util.jar.Manifest) Verifier(aQute.bnd.osgi.Verifier) Entry(java.util.Map.Entry) CapabilityDTO(org.osgi.resource.dto.CapabilityDTO) Version(aQute.bnd.version.Version) Collection(java.util.Collection) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Aggregations

Version (aQute.bnd.version.Version)168 File (java.io.File)64 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)27 Attrs (aQute.bnd.header.Attrs)19 MavenVersion (aQute.bnd.version.MavenVersion)19 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)18 IOException (java.io.IOException)17 Jar (aQute.bnd.osgi.Jar)16 Workspace (aQute.bnd.build.Workspace)13 Project (aQute.bnd.build.Project)12 RevisionRef (aQute.service.library.Library.RevisionRef)12 Matcher (java.util.regex.Matcher)12 Parameters (aQute.bnd.header.Parameters)11 VersionRange (aQute.bnd.version.VersionRange)11 SortedList (aQute.lib.collections.SortedList)9 Processor (aQute.bnd.osgi.Processor)8 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)8 FileNotFoundException (java.io.FileNotFoundException)8 LinkedHashMap (java.util.LinkedHashMap)8