Search in sources :

Example 1 with XMLElement

use of org.jacoco.report.internal.xml.XMLElement in project jacoco by jacoco.

the class XmlDocumentation method main.

/**
 * Called during the build process.
 *
 * @param args
 *            exactly one argument expected with the target location
 * @throws IOException
 *             if XML document cannot be written
 */
public static void main(final String... args) throws IOException {
    final File file = new File(args[0]);
    file.getParentFile().mkdirs();
    final XMLElement root = new XMLDocument("documentation", null, null, "UTF-8", true, new FileOutputStream(file));
    for (final Command c : AllCommands.get()) {
        writeCommand(c, root);
    }
    root.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) XMLElement(org.jacoco.report.internal.xml.XMLElement) File(java.io.File) XMLDocument(org.jacoco.report.internal.xml.XMLDocument)

Example 2 with XMLElement

use of org.jacoco.report.internal.xml.XMLElement in project jacoco by jacoco.

the class XmlDocumentation method writeOptions.

private static void writeOptions(final XMLElement parent, @SuppressWarnings("rawtypes") final List<OptionHandler> list) throws IOException {
    for (final OptionHandler<?> o : list) {
        final XMLElement optionNode = parent.element("option");
        optionNode.attr("required", String.valueOf(o.option.required()));
        optionNode.attr("multiple", String.valueOf(o.setter.isMultiValued()));
        optionNode.element("usage").text(o.getNameAndMeta(null));
        optionNode.element("description").text(o.option.usage());
    }
}
Also used : XMLElement(org.jacoco.report.internal.xml.XMLElement)

Example 3 with XMLElement

use of org.jacoco.report.internal.xml.XMLElement in project jacoco by jacoco.

the class XmlDocumentation method writeCommand.

private static void writeCommand(final Command command, final XMLElement parent) throws IOException {
    final CommandParser parser = new CommandParser(command);
    final XMLElement element = parent.element("command");
    element.attr("name", command.name());
    element.element("usage").text(command.usage(parser));
    element.element("description").text(command.description());
    writeOptions(element, parser.getArguments());
    writeOptions(element, parser.getOptions());
}
Also used : XMLElement(org.jacoco.report.internal.xml.XMLElement)

Example 4 with XMLElement

use of org.jacoco.report.internal.xml.XMLElement in project jacoco by jacoco.

the class XMLFormatter method createVisitor.

/**
 * Creates a new visitor to write a report to the given stream.
 *
 * @param output
 *            output stream to write the report to
 * @return visitor to emit the report data to
 * @throws IOException
 *             in case of problems with the output stream
 */
public IReportVisitor createVisitor(final OutputStream output) throws IOException {
    final XMLElement root = new XMLDocument("report", PUBID, SYSTEM, outputEncoding, true, output);
    class RootVisitor extends XMLGroupVisitor implements IReportVisitor {

        RootVisitor(final XMLElement element) throws IOException {
            super(element, null);
        }

        private List<SessionInfo> sessionInfos;

        public void visitInfo(final List<SessionInfo> sessionInfos, final Collection<ExecutionData> executionData) throws IOException {
            this.sessionInfos = sessionInfos;
        }

        @Override
        protected void handleBundle(final IBundleCoverage bundle, final ISourceFileLocator locator) throws IOException {
            writeHeader(bundle.getName());
            XMLCoverageWriter.writeBundle(bundle, element);
        }

        @Override
        protected AbstractGroupVisitor handleGroup(final String name) throws IOException {
            writeHeader(name);
            return new XMLGroupVisitor(element, name);
        }

        private void writeHeader(final String name) throws IOException {
            element.attr("name", name);
            for (final SessionInfo i : sessionInfos) {
                final XMLElement sessioninfo = root.element("sessioninfo");
                sessioninfo.attr("id", i.getId());
                sessioninfo.attr("start", i.getStartTimeStamp());
                sessioninfo.attr("dump", i.getDumpTimeStamp());
            }
        }

        @Override
        protected void handleEnd() throws IOException {
            element.close();
        }
    }
    return new RootVisitor(root);
}
Also used : XMLGroupVisitor(org.jacoco.report.internal.xml.XMLGroupVisitor) Collection(java.util.Collection) IBundleCoverage(org.jacoco.core.analysis.IBundleCoverage) SessionInfo(org.jacoco.core.data.SessionInfo) List(java.util.List) XMLElement(org.jacoco.report.internal.xml.XMLElement) ISourceFileLocator(org.jacoco.report.ISourceFileLocator) XMLDocument(org.jacoco.report.internal.xml.XMLDocument) IReportVisitor(org.jacoco.report.IReportVisitor)

Aggregations

XMLElement (org.jacoco.report.internal.xml.XMLElement)4 XMLDocument (org.jacoco.report.internal.xml.XMLDocument)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Collection (java.util.Collection)1 List (java.util.List)1 IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)1 SessionInfo (org.jacoco.core.data.SessionInfo)1 IReportVisitor (org.jacoco.report.IReportVisitor)1 ISourceFileLocator (org.jacoco.report.ISourceFileLocator)1 XMLGroupVisitor (org.jacoco.report.internal.xml.XMLGroupVisitor)1