Class XmlUtil


  • public class XmlUtil
    extends Object
    The XmlUtil class contains the helpers to work with XML.
    • Constructor Detail

      • XmlUtil

        public XmlUtil()
    • Method Detail

      • newScanHistory

        public static final ScanHistory newScanHistory​(String buildInfoXml,
                                                       String detailedReportXml,
                                                       Run<?,​?> build)
                                                throws Exception
        Get the scan results from the detailed report and previous Jenkins builds result to compose the scan result for the current Jenkins build.
        Parameters:
        buildInfoXml - a String object - the XML returned from calling GetBuildInfo API.
        detailedReportXml - a String object - the XML returned from calling GetDetailedReport API.
        build - a Run object - the current Jenkins build.
        Returns:
        a ScanHistory object - the info to be displayed in the Veracode post build step.
        Throws:
        Exception - when an error is encountered during the operation.
      • newSCAHistory

        public static final SCAScanHistory newSCAHistory​(String detailedReportXml,
                                                         long buildDate,
                                                         SCAScanHistory lastSCAHistory)
                                                  throws Exception
        Retrieve SCA results from the given Detailed Report XML.
        Parameters:
        detailedReportXml - a String object - the XML returned from calling GetDetailedReport API.
        buildDate - a long - the build date.
        lastSCAHistory - a SCAScanHistory object.
        Returns:
        a SCAScanHistory object - the SCA result in the detailed report.
        Throws:
        Exception - when an error is encountered during the operation.
      • newDAScanHistory

        public static final DAScanHistory newDAScanHistory​(String detailedReportXml,
                                                           com.veracode.apiwrapper.dynamicanalysis.model.client.ScanOccurrenceInfo scanOccurrenceInfo,
                                                           Run<?,​?> build)
                                                    throws Exception
        Get the scan results from the detailed report and scan occurrence result. In addition, comparison of results to previous successful Jenkins build result.
        Parameters:
        detailedReportXml - a String object - the XML returned from calling GetDetailedReport API.
        scanOccurrenceInfo - a ScanOccurrenceInfo object - analysis occurrence info returned from DA via REST API.
        build - a Run object - the Jenkins build.
        Returns:
        a DAScanHistory object - the info to be displayed in the Veracode post build step.
        Throws:
        Exception - when an error is encountered during the operation.
      • parseAppId

        public static final String parseAppId​(String appName,
                                              String xmlAppListResult)
                                       throws Exception
        Find the Application ID by its name within an XML document.
        Parameters:
        appName - a String object - the name of an application.
        xmlAppListResult - a String object - the XML result from a GetAppList call.
        Returns:
        a String object - the ID of the application or null if the ID is not found.
        Throws:
        Exception - when given invalid parameter(s) or an error occurred when parsing the given XML.
      • parseSandboxId

        public static final String parseSandboxId​(String sandboxName,
                                                  String xmlSandboxListResult)
                                           throws Exception
        Find the sandbox ID by its name in an XML document.
        Parameters:
        sandboxName - a String object - the name of a sandbox.
        xmlSandboxListResult - a String object - the XML from the getSandboxList API.
        Returns:
        a String object - the ID of the given sandbox or empty string if none found.
        Throws:
        Exception - when given invalid parameter(s) or an error occurred when parsing the given XML.
      • getXmlDocument

        public static final Document getXmlDocument​(String xmlString)
                                             throws Exception
        Takes an XML return an creates a DOM tree.
        Parameters:
        xmlString - a String object.
        Returns:
        a Document object.
        Throws:
        Exception - if any.
      • parseBuildId

        public static final String parseBuildId​(String xmlBuildInfoResult)
                                         throws Exception
        Find the build ID within a XML document.
        Parameters:
        xmlBuildInfoResult - a String object - a String that represents the buildinfo XML document, which references the buildinfo.xsd schema.
        Returns:
        a String object - a build ID.
        Throws:
        Exception - when given invalid XML document or an error occurred when parsing the given XML.
      • getErrorString

        public static final String getErrorString​(String xmlString)
        Get the error string, if any, from a XML document.
        Parameters:
        xmlString - a String object - a XML document.
        Returns:
        a String object - the error message in the XML document if found, empty string otherwise. The return value will never be null.