All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.pmckeown.dependencytrack.finding.report.XmlReportWriter Maven / Gradle / Ivy

Go to download

Maven plugin to integrate with a Dependency Track server to submit dependency manifests and gather project metrics.

There is a newer version: 1.7.0
Show newest version
package io.github.pmckeown.dependencytrack.finding.report;

import io.github.pmckeown.dependencytrack.DependencyTrackException;

import javax.inject.Inject;
import javax.inject.Singleton;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.io.File;

@Singleton
class XmlReportWriter {

    private FindingsReportMarshallerService marshallerService;

    @Inject
    XmlReportWriter(FindingsReportMarshallerService marshallerService) {
        this.marshallerService = marshallerService;
    }

    void write(File buildDirectory, FindingsReport findingsReport) throws DependencyTrackException {
        try {
            Marshaller marshaller = marshallerService.getMarshaller();
            File outputFile = getFile(buildDirectory);
            marshaller.marshal(findingsReport, outputFile);
        } catch (JAXBException ex) {
            throw new DependencyTrackException("Error occurred while generating XML report", ex);
        }
    }

    private File getFile(File buildDirectory) {
        if (buildDirectory != null && !buildDirectory.exists()) {
            buildDirectory.mkdir();
        }
        return new File(buildDirectory, FindingsReportConstants.XML_REPORT_FILENAME);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy