use of com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager in project synopsys-detect by blackducksoftware.
the class ClangExtractor method extract.
public Extraction extract(ClangPackageManager currentPackageManager, ClangPackageManagerRunner packageManagerRunner, File sourceDirectory, File outputDirectory, File jsonCompilationDatabaseFile, boolean cleanup) {
try {
logger.debug(String.format("Analyzing %s", jsonCompilationDatabaseFile.getAbsolutePath()));
logger.debug(String.format("extract() called; compileCommandsJsonFilePath: %s", jsonCompilationDatabaseFile.getAbsolutePath()));
List<CompileCommand> compileCommands = compileCommandDatabaseParser.parseCompileCommandDatabase(jsonCompilationDatabaseFile);
Set<File> dependencyFileDetails = dependencyFileDetailGenerator.fromCompileCommands(compileCommands, outputDirectory, cleanup);
PackageDetailsResult results = packageManagerRunner.getAllPackages(currentPackageManager, sourceDirectory, executableRunner, dependencyFileDetails);
logger.trace("Found : " + results.getFoundPackages() + " packages.");
logger.trace("Found : " + results.getUnRecognizedDependencyFiles() + " non-package files.");
List<Forge> packageForges = forgeChooser.determineForges(currentPackageManager);
CodeLocation codeLocation = clangPackageDetailsTransformer.toCodeLocation(packageForges, results.getFoundPackages());
logFileCollection("Unrecognized dependency files (all)", results.getUnRecognizedDependencyFiles());
List<File> unrecognizedIncludeFiles = results.getUnRecognizedDependencyFiles().stream().filter(file -> !isFileUnderDir(sourceDirectory, file)).collect(Collectors.toList());
logFileCollection(String.format("Unrecognized dependency files that are outside the compile_commands.json directory (%s) and will be collected", sourceDirectory), unrecognizedIncludeFiles);
return new Extraction.Builder().unrecognizedPaths(unrecognizedIncludeFiles).success(codeLocation).build();
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager in project synopsys-detect by blackducksoftware.
the class ClangPackageManagerRunnerTest method runTest.
private PackageDetailsResult runTest(ClangPackageManagerInfo packageManagerInfo, ClangPackageManagerResolver packageResolver, String pkgName, String pkgArch, boolean archBuried, String pkgMgrOwnerQueryResultPattern, String pkgMgrDetailsQueryResultPattern, File dependencyFile) throws ExecutableRunnerException {
ClangPackageManager currentPackageManager = new ClangPackageManager(packageManagerInfo, packageResolver);
File workingDirectory = new File("test");
DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
List<String> fileSpecificGetOwnerArgs = new ArrayList<>(packageManagerInfo.getPkgMgrGetOwnerCmdArgs());
fileSpecificGetOwnerArgs.add(dependencyFile.getAbsolutePath());
if (packageManagerInfo.getPkgInfoArgs().isPresent() && (pkgMgrDetailsQueryResultPattern != null)) {
List<String> fileSpecificGetDetailsArgs = new ArrayList<>(packageManagerInfo.getPkgInfoArgs().get());
// If absent or buried, the detail query should omit arch; otherwise: the detail query should include arch
if (archBuried || pkgArch == null) {
fileSpecificGetDetailsArgs.add(pkgName);
} else {
fileSpecificGetDetailsArgs.add(pkgName + ":" + pkgArch);
}
String pkgMgrGetDetailsQueryFileOutput = String.format(pkgMgrDetailsQueryResultPattern, dependencyFile);
ExecutableOutput pkgMgrGetDetailsQueryFileResult = new ExecutableOutput(0, pkgMgrGetDetailsQueryFileOutput, "");
Mockito.when(executableRunner.execute(workingDirectory, packageManagerInfo.getPkgMgrCmdString(), fileSpecificGetDetailsArgs)).thenReturn(pkgMgrGetDetailsQueryFileResult);
}
String pkgMgrGetOwnerQueryFileOutput = String.format(pkgMgrOwnerQueryResultPattern, dependencyFile.getAbsolutePath());
ExecutableOutput pkgMgrGetOwnerQueryFileResult = new ExecutableOutput(0, pkgMgrGetOwnerQueryFileOutput, "");
Mockito.when(executableRunner.execute(workingDirectory, packageManagerInfo.getPkgMgrCmdString(), fileSpecificGetOwnerArgs)).thenReturn(pkgMgrGetOwnerQueryFileResult);
ClangPackageManagerRunner runner = new ClangPackageManagerRunner();
// Test
return runner.getPackages(currentPackageManager, workingDirectory, executableRunner, dependencyFile);
}
use of com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager in project synopsys-detect by blackducksoftware.
the class ForgeChooserTest method testDistroIdentified.
@Test
void testDistroIdentified() {
LinuxDistroToForgeMapper forgeGenerator = Mockito.mock(LinuxDistroToForgeMapper.class);
LinuxDistro linuxDistro = Mockito.mock(LinuxDistro.class);
ForgeChooser forgeChooser = new ForgeChooser(forgeGenerator, linuxDistro);
ClangPackageManager currentPackageManager = Mockito.mock(ClangPackageManager.class);
Mockito.when(linuxDistro.extractLinuxDistroNameFromEtcDir()).thenReturn(Optional.of("ubuntu"));
Forge createdForge = Mockito.mock(Forge.class);
Mockito.when(forgeGenerator.createPreferredAliasNamespaceForge("ubuntu")).thenReturn(createdForge);
List<Forge> chosenForges = forgeChooser.determineForges(currentPackageManager);
assertEquals(1, chosenForges.size());
assertEquals(createdForge, chosenForges.get(0));
}
use of com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager in project synopsys-detect by blackducksoftware.
the class ForgeChooserTest method testDistroNotIdentified.
@Test
void testDistroNotIdentified() {
LinuxDistroToForgeMapper forgeGenerator = Mockito.mock(LinuxDistroToForgeMapper.class);
LinuxDistro linuxDistro = Mockito.mock(LinuxDistro.class);
ForgeChooser forgeChooser = new ForgeChooser(forgeGenerator, linuxDistro);
ClangPackageManager currentPackageManager = Mockito.mock(ClangPackageManager.class);
Mockito.when(linuxDistro.extractLinuxDistroNameFromEtcDir()).thenReturn(Optional.empty());
ClangPackageManagerInfo packageManagerInfo = Mockito.mock(ClangPackageManagerInfo.class);
Mockito.when(currentPackageManager.getPackageManagerInfo()).thenReturn(packageManagerInfo);
Forge possibleForge1 = Mockito.mock(Forge.class);
Mockito.when(possibleForge1.getName()).thenReturn("possibleForge1");
Forge possibleForge2 = Mockito.mock(Forge.class);
Mockito.when(possibleForge2.getName()).thenReturn("possibleForge2");
List<Forge> possibleForges = Arrays.asList(possibleForge1, possibleForge2);
Mockito.when(packageManagerInfo.getPossibleForges()).thenReturn(possibleForges);
List<Forge> chosenForges = forgeChooser.determineForges(currentPackageManager);
assertEquals(2, chosenForges.size());
assertEquals(possibleForge1, chosenForges.get(0));
assertEquals(possibleForge2, chosenForges.get(1));
}
use of com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager in project synopsys-detect by blackducksoftware.
the class ClangDetectableTest method testApplicable.
@Test
public void testApplicable() {
DetectableExecutableRunner executableRunner = null;
List<ClangPackageManager> availablePackageManagers = new ArrayList<>(0);
ClangExtractor clangExtractor = null;
ClangPackageManagerRunner packageManagerRunner = null;
ClangDetectableOptions options = new ClangDetectableOptions(false);
DetectableEnvironment environment = MockDetectableEnvironment.empty();
FileFinder fileFinder = MockFileFinder.withFileNamed(JSON_COMPILATION_DATABASE_FILENAME);
ClangDetectable detectable = new ClangDetectable(environment, executableRunner, fileFinder, availablePackageManagers, clangExtractor, options, packageManagerRunner);
assertTrue(detectable.applicable().getPassed());
}
Aggregations