Search in sources :

Example 1 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 2 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 3 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 4 with Tag

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

the class bnd method runtTest.

/**
	 * Help function to run the tests
	 */
private int runtTest(File testFile, Workspace ws, File reportDir, Tag summary) throws Exception {
    File tmpDir = new File(reportDir, "tmp");
    IO.mkdirs(tmpDir);
    tmpDir.deleteOnExit();
    Tag test = new Tag(summary, "test");
    test.addAttribute("path", testFile.getAbsolutePath());
    if (!testFile.isFile()) {
        error("No bnd file: %s", testFile);
        test.addAttribute("exception", "No bnd file found");
        error("No bnd file found for %s", testFile.getAbsolutePath());
        return 1;
    }
    Project project = new Project(ws, testFile.getAbsoluteFile().getParentFile(), testFile.getAbsoluteFile());
    project.use(this);
    project.setProperty(NOBUNDLES, "true");
    ProjectTester tester = project.getProjectTester();
    if (!project.isOk()) {
        getInfo(project, project.toString() + ": " + testFile.getName() + ":");
        // Indicate failure but do not abort
        return 1;
    }
    tester.setContinuous(false);
    tester.setReportDir(tmpDir);
    test.addAttribute("title", project.toString());
    long start = System.currentTimeMillis();
    try {
        int errors = tester.test();
        Collection<File> reports = tester.getReports();
        for (File report : reports) {
            Tag bundle = new Tag(test, "bundle");
            File dest = new File(reportDir, report.getName());
            IO.rename(report, dest);
            bundle.addAttribute("file", dest.getAbsolutePath());
            doPerReport(bundle, dest);
        }
        switch(errors) {
            case ProjectLauncher.OK:
                return 0;
            case ProjectLauncher.CANCELED:
                test.addAttribute("failed", "canceled");
                return 1;
            case ProjectLauncher.DUPLICATE_BUNDLE:
                test.addAttribute("failed", "duplicate bundle");
                return 1;
            case ProjectLauncher.ERROR:
                test.addAttribute("failed", "unknown reason");
                return 1;
            case ProjectLauncher.RESOLVE_ERROR:
                test.addAttribute("failed", "resolve error");
                return 1;
            case ProjectLauncher.TIMEDOUT:
                test.addAttribute("failed", "timed out");
                return 1;
            case ProjectLauncher.WARNING:
                test.addAttribute("warning", "true");
                return 1;
            case ProjectLauncher.ACTIVATOR_ERROR:
                test.addAttribute("failed", "activator error");
                return 1;
            default:
                if (errors > 0) {
                    test.addAttribute("errors", errors);
                    return errors;
                }
                test.addAttribute("failed", "unknown reason");
                return errors;
        }
    } catch (Exception e) {
        test.addAttribute("failed", e);
        exception(e, "Exception in run %s", e);
        return 1;
    } finally {
        long duration = System.currentTimeMillis() - start;
        test.addAttribute("duration", (duration + 500) / 1000);
        getInfo(project, project.toString() + ": ");
    }
}
Also used : Project(aQute.bnd.build.Project) Tag(aQute.lib.tag.Tag) ProjectTester(aQute.bnd.build.ProjectTester) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ZipException(java.util.zip.ZipException)

Example 5 with Tag

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

the class bnd method _runtests.

/**
	 * Run the tests from a prepared bnd file.
	 * 
	 * @throws Exception
	 */
@Description("Run OSGi tests and create report")
public void _runtests(runtestsOptions opts) throws Exception {
    int errors = 0;
    File cwd = new File("").getAbsoluteFile();
    Workspace ws = new Workspace(cwd);
    try {
        File reportDir = getFile("reports");
        IO.delete(reportDir);
        Tag summary = new Tag("summary");
        summary.addAttribute("date", new Date());
        summary.addAttribute("ws", ws.getBase());
        if (opts.reportdir() != null) {
            reportDir = getFile(opts.reportdir());
        }
        IO.mkdirs(reportDir);
        if (!reportDir.isDirectory())
            error("reportdir must be a directory %s (tried to create it ...)", reportDir);
        if (opts.title() != null)
            summary.addAttribute("title", opts.title());
        if (opts.dir() != null)
            cwd = getFile(opts.dir());
        if (opts.workspace() != null) {
            ws.close();
            ws = Workspace.getWorkspace(getFile(opts.workspace()));
        }
        // TODO check all the arguments
        boolean hadOne = false;
        try {
            for (String arg : opts._arguments()) {
                logger.debug("will run test {}", arg);
                File f = getFile(arg);
                errors += runtTest(f, ws, reportDir, summary);
                hadOne = true;
            }
            if (!hadOne) {
                // See if we had any, if so, just use all files in
                // the current directory
                File[] files = cwd.listFiles();
                for (File f : files) {
                    if (f.getName().endsWith(".bnd")) {
                        errors += runtTest(f, ws, reportDir, summary);
                    }
                }
            }
        } catch (Throwable e) {
            if (isExceptions()) {
                printExceptionSummary(e, out);
            }
            exception(e, "FAILURE IN RUNTESTS");
            errors++;
        }
        if (errors > 0)
            summary.addAttribute("errors", errors);
        for (String error : getErrors()) {
            Tag e = new Tag("error");
            e.addContent(error);
        }
        for (String warning : getWarnings()) {
            Tag e = new Tag("warning");
            e.addContent(warning);
        }
        File r = getFile(reportDir, "summary.xml");
        try (PrintWriter pw = IO.writer(r, UTF_8)) {
            summary.print(0, pw);
        }
        if (errors != 0)
            error("Errors found %s", errors);
    } finally {
        ws.close();
    }
}
Also used : Tag(aQute.lib.tag.Tag) File(java.io.File) Date(java.util.Date) Workspace(aQute.bnd.build.Workspace) PrintWriter(java.io.PrintWriter) Description(aQute.lib.getopt.Description)

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