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