Search in sources :

Example 1 with SbtReport

use of com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtReport in project synopsys-detect by blackducksoftware.

the class SbtReportParser method parseReportFromXml.

public SbtReport parseReportFromXml(Document xmlReport) {
    Node ivyReport = XmlUtil.getNode(IVY_REPORT_NODE_KEY, xmlReport);
    Node infoNode = XmlUtil.getNode(INFO_NODE_KEY, ivyReport);
    Node dependenciesNode = XmlUtil.getNode(DEPENDENCIES_NODE_KEY, ivyReport);
    List<Node> xmlModules = XmlUtil.getNodeList(MODULE_NODE_KEY, dependenciesNode);
    String organisation = XmlUtil.getAttribute(ORGANISATION_NODE_KEY, infoNode);
    String module = XmlUtil.getAttribute(MODULE_NODE_KEY, infoNode);
    String revision = XmlUtil.getAttribute(REVISION_NODE_KEY, infoNode);
    String configuration = XmlUtil.getAttribute(CONFIGURATION_NODE_KEY, infoNode);
    List<SbtModule> dependencies = xmlModules.stream().map(this::createModule).collect(Collectors.toList());
    return new SbtReport(organisation, module, revision, configuration, dependencies);
}
Also used : Node(org.w3c.dom.Node) SbtModule(com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtModule) SbtReport(com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtReport)

Example 2 with SbtReport

use of com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtReport in project synopsys-detect by blackducksoftware.

the class SbtResolutionCacheExtractor method makeModuleAggregate.

private List<SbtDependencyModule> makeModuleAggregate(List<File> reportFiles, List<String> include, List<String> exclude) throws SAXException, IOException, ParserConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    SbtReportParser parser = new SbtReportParser();
    SbtDependencyResolver resolver = new SbtDependencyResolver(externalIdFactory);
    ExcludedIncludedWildcardFilter filter = ExcludedIncludedWildcardFilter.fromCollections(exclude, include);
    SbtModuleAggregator aggregator = new SbtModuleAggregator();
    List<SbtDependencyModule> modules = new ArrayList<>();
    for (File reportFile : reportFiles) {
        Document xml = builder.parse(reportFile);
        logger.debug(String.format("Parsing SBT report file: %s", reportFile.getCanonicalPath()));
        SbtReport report = parser.parseReportFromXml(xml);
        SbtDependencyModule tree = resolver.resolveReport(report);
        modules.add(tree);
    }
    List<SbtDependencyModule> includedModules = modules.stream().filter(module -> filter.shouldInclude(module.getConfiguration())).collect(Collectors.toList());
    if (modules.isEmpty()) {
        logger.warn("No sbt configurations were found in report folder.");
        return null;
    } else if (includedModules.isEmpty()) {
        logger.warn(String.format("Although %s configs were found, none were included.", modules.size()));
        return null;
    }
    return aggregator.aggregateModules(includedModules);
}
Also used : Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Extraction(com.synopsys.integration.detectable.extraction.Extraction) LoggerFactory(org.slf4j.LoggerFactory) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) IOException(java.io.IOException) SbtProject(com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtProject) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) SbtDependencyModule(com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtDependencyModule) File(java.io.File) ExcludedIncludedWildcardFilter(com.synopsys.integration.util.ExcludedIncludedWildcardFilter) ArrayList(java.util.ArrayList) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXException(org.xml.sax.SAXException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) SbtReport(com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtReport) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) SbtDependencyModule(com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtDependencyModule) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) ExcludedIncludedWildcardFilter(com.synopsys.integration.util.ExcludedIncludedWildcardFilter) DocumentBuilder(javax.xml.parsers.DocumentBuilder) File(java.io.File) SbtReport(com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtReport)

Aggregations

SbtReport (com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtReport)2 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)1 FileFinder (com.synopsys.integration.common.util.finder.FileFinder)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 SbtDependencyModule (com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtDependencyModule)1 SbtModule (com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtModule)1 SbtProject (com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtProject)1 Extraction (com.synopsys.integration.detectable.extraction.Extraction)1 ExcludedIncludedWildcardFilter (com.synopsys.integration.util.ExcludedIncludedWildcardFilter)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Logger (org.slf4j.Logger)1