Search in sources :

Example 6 with Tag

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

the class PomGenerator method out.

public void out(OutputStream out) throws IOException {
    try (Writer w = new OutputStreamWriter(out, StandardCharsets.UTF_8)) {
        PrintWriter pw = new PrintWriter(w);
        pw.println("<?xml version='1.0' encoding='UTF-8'?>");
        Tag tag = build();
        tag.print(1, pw);
    }
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) Tag(aQute.lib.tag.Tag) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter)

Example 7 with Tag

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

the class DiffCommand method diff.

private void diff(diffOptions options, DiffPluginImpl di, Jar newer, Jar older) throws Exception {
    if (newer == null) {
        bnd.error("No newer file specified");
        return;
    }
    if (older == null) {
        bnd.error("No older file specified");
        return;
    }
    PrintWriter pw = null;
    try {
        File fout = options.output();
        if (fout == null)
            pw = IO.writer(bnd.out);
        else
            pw = IO.writer(fout, UTF_8);
        Instructions packageFilters = new Instructions(options.pack());
        if (options.ignore() != null)
            di.setIgnore(Processor.join(options.ignore()));
        Tree n = di.tree(newer);
        Tree o = di.tree(older);
        Diff diff = n.diff(o);
        boolean all = options.api() == false && options.resources() == false && options.manifest() == false;
        if (!options.xml()) {
            if (all || options.api())
                for (Diff packageDiff : diff.get("<api>").getChildren()) {
                    if (packageFilters.matches(packageDiff.getName()))
                        show(pw, packageDiff, 0, !options.full());
                }
            if (all || options.manifest())
                show(pw, diff.get("<manifest>"), 0, !options.full());
            if (all || options.resources())
                show(pw, diff.get("<resources>"), 0, !options.full());
        } else {
            Tag tag = new Tag("diff");
            tag.addAttribute("date", new Date());
            tag.addContent(getTagFrom("newer", newer));
            tag.addContent(getTagFrom("older", older));
            if (all || options.api())
                tag.addContent(getTagFrom(diff.get("<api>"), !options.full()));
            if (all || options.manifest())
                tag.addContent(getTagFrom(diff.get("<manifest>"), !options.full()));
            if (all || options.resources())
                tag.addContent(getTagFrom(diff.get("<resources>"), !options.full()));
            pw.print("<?xml version='1.0' encoding='UTF-8'?>\n");
            tag.print(0, pw);
        }
    } finally {
        if (older != null) {
            older.close();
        }
        if (newer != null) {
            newer.close();
        }
        if (pw != null) {
            pw.close();
        }
    }
}
Also used : Diff(aQute.bnd.service.diff.Diff) Tree(aQute.bnd.service.diff.Tree) Instructions(aQute.bnd.osgi.Instructions) Tag(aQute.lib.tag.Tag) File(java.io.File) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Example 8 with Tag

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

the class DiffCommand method getTagFrom.

private static Tag getTagFrom(String name, Jar jar) throws Exception {
    Tag tag = new Tag(name);
    tag.addAttribute("bsn", jar.getBsn());
    tag.addAttribute("name", jar.getName());
    tag.addAttribute("version", jar.getVersion());
    tag.addAttribute("lastmodified", jar.lastModified());
    return tag;
}
Also used : Tag(aQute.lib.tag.Tag)

Example 9 with Tag

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

the class DiffCommand method getTagFrom.

private static Tag getTagFrom(Diff diff, boolean limited) {
    if (limited && (diff.getDelta() == Delta.UNCHANGED || diff.getDelta() == Delta.IGNORED))
        return null;
    Tag tag = new Tag("diff");
    tag.addAttribute("name", diff.getName());
    tag.addAttribute("delta", diff.getDelta());
    tag.addAttribute("type", diff.getType());
    if (limited && (diff.getDelta() == Delta.ADDED || diff.getDelta() == Delta.REMOVED))
        return tag;
    for (Diff c : diff.getChildren()) {
        Tag child = getTagFrom(c, limited);
        if (child != null)
            tag.addContent(child);
    }
    return tag;
}
Also used : Diff(aQute.bnd.service.diff.Diff) Tag(aQute.lib.tag.Tag)

Example 10 with Tag

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

the class PomFromManifest method write.

@Override
public void write(OutputStream out) throws IOException {
    PrintWriter ps = IO.writer(out);
    String name = manifest.getMainAttributes().getValue(Analyzer.BUNDLE_NAME);
    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 licenses = 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().toString()));
    if (description != null) {
        new Tag(project, "description").addContent(description);
    }
    if (name != null) {
        new Tag(project, "name").addContent(name);
    }
    if (projectURL != null)
        new Tag(project, "url").addContent(projectURL);
    else if (docUrl != null) {
        new Tag(project, "url").addContent(docUrl);
    } else
        new Tag(project, "url").addContent("http://no-url");
    String scmheader = manifest.getMainAttributes().getValue("Bundle-SCM");
    if (scmheader != null)
        scm.add(scmheader);
    Tag scmtag = new Tag(project, "scm");
    if (scm != null && !scm.isEmpty()) {
        for (String cm : this.scm) {
            new Tag(scmtag, "url").addContent(cm);
            new Tag(scmtag, "connection").addContent(cm);
            new Tag(scmtag, "developerConnection").addContent(cm);
        }
    } else {
        new Tag(scmtag, "url").addContent("private");
        new Tag(scmtag, "connection").addContent("private");
        new Tag(scmtag, "developerConnection").addContent("private");
    }
    if (bundleVendor != null) {
        Matcher m = NAME_URL.matcher(bundleVendor);
        String namePart = bundleVendor;
        String urlPart = this.projectURL;
        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());
        }
    }
    if (!developers.isEmpty()) {
        Tag d = new Tag(project, "developers");
        for (String email : developers) {
            String id = email;
            String xname = email;
            String organization = null;
            Matcher m = Pattern.compile("([^@]+)@([\\d\\w\\-_\\.]+)\\.([\\d\\w\\-_\\.]+)").matcher(email);
            if (m.matches()) {
                xname = m.group(1);
                organization = m.group(2);
            }
            Tag developer = new Tag(d, "developer");
            new Tag(developer, "id").addContent(id);
            new Tag(developer, "name").addContent(xname);
            new Tag(developer, "email").addContent(email);
            if (organization != null)
                new Tag(developer, "organization").addContent(organization);
        }
    }
    if (licenses != null) {
        Tag ls = new Tag(project, "licenses");
        Parameters map = Processor.parseHeader(licenses, null);
        for (Iterator<Entry<String, Attrs>> e = map.entrySet().iterator(); e.hasNext(); ) {
            // Bundle-License:
            // http://www.opensource.org/licenses/apache2.0.php; \
            // description="${Bundle-Copyright}"; \
            // link=LICENSE
            //
            //  <license>
            //    <name>This material is licensed under the Apache
            // Software License, Version 2.0</name>
            //    <url>http://www.apache.org/licenses/LICENSE-2.0</url>
            //    <distribution>repo</distribution>
            //    </license>
            Entry<String, Attrs> entry = e.next();
            Tag l = new Tag(ls, "license");
            Map<String, String> values = entry.getValue();
            String url = entry.getKey();
            if (values.containsKey("description"))
                tagFromMap(l, values, "description", "name", url);
            else
                tagFromMap(l, values, "name", "name", url);
            tagFromMap(l, values, "url", "url", url);
            tagFromMap(l, values, "distribution", "distribution", "repo");
        }
    }
    project.print(0, ps);
    ps.flush();
}
Also used : Entry(java.util.Map.Entry) Parameters(aQute.bnd.header.Parameters) Matcher(java.util.regex.Matcher) Attrs(aQute.bnd.header.Attrs) Tag(aQute.lib.tag.Tag) PrintWriter(java.io.PrintWriter)

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