Search in sources :

Example 71 with Version

use of org.osgi.framework.Version in project bnd by bndtools.

the class Activator method getReportWriter.

private Writer getReportWriter(File reportDir, Bundle bundle) throws IOException {
    if (reportDir.isDirectory()) {
        Version v = bundle.getVersion();
        File f = new File(reportDir, "TEST-" + bundle.getSymbolicName() + "-" + v.getMajor() + "." + v.getMinor() + "." + v.getMicro() + ".xml");
        Writer writer = new OutputStreamWriter(Files.newOutputStream(f.toPath()), UTF_8);
        writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        return writer;
    }
    return null;
}
Also used : Version(org.osgi.framework.Version) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 72 with Version

use of org.osgi.framework.Version in project bnd by bndtools.

the class ArtifactRepository method parse.

void parse() throws Exception {
    final Map<String, String> properties = getProperties("repository/properties/property");
    properties.put("repoUrl", base.resolve("").toString());
    final Domain parent = new Domain() {

        @Override
        public Map<String, String> getMap() {
            return properties;
        }

        @Override
        public Domain getParent() {
            return null;
        }
    };
    rules = getRules();
    NodeList artifactNodes = getNodes("repository/artifacts/artifact");
    for (int i = 0; i < artifactNodes.getLength(); i++) {
        final Node artifactNode = artifactNodes.item(i).cloneNode(true);
        final XMLArtifact xmlArtifact = getFromType(artifactNode, XMLArtifact.class);
        final Map<String, String> map = Converter.cnv(new TypeReference<Map<String, String>>() {
        }, xmlArtifact);
        if ("osgi.bundle".equals(xmlArtifact.classifier)) {
            Domain domain = new Domain() {

                @Override
                public Map<String, String> getMap() {
                    return map;
                }

                @Override
                public Domain getParent() {
                    return parent;
                }
            };
            ReplacerAdapter ra = new ReplacerAdapter(domain);
            for (Rule r : rules) {
                if (r.matches(map)) {
                    String s = ra.process(r.output);
                    URI uri = new URI(s).normalize();
                    Artifact artifact = new Artifact();
                    artifact.uri = uri;
                    artifact.id = xmlArtifact.id;
                    artifact.version = new Version(xmlArtifact.version);
                    artifact.md5 = getProperties(artifactNode, "properties/property").get("download.md5");
                    artifacts.add(artifact);
                    break;
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) URI(java.net.URI) Artifact(aQute.p2.api.Artifact) Version(org.osgi.framework.Version) ReplacerAdapter(aQute.libg.sed.ReplacerAdapter) Domain(aQute.libg.sed.Domain) Map(java.util.Map)

Example 73 with Version

use of org.osgi.framework.Version in project Lucee by lucee.

the class OSGiUtil method toPackageDefinition.

private static PackageDefinition toPackageDefinition(String str, String filterPackageName, List<VersionDefinition> versionDefinitions) {
    // first part is the package
    StringList list = ListUtil.toList(str, ';');
    PackageDefinition pd = null;
    String token;
    Version v;
    while (list.hasNext()) {
        token = list.next().trim();
        if (pd == null) {
            if (!token.equals(filterPackageName))
                return null;
            pd = new PackageDefinition(token);
        } else // only intressted in version
        {
            StringList entry = ListUtil.toList(token, '=');
            if (entry.size() == 2 && entry.next().trim().equalsIgnoreCase("version")) {
                String version = StringUtil.unwrap(entry.next().trim());
                if (!version.equals("0.0.0")) {
                    v = OSGiUtil.toVersion(version, null);
                    if (v != null) {
                        if (versionDefinitions != null) {
                            Iterator<VersionDefinition> it = versionDefinitions.iterator();
                            while (it.hasNext()) {
                                if (!it.next().matches(v)) {
                                    return null;
                                }
                            }
                        }
                        pd.setVersion(v);
                    }
                }
            }
        }
    }
    return pd;
}
Also used : StringList(lucee.commons.lang.StringList) Version(org.osgi.framework.Version)

Example 74 with Version

use of org.osgi.framework.Version in project Lucee by lucee.

the class OSGiUtil method toVersion.

public static Version toVersion(String version, Version defaultValue) {
    if (StringUtil.isEmpty(version))
        return defaultValue;
    // String[] arr = ListUtil.listToStringArray(version, '.');
    String[] arr;
    try {
        arr = ListUtil.toStringArrayTrim(ListUtil.listToArray(version.trim(), '.'));
    } catch (PageException e) {
        // should not happen
        return defaultValue;
    }
    Integer major, minor, micro;
    String qualifier;
    if (arr.length == 1) {
        major = Caster.toInteger(arr[0], null);
        minor = 0;
        micro = 0;
        qualifier = null;
    } else if (arr.length == 2) {
        major = Caster.toInteger(arr[0], null);
        minor = Caster.toInteger(arr[1], null);
        micro = 0;
        qualifier = null;
    } else if (arr.length == 3) {
        major = Caster.toInteger(arr[0], null);
        minor = Caster.toInteger(arr[1], null);
        micro = Caster.toInteger(arr[2], null);
        qualifier = null;
    } else {
        major = Caster.toInteger(arr[0], null);
        minor = Caster.toInteger(arr[1], null);
        micro = Caster.toInteger(arr[2], null);
        qualifier = arr[3];
    }
    if (major == null || minor == null || micro == null)
        return defaultValue;
    if (qualifier == null)
        return new Version(major, minor, micro);
    return new Version(major, minor, micro, qualifier);
}
Also used : PageException(lucee.runtime.exp.PageException) Version(org.osgi.framework.Version)

Example 75 with Version

use of org.osgi.framework.Version in project Lucee by lucee.

the class Admin method doChangeVersionTo.

private void doChangeVersionTo() throws PageException {
    try {
        Version version = OSGiUtil.toVersion(getString("admin", "changeVersionTo", "version"));
        admin.changeVersionTo(version, password, // ,pageContext.getConfig().getLog("Application")
        pageContext.getConfig().getIdentification());
        adminSync.broadcast(attributes, config);
    } catch (BundleException e) {
        throw Caster.toPageException(e);
    }
}
Also used : Version(org.osgi.framework.Version) BundleException(org.osgi.framework.BundleException)

Aggregations

Version (org.osgi.framework.Version)222 Test (org.junit.Test)35 ArrayList (java.util.ArrayList)28 Bundle (org.osgi.framework.Bundle)27 File (java.io.File)23 HashMap (java.util.HashMap)21 Capability (org.osgi.resource.Capability)20 IOException (java.io.IOException)19 BundleException (org.osgi.framework.BundleException)15 Resource (org.osgi.resource.Resource)14 InputStream (java.io.InputStream)12 Map (java.util.Map)11 Manifest (java.util.jar.Manifest)11 List (java.util.List)10 URL (java.net.URL)8 HashSet (java.util.HashSet)8 Content (org.apache.aries.application.Content)8 AriesApplication (org.apache.aries.application.management.AriesApplication)8 VersionRange (org.apache.felix.utils.version.VersionRange)8 BundleRevision (org.osgi.framework.wiring.BundleRevision)8