Search in sources :

Example 1 with ExcludedIncludedWildcardFilter

use of com.synopsys.integration.util.ExcludedIncludedWildcardFilter in project synopsys-detect by blackducksoftware.

the class MavenCodeLocationPackager method extractCodeLocations.

// mavenOutput should be the full output of mvn dependency:tree (no scope applied); scope filtering is now done by this method
public List<MavenParseResult> extractCodeLocations(String sourcePath, List<String> mavenOutput, List<String> excludedScopes, List<String> includedScopes, List<String> excludedModules, List<String> includedModules) {
    ExcludedIncludedWildcardFilter modulesFilter = ExcludedIncludedWildcardFilter.fromCollections(excludedModules, includedModules);
    ExcludedIncludedWildcardFilter scopeFilter = ExcludedIncludedWildcardFilter.fromCollections(excludedScopes, includedScopes);
    codeLocations = new ArrayList<>();
    currentMavenProject = null;
    dependencyParentStack = new Stack<>();
    parsingProjectSection = false;
    currentGraph = new BasicDependencyGraph();
    level = 0;
    for (String currentLine : mavenOutput) {
        String line = currentLine.trim();
        if (shouldSkipLine(line)) {
            continue;
        }
        line = trimLogLevel(line);
        if (parsingProjectSection && currentMavenProject == null) {
            initializeCurrentMavenProject(modulesFilter, sourcePath, line);
            continue;
        }
        boolean finished = line.contains("--------") || endOfTreePattern.matcher(line).matches();
        if (finished) {
            currentMavenProject = null;
            dependencyParentStack.clear();
            parsingProjectSection = false;
            level = 0;
            continue;
        }
        int previousLevel = level;
        String cleanedLine = calculateCurrentLevelAndCleanLine(line);
        ScopedDependency dependency = textToDependency(cleanedLine);
        if (null == dependency) {
            continue;
        }
        if (currentMavenProject != null) {
            populateGraphDependencies(scopeFilter, dependency, previousLevel);
        }
    }
    addOrphansToGraph(currentGraph, orphans);
    return codeLocations;
}
Also used : ExcludedIncludedWildcardFilter(com.synopsys.integration.util.ExcludedIncludedWildcardFilter) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph)

Example 2 with ExcludedIncludedWildcardFilter

use of com.synopsys.integration.util.ExcludedIncludedWildcardFilter in project synopsys-detect by blackducksoftware.

the class YarnLockExtractor method extract.

public Extraction extract(File projectDir, File yarnLockFile, File rootPackageJsonFile) {
    try {
        NullSafePackageJson rootPackageJson = packageJsonFiles.read(rootPackageJsonFile);
        String projectName = rootPackageJson.getName().orElse("null");
        logger.debug("Extracting Yarn project {} in {}", projectName, projectDir.getAbsolutePath());
        YarnLock yarnLock = readYarnLock(yarnLockFile);
        YarnWorkspaces workspaceData = collectWorkspaceData(projectDir);
        ExcludedIncludedWildcardFilter workspacesFilter = deriveExcludedIncludedWildcardFilter();
        YarnResult yarnResult = yarnPackager.generateCodeLocation(rootPackageJson, workspaceData, yarnLock, new ArrayList<>(), workspacesFilter);
        Optional<Exception> yarnException = yarnResult.getException();
        if (yarnException.isPresent()) {
            throw yarnException.get();
        }
        return new Extraction.Builder().projectName(yarnResult.getProjectName()).projectVersion(yarnResult.getProjectVersionName()).success(yarnResult.getCodeLocations()).build();
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) ExcludedIncludedWildcardFilter(com.synopsys.integration.util.ExcludedIncludedWildcardFilter) NullSafePackageJson(com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson) YarnWorkspaces(com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspaces) Extraction(com.synopsys.integration.detectable.extraction.Extraction) IOException(java.io.IOException)

Example 3 with ExcludedIncludedWildcardFilter

use of com.synopsys.integration.util.ExcludedIncludedWildcardFilter 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

ExcludedIncludedWildcardFilter (com.synopsys.integration.util.ExcludedIncludedWildcardFilter)3 Extraction (com.synopsys.integration.detectable.extraction.Extraction)2 IOException (java.io.IOException)2 BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)1 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 SbtProject (com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtProject)1 SbtReport (com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtReport)1 NullSafePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson)1 YarnLock (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock)1 YarnWorkspaces (com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspaces)1 File (java.io.File)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