use of com.synopsys.integration.util.ExcludedIncludedFilter in project hub-detect by blackducksoftware.
the class SbtPackager method makeModuleAggregate.
private List<SbtDependencyModule> makeModuleAggregate(final List<File> reportFiles, final String include, final String exclude) throws SAXException, IOException, ParserConfigurationException {
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
final DocumentBuilder builder = factory.newDocumentBuilder();
final SbtReportParser parser = new SbtReportParser();
final SbtDependencyResolver resolver = new SbtDependencyResolver(externalIdFactory);
final ExcludedIncludedFilter filter = new ExcludedIncludedFilter(exclude, include);
final SbtModuleAggregator aggregator = new SbtModuleAggregator();
final List<SbtDependencyModule> modules = new ArrayList<>();
for (final File reportFile : reportFiles) {
final Document xml = builder.parse(reportFile);
logger.debug(String.format("Parsing SBT report file: %s", reportFile.getCanonicalPath()));
final SbtReport report = parser.parseReportFromXml(xml);
final SbtDependencyModule tree = resolver.resolveReport(report);
modules.add(tree);
}
final List<SbtDependencyModule> includedModules = modules.stream().filter(module -> filter.shouldInclude(module.configuration)).collect(Collectors.toList());
if (modules.size() <= 0) {
logger.warn("No sbt configurations were found in report folder.");
return null;
} else if (includedModules.size() <= 0) {
logger.warn(String.format("Although %s configs were found, none were included.", modules.size()));
return null;
}
return aggregator.aggregateModules(includedModules);
}
use of com.synopsys.integration.util.ExcludedIncludedFilter in project hub-detect by blackducksoftware.
the class MavenCodeLocationPackager method extractCodeLocations.
// mavenTextOutput should be the full output of mvn dependency:tree (no scope applied); scope filtering is now done by this method
public List<MavenParseResult> extractCodeLocations(final String sourcePath, final String mavenOutputText, final String targetScope, final String excludedModules, final String includedModules) {
final ExcludedIncludedFilter filter = new ExcludedIncludedFilter(excludedModules, includedModules);
codeLocations = new ArrayList<>();
currentMavenProject = null;
dependencyParentStack = new Stack<>();
parsingProjectSection = false;
currentGraph = new MutableMapDependencyGraph();
level = 0;
for (final String currentLine : mavenOutputText.split(System.lineSeparator())) {
String line = currentLine.trim();
if (!isLineRelevant(line)) {
continue;
}
line = trimLogLevel(line);
if (StringUtils.isBlank(line)) {
continue;
}
if (isProjectSection(line)) {
parsingProjectSection = true;
continue;
}
if (!parsingProjectSection) {
continue;
}
if (isDependencyTreeUpdates(line)) {
continue;
}
if (parsingProjectSection && currentMavenProject == null) {
// this is the first line of a new code location, the following lines will be the tree of dependencies for this code location
currentGraph = new MutableMapDependencyGraph();
final MavenParseResult mavenProject = createMavenParseResult(sourcePath, line, currentGraph);
if (null != mavenProject && filter.shouldInclude(mavenProject.projectName)) {
logger.trace(String.format("Project: %s", mavenProject.projectName));
this.currentMavenProject = mavenProject;
codeLocations.add(mavenProject);
} else {
logger.trace("Project: unknown");
currentMavenProject = null;
dependencyParentStack.clear();
parsingProjectSection = false;
level = 0;
}
continue;
}
final boolean finished = line.contains("--------");
if (finished) {
currentMavenProject = null;
dependencyParentStack.clear();
parsingProjectSection = false;
level = 0;
continue;
}
final int previousLevel = level;
final String cleanedLine = calculateCurrentLevelAndCleanLine(line);
final ScopedDependency dependency = textToDependency(cleanedLine);
if (null == dependency) {
continue;
}
if (currentMavenProject != null) {
if (level == 1) {
// a direct dependency, clear the stack and add this as a potential parent for the next line
if (dependency.isInScope(targetScope)) {
logger.trace(String.format("Level 1 component %s:%s:%s:%s is in scope; adding it to hierarchy root", dependency.externalId.group, dependency.externalId.name, dependency.externalId.version, dependency.scope));
currentGraph.addChildToRoot(dependency);
inOutOfScopeTree = false;
} else {
logger.trace(String.format("Level 1 component %s:%s:%s:%s is a top-level out-of-scope component; entering non-scoped tree", dependency.externalId.group, dependency.externalId.name, dependency.externalId.version, dependency.scope));
inOutOfScopeTree = true;
}
dependencyParentStack.clear();
dependencyParentStack.push(dependency);
} else {
// level should be greater than 1
if (level == previousLevel) {
// a sibling of the previous dependency
dependencyParentStack.pop();
addDependencyIfInScope(currentGraph, orphans, targetScope, inOutOfScopeTree, dependencyParentStack.peek(), dependency);
dependencyParentStack.push(dependency);
} else if (level > previousLevel) {
// a child of the previous dependency
addDependencyIfInScope(currentGraph, orphans, targetScope, inOutOfScopeTree, dependencyParentStack.peek(), dependency);
dependencyParentStack.push(dependency);
} else {
// a child of a dependency further back than 1 line
for (int i = previousLevel; i >= level; i--) {
dependencyParentStack.pop();
}
addDependencyIfInScope(currentGraph, orphans, targetScope, inOutOfScopeTree, dependencyParentStack.peek(), dependency);
dependencyParentStack.push(dependency);
}
}
}
}
addOrphansToGraph(currentGraph, orphans);
return codeLocations;
}
Aggregations