Search in sources :

Example 6 with SbtDependencyModule

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

the class SbtResolutionCacheExtractor method extractModules.

private List<SbtDependencyModule> extractModules(File path, boolean followSymLinks, int depth, List<String> included, List<String> excluded) throws IOException, SAXException, ParserConfigurationException {
    List<File> sbtFiles = fileFinder.findFiles(path, BUILD_SBT_FILENAME, followSymLinks, depth);
    List<File> resolutionCaches = fileFinder.findFiles(path, RESOLUTION_CACHE_DIRECTORY, followSymLinks, depth);
    // TODO: ensure this does what the old method did. findDirectoriesContainingDirectoriesToDepth
    logger.debug(String.format("Found %s build.sbt files.", sbtFiles.size()));
    logger.debug(String.format("Found %s resolution caches.", resolutionCaches.size()));
    List<SbtDependencyModule> modules = new ArrayList<>();
    List<String> usedReports = new ArrayList<>();
    for (File sbtFile : sbtFiles) {
        logger.debug(String.format("Found SBT build file: %s", sbtFile.getCanonicalPath()));
        File sbtDirectory = sbtFile.getParentFile();
        File reportPath = new File(sbtDirectory, REPORT_FILE_DIRECTORY);
        List<SbtDependencyModule> foundModules = extractReportModules(path, reportPath, sbtDirectory, included, excluded, usedReports);
        modules.addAll(foundModules);
    }
    for (File resCache : resolutionCaches) {
        logger.debug(String.format("Found resolution cache: %s", resCache.getCanonicalPath()));
        File reportPath = new File(resCache, REPORT_DIRECTORY);
        List<SbtDependencyModule> foundModules = extractReportModules(path, reportPath, resCache.getParentFile(), included, excluded, usedReports);
        modules.addAll(foundModules);
    }
    modules.removeIf(it -> {
        if (it.getName().contains("temp-module")) {
            logger.debug("Excluding temp module: " + it.getName());
            return true;
        } else {
            return false;
        }
    });
    if (modules.isEmpty()) {
        if (sbtFiles.isEmpty()) {
            logger.error("Sbt found no build.sbt files even though it applied.");
        } else if (resolutionCaches.isEmpty()) {
            logger.error("Sbt found no resolution-caches, this most likely means you are not running post build.");
            logger.error("Please build the project before running detect.");
        } else {
            logger.error("Sbt was unable to parse any dependencies from any resolution caches.");
        }
    }
    return modules;
}
Also used : SbtDependencyModule(com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtDependencyModule) ArrayList(java.util.ArrayList) File(java.io.File)

Example 7 with SbtDependencyModule

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

the class SbtResolutionCacheExtractor method findFirstModuleVersion.

private String findFirstModuleVersion(List<SbtDependencyModule> modules, String... names) {
    String version = null;
    List<String> nameList = new ArrayList<>(Arrays.asList(names));
    for (SbtDependencyModule it : modules) {
        if (version == null && it.getName() != null && nameList.contains(it.getName())) {
            logger.debug(String.format("Matched %s to project version.", it.getName()));
            version = it.getVersion();
        }
    }
    return version;
}
Also used : SbtDependencyModule(com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtDependencyModule) ArrayList(java.util.ArrayList)

Aggregations

SbtDependencyModule (com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtDependencyModule)7 ArrayList (java.util.ArrayList)5 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)3 SbtProject (com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtProject)3 Extraction (com.synopsys.integration.detectable.extraction.Extraction)3 File (java.io.File)3 IOException (java.io.IOException)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 SAXException (org.xml.sax.SAXException)3 BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)2 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)2 FileFinder (com.synopsys.integration.common.util.finder.FileFinder)2 SbtReport (com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtReport)2 ExcludedIncludedWildcardFilter (com.synopsys.integration.util.ExcludedIncludedWildcardFilter)2 Arrays (java.util.Arrays)2