Search in sources :

Example 16 with Tag

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

the class MetaTypeReader method addMethod.

private void addMethod(MethodDef method, Meta.AD ad) throws Exception {
    if (method.isStatic())
        return;
    // Set all the defaults.
    String rtype = method.getGenericReturnType();
    String id = Configurable.mangleMethodName(method.getName());
    String name = Clazz.unCamel(id);
    int cardinality = 0;
    if (rtype.endsWith("[]")) {
        cardinality = Integer.MAX_VALUE;
        rtype = rtype.substring(0, rtype.length() - 2);
    }
    if (rtype.indexOf('<') > 0) {
        if (cardinality != 0)
            reporter.error("AD for %s.%s uses an array of collections in return type (%s), Metatype allows either Vector or array", clazz.getClassName().getFQN(), method.getName(), method.getType().getFQN());
        Matcher m = COLLECTION.matcher(rtype);
        if (m.matches()) {
            rtype = Clazz.objectDescriptorToFQN(m.group(3));
            cardinality = Integer.MIN_VALUE;
        }
    }
    Meta.Type type = getType(rtype);
    boolean required = ad == null || ad.required();
    String deflt = null;
    String max = null;
    String min = null;
    String[] optionLabels = null;
    String[] optionValues = null;
    String description = null;
    TypeRef typeRef = reporter.getTypeRefFromFQN(rtype);
    Clazz c = reporter.findClass(typeRef);
    if (c != null && c.isEnum()) {
        optionValues = parseOptionValues(c);
    }
    if (ad != null) {
        if (ad.id() != null)
            id = ad.id();
        if (ad.name() != null)
            name = ad.name();
        if (ad.cardinality() != 0)
            cardinality = ad.cardinality();
        if (ad.type() != null)
            type = ad.type();
        if (ad.description() != null)
            description = ad.description();
        if (ad.optionLabels() != null)
            optionLabels = ad.optionLabels();
        if (ad.optionValues() != null)
            optionValues = ad.optionValues();
        if (ad.min() != null)
            min = ad.min();
        if (ad.max() != null)
            max = ad.max();
        if (ad.deflt() != null)
            deflt = ad.deflt();
    }
    if (optionValues != null) {
        if (optionLabels == null || optionLabels.length == 0) {
            optionLabels = new String[optionValues.length];
            for (int i = 0; i < optionValues.length; i++) optionLabels[i] = Clazz.unCamel(optionValues[i]);
        }
        if (optionLabels.length != optionValues.length) {
            reporter.error("Option labels and option values not the same length for %s", id);
            optionLabels = optionValues;
        }
    }
    Tag adt = new Tag(this.ocd, "AD");
    adt.addAttribute("name", name);
    adt.addAttribute("id", id);
    adt.addAttribute("cardinality", cardinality);
    adt.addAttribute("required", required);
    adt.addAttribute("default", deflt);
    adt.addAttribute("type", type);
    adt.addAttribute("max", max);
    adt.addAttribute("min", min);
    adt.addAttribute("description", description);
    if (optionLabels != null && optionValues != null) {
        for (int i = 0; i < optionLabels.length; i++) {
            Tag option = new Tag(adt, "Option");
            option.addAttribute("label", optionLabels[i]);
            option.addAttribute("value", optionValues[i]);
        }
    }
}
Also used : Meta(aQute.bnd.annotation.metatype.Meta) Matcher(java.util.regex.Matcher) TypeRef(aQute.bnd.osgi.Descriptors.TypeRef) Clazz(aQute.bnd.osgi.Clazz) Tag(aQute.lib.tag.Tag)

Example 17 with Tag

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

the class OCDDef method getTag.

Tag getTag() {
    Tag metadata = new Tag("metatype:MetaData");
    // .addAttribute("xmlns:metatype",
    // MetatypeVersion.VERSION_1_3.getNamespace());
    Namespaces namespaces = new Namespaces();
    String xmlns = version.getNamespace();
    namespaces.registerNamespace("metatype", xmlns);
    addNamespaces(namespaces, xmlns);
    for (ADDef ad : attributes) ad.addNamespaces(namespaces, xmlns);
    for (DesignateDef dd : designates) dd.addNamespaces(namespaces, xmlns);
    namespaces.addNamespaces(metadata);
    if (localization != null) {
        metadata.addAttribute("localization", localization);
    }
    Tag ocd = new Tag(metadata, "OCD").addAttribute("id", id);
    if (name != null) {
        ocd.addAttribute("name", name);
    }
    if (description != null) {
        ocd.addAttribute("description", description);
    }
    addAttributes(ocd, namespaces);
    for (ADDef ad : attributes) {
        ocd.addContent(ad.getTag(namespaces));
    }
    for (IconDef icon : icons) {
        ocd.addContent(icon.getTag());
    }
    for (DesignateDef designate : designates) {
        metadata.addContent(designate.getInnerTag(namespaces));
    }
    return metadata;
}
Also used : Namespaces(aQute.bnd.xmlattribute.Namespaces) Tag(aQute.lib.tag.Tag)

Example 18 with Tag

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

the class ADDef method getTag.

Tag getTag(Namespaces namespaces) {
    Tag ad = new Tag("AD").addAttribute("id", id).addAttribute("type", typeString);
    if (cardinality != 0) {
        ad.addAttribute("cardinality", cardinality);
    }
    if (!required) {
        ad.addAttribute("required", required);
    }
    if (name != null) {
        ad.addAttribute("name", name);
    }
    if (description != null) {
        ad.addAttribute("description", description);
    }
    if (min != null) {
        ad.addAttribute("min", min);
    }
    if (max != null) {
        ad.addAttribute("max", max);
    }
    if (defaults != null) {
        StringBuffer b = new StringBuffer();
        String sep = "";
        for (String defaultValue : defaults) {
            b.append(sep);
            escape(defaultValue, b);
            sep = ",";
        }
        ad.addAttribute("default", b.toString());
    }
    for (OptionDef option : options) {
        ad.addContent(option.getTag());
    }
    addAttributes(ad, namespaces);
    return ad;
}
Also used : Tag(aQute.lib.tag.Tag)

Example 19 with Tag

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

the class Tool method printOverview.

void printOverview(String name, String version, String bundleDescription) throws FileNotFoundException {
    Tag body = new Tag("body");
    new Tag(body, "h1", name);
    new Tag(body, "p", "Version " + version);
    new Tag(body, "p", bundleDescription);
    Tag table = new Tag(body, "table");
    for (String key : manifest) {
        if (key.equalsIgnoreCase(Constants.BUNDLE_DESCRIPTION) || key.equalsIgnoreCase(Constants.BUNDLE_VERSION))
            continue;
        Tag tr = new Tag(table, "tr");
        new Tag(tr, "td", key);
        new Tag(tr, "td", manifest.get(key));
    }
    File overview = new File(sources, "overview.html");
    try (PrintWriter pw = new PrintWriter(overview)) {
        body.print(2, pw);
    }
}
Also used : Tag(aQute.lib.tag.Tag) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 20 with Tag

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

the class PomResource method tagFromMap.

/**
	 * Utility function to print a tag from a map
	 * 
	 * @param parent
	 * @param attrs
	 * @param key
	 * @param tag
	 * @param defaultValue
	 */
private Tag tagFromMap(Tag parent, Map<String, String> attrs, String key, String tag, String defaultValue) {
    String value = attrs.get(key);
    if (value == null)
        value = attrs.get(tag);
    if (value == null)
        value = defaultValue;
    if (value == null)
        return parent;
    new Tag(parent, tag).addContent(value.trim());
    return parent;
}
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