use of com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtDependencyModule in project synopsys-detect by blackducksoftware.
the class SbtDependencyResolver method resolveReport.
public SbtDependencyModule resolveReport(SbtReport report) {
ExternalId rootId = externalIdFactory.createMavenExternalId(report.getOrganisation(), report.getModule(), report.getRevision());
logger.debug("Created external id: {}", rootId);
BasicDependencyGraph graph = new BasicDependencyGraph();
logger.debug("Dependencies found: " + report.getDependencies().size());
report.getDependencies().forEach(module -> {
logger.debug("Revisions found: " + module.getRevisions().size());
module.getRevisions().forEach(revision -> {
logger.debug("Callers found: " + revision.getCallers().size());
ExternalId id = externalIdFactory.createMavenExternalId(module.getOrganisation(), module.getName(), revision.getName());
Dependency child = new Dependency(module.getName(), revision.getName(), id);
revision.getCallers().forEach(caller -> {
ExternalId parentId = externalIdFactory.createMavenExternalId(caller.getOrganisation(), caller.getName(), caller.getRevision());
Dependency parent = new Dependency(caller.getName(), caller.getRevision(), parentId);
logger.debug("Caller id: " + parentId.toString());
if (rootId.equals(parentId)) {
graph.addChildToRoot(child);
} else {
graph.addParentWithChild(parent, child);
}
});
});
});
SbtDependencyModule module = new SbtDependencyModule();
module.setName(report.getModule());
module.setVersion(report.getRevision());
module.setOrg(report.getOrganisation());
module.setGraph(graph);
module.setConfiguration(report.getConfiguration());
return module;
}
use of com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtDependencyModule in project synopsys-detect by blackducksoftware.
the class SbtResolutionCacheExtractor method extractProject.
private SbtProject extractProject(File path, boolean followSymLinks, int depth, List<String> included, List<String> excluded) throws IOException, SAXException, ParserConfigurationException {
List<SbtDependencyModule> rawModules = extractModules(path, followSymLinks, depth, included, excluded);
List<SbtDependencyModule> modules = rawModules.stream().filter(it -> it.getGraph() != null).collect(Collectors.toList());
int skipped = rawModules.size() - modules.size();
if (skipped > 0) {
logger.error(String.format("Skipped %s", skipped));
}
SbtProject result = new SbtProject();
result.setModules(modules);
if (modules.isEmpty()) {
logger.warn("Unable to create an sbt project, no sbt modules were found.");
} else if (modules.size() == 1) {
logger.warn("Found exactly one root module, using it's name and version.");
result.setProjectName(modules.get(0).getName());
result.setProjectVersion(modules.get(0).getVersion());
result.setProjectExternalId(externalIdFactory.createMavenExternalId(modules.get(0).getOrg(), modules.get(0).getName(), modules.get(0).getVersion()));
} else {
logger.warn("Unable to find exactly one root module. Using source path for root project name - will not set an external id.");
result.setProjectName(path.getName());
result.setProjectVersion(findFirstModuleVersion(modules, result.getProjectName(), "root"));
result.setProjectExternalId(null);
if (result.getProjectVersion() == null && modules.size() > 1) {
logger.warn(String.format("Getting version from first project: %s", modules.get(0).getName()));
result.setProjectVersion(modules.get(0).getVersion());
}
}
return result;
}
use of com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtDependencyModule 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);
}
use of com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtDependencyModule in project synopsys-detect by blackducksoftware.
the class SbtResolutionCacheExtractor method extract.
public Extraction extract(File directory, SbtResolutionCacheOptions sbtResolutionCacheOptions) {
// TODO: Extractor should not use DetectableOptions
try {
// TODO: Handle null better.
List<String> included = sbtResolutionCacheOptions.getIncludedConfigurations();
List<String> excluded = sbtResolutionCacheOptions.getExcludedConfigurations();
int depth = sbtResolutionCacheOptions.getReportDepth();
SbtProject project = extractProject(directory, sbtResolutionCacheOptions.isFollowSymLinks(), depth, included, excluded);
List<CodeLocation> codeLocations = new ArrayList<>();
String projectName = null;
String projectVersion = null;
for (SbtDependencyModule module : project.getModules()) {
CodeLocation codeLocation;
if (project.getProjectExternalId() != null) {
codeLocation = new CodeLocation(module.getGraph(), project.getProjectExternalId());
} else {
codeLocation = new CodeLocation(module.getGraph());
}
if (projectName == null) {
projectName = project.getProjectName();
projectVersion = project.getProjectVersion();
}
codeLocations.add(codeLocation);
}
if (codeLocations.size() > 0) {
return new Extraction.Builder().success(codeLocations).projectName(projectName).projectVersion(projectVersion).build();
} else {
logger.error("Unable to find any dependency information.");
return new Extraction.Builder().failure("Unable to find any dependency information.").build();
}
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtDependencyModule in project synopsys-detect by blackducksoftware.
the class SbtModuleAggregator method aggregateModules.
public List<SbtDependencyModule> aggregateModules(List<SbtDependencyModule> modules) {
Set<SbtAggregate> aggregates = uniqueAggregates(modules);
logger.debug("Found unique aggregates: " + aggregates.size());
return aggregates.stream().map(aggregate -> {
SbtDependencyModule aggregated = new SbtDependencyModule();
aggregated.setName(aggregate.getName());
aggregated.setVersion(aggregate.getVersion());
aggregated.setOrg(aggregate.getOrg());
BasicDependencyGraph graph = new BasicDependencyGraph();
aggregated.setGraph(graph);
modules.forEach(module -> {
if (moduleEqualsAggregate(module, aggregate)) {
logger.debug("Combining '" + module.getName() + "' with '" + aggregate.getName() + "'");
graph.copyGraphToRoot((BasicDependencyGraph) module.getGraph());
}
});
return aggregated;
}).collect(Collectors.toList());
}
Aggregations