Search in sources :

Example 21 with Tag

use of aQute.lib.tag.Tag in project bnd by bndtools.

the class PomResource method write.

@Override
public void write(OutputStream out) throws IOException {
    PrintWriter pw = IO.writer(out);
    String description = manifest.getMainAttributes().getValue(Constants.BUNDLE_DESCRIPTION);
    String docUrl = manifest.getMainAttributes().getValue(Constants.BUNDLE_DOCURL);
    String bundleVendor = manifest.getMainAttributes().getValue(Constants.BUNDLE_VENDOR);
    String bundleLicense = manifest.getMainAttributes().getValue(Constants.BUNDLE_LICENSE);
    Tag project = new Tag("project");
    project.addAttribute("xmlns", "http://maven.apache.org/POM/4.0.0");
    project.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    project.addAttribute("xsi:schemaLocation", "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd");
    project.addContent(new Tag("modelVersion").addContent("4.0.0"));
    project.addContent(new Tag("groupId").addContent(getGroupId()));
    project.addContent(new Tag("artifactId").addContent(getArtifactId()));
    project.addContent(new Tag(VERSION).addContent(getVersion()));
    if (description == null) {
        description = name;
    }
    new Tag(project, "description").addContent(description);
    new Tag(project, "name").addContent(name);
    if (docUrl != null) {
        new Tag(project, "url").addContent(docUrl);
    }
    if (scm != null) {
        Tag scm = new Tag(project, "scm");
        for (Map.Entry<String, String> e : this.scm.entrySet()) {
            new Tag(scm, e.getKey()).addContent(e.getValue());
        }
    }
    if (bundleVendor != null) {
        Matcher m = NAME_URL.matcher(bundleVendor);
        String namePart = bundleVendor;
        String urlPart = null;
        if (m.matches()) {
            namePart = m.group(1);
            urlPart = m.group(2);
        }
        Tag organization = new Tag(project, "organization");
        new Tag(organization, "name").addContent(namePart.trim());
        if (urlPart != null) {
            new Tag(organization, "url").addContent(urlPart.trim());
        }
    }
    Tag ls = null;
    Parameters licenses = new Parameters(bundleLicense, processor);
    for (Entry<String, Attrs> license : licenses.entrySet()) {
        // Bundle-License: identifier;description="description";link="URL"
        //
        // <licenses>
        //   <license>
        //     <name>identifier</name>
        //     <url>URL</url>
        //     <distribution>repo</distribution>
        //     <comments>description</comments>
        //   </license>
        // </licenses>
        String identifier = license.getKey();
        if (identifier == null)
            continue;
        identifier = identifier.trim();
        if (identifier.equals("<<EXTERNAL>>"))
            continue;
        if (ls == null)
            ls = new Tag(project, "licenses");
        Tag l = new Tag(ls, "license");
        Map<String, String> attrs = license.getValue();
        tagFromMap(l, attrs, "name", "name", identifier);
        tagFromMap(l, attrs, "link", "url", identifier);
        tagFromMap(l, attrs, "distribution", "distribution", "repo");
        tagFromMap(l, attrs, "description", "comments", null);
    }
    String scm = manifest.getMainAttributes().getValue(Constants.BUNDLE_SCM);
    if (scm != null && scm.length() > 0) {
        Attrs pscm = OSGiHeader.parseProperties(scm);
        Tag tscm = new Tag(project, "scm");
        for (String s : pscm.keySet()) {
            new Tag(tscm, s, pscm.get(s));
        }
    }
    Parameters developers = new Parameters(manifest.getMainAttributes().getValue(Constants.BUNDLE_DEVELOPERS), processor);
    if (developers.size() > 0) {
        Tag tdevelopers = new Tag(project, "developers");
        for (String id : developers.keySet()) {
            Tag tdeveloper = new Tag(tdevelopers, "developer");
            new Tag(tdeveloper, "id", id);
            Attrs i = new Attrs(developers.get(id));
            if (!i.containsKey("email"))
                i.put("email", id);
            i.remove("id");
            for (String s : i.keySet()) {
                if (s.equals("roles")) {
                    Tag troles = new Tag(tdeveloper, "roles");
                    String[] roles = i.get(s).trim().split("\\s*,\\s*");
                    for (String role : roles) {
                        new Tag(troles, "role", role);
                    }
                } else
                    new Tag(tdeveloper, s, i.get(s));
            }
        }
    }
    String validate = project.validate();
    if (validate != null)
        throw new IllegalArgumentException(validate);
    pw.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    project.print(0, pw);
    pw.flush();
}
Also used : Parameters(aQute.bnd.header.Parameters) Matcher(java.util.regex.Matcher) Attrs(aQute.bnd.header.Attrs) Tag(aQute.lib.tag.Tag) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 22 with Tag

use of aQute.lib.tag.Tag in project bnd by bndtools.

the class XMLResourceGenerator method attributes.

private void attributes(Tag cr, Map<String, Object> atrributes) throws Exception {
    for (Entry<String, Object> e : atrributes.entrySet()) {
        Object value = e.getValue();
        if (value == null)
            continue;
        TypedAttribute ta = TypedAttribute.getTypedAttribute(value);
        if (ta == null)
            continue;
        Tag d = new Tag(cr, "attribute");
        d.addAttribute("name", e.getKey());
        d.addAttribute("value", ta.value);
        if (ta.type != null)
            d.addAttribute("type", ta.type);
    }
}
Also used : TypedAttribute(aQute.bnd.osgi.resource.TypedAttribute) Tag(aQute.lib.tag.Tag)

Example 23 with Tag

use of aQute.lib.tag.Tag in project bnd by bndtools.

the class XMLResourceGenerator method resource.

public XMLResourceGenerator resource(Resource resource) throws Exception {
    if (!visited.contains(resource)) {
        visited.add(resource);
        Tag r = new Tag(repository, "resource");
        for (Capability cap : resource.getCapabilities(null)) {
            Tag cr = new Tag(r, "capability");
            cr.addAttribute("namespace", cap.getNamespace());
            directives(cr, cap.getDirectives());
            attributes(cr, cap.getAttributes());
        }
        for (Requirement req : resource.getRequirements(null)) {
            Tag cr = new Tag(r, "requirement");
            cr.addAttribute("namespace", req.getNamespace());
            directives(cr, req.getDirectives());
            attributes(cr, req.getAttributes());
        }
    }
    return this;
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) Tag(aQute.lib.tag.Tag)

Example 24 with Tag

use of aQute.lib.tag.Tag in project bnd by bndtools.

the class XMLResourceGenerator method directives.

private void directives(Tag cr, Map<String, String> directives) {
    for (Entry<String, String> e : directives.entrySet()) {
        Tag d = new Tag(cr, "directive");
        d.addAttribute("name", e.getKey());
        d.addAttribute("value", e.getValue());
    }
}
Also used : Tag(aQute.lib.tag.Tag)

Example 25 with Tag

use of aQute.lib.tag.Tag in project bnd by bndtools.

the class BaselineCommands method getTag.

private Tag getTag(Info info) {
    Tag tag = new Tag("info");
    tag.addAttribute("name", info.packageName);
    tag.addAttribute("newerVersion", info.newerVersion);
    tag.addAttribute("olderVersion", info.olderVersion);
    tag.addAttribute("suggestedVersion", info.suggestedVersion);
    tag.addAttribute("suggestedIfProviders", info.suggestedIfProviders);
    tag.addAttribute("mismatch", info.mismatch);
    tag.addAttribute("warning", info.warning);
    StringBuilder sb = new StringBuilder();
    if (info.packageDiff.getDelta() == Delta.UNCHANGED)
        tag.addAttribute("equals", "true");
    else {
        traverseTag(sb, info.packageDiff, "");
        String s = sb.toString().trim();
        if (s.length() != 0) {
            Tag d = new Tag(tag, "diff", s);
            d.setCDATA();
        }
    }
    if (info.providers != null)
        for (String provider : info.providers) {
            Tag p = new Tag(tag, "provider");
            p.addAttribute("provider", provider);
        }
    return tag;
}
Also used : Tag(aQute.lib.tag.Tag)

Aggregations

Tag (aQute.lib.tag.Tag)28 PrintWriter (java.io.PrintWriter)8 File (java.io.File)5 Attrs (aQute.bnd.header.Attrs)3 Parameters (aQute.bnd.header.Parameters)3 TypeRef (aQute.bnd.osgi.Descriptors.TypeRef)3 Namespaces (aQute.bnd.xmlattribute.Namespaces)3 List (java.util.List)3 Map (java.util.Map)3 Matcher (java.util.regex.Matcher)3 MethodDef (aQute.bnd.osgi.Clazz.MethodDef)2 Instructions (aQute.bnd.osgi.Instructions)2 Diff (aQute.bnd.service.diff.Diff)2 Tree (aQute.bnd.service.diff.Tree)2 MultiMap (aQute.lib.collections.MultiMap)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Date (java.util.Date)2 Meta (aQute.bnd.annotation.metatype.Meta)1 Project (aQute.bnd.build.Project)1