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;
}
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();
}
}
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);
}
Aggregations