Search in sources :

Example 1 with ClangPackageManager

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();
    }
}
Also used : Logger(org.slf4j.Logger) Forge(com.synopsys.integration.bdio.model.Forge) PackageDetailsResult(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetailsResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) ClangPackageManagerRunner(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerRunner) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ClangPackageDetailsTransformer(com.synopsys.integration.detectable.detectables.clang.dependencyfile.ClangPackageDetailsTransformer) File(java.io.File) ArrayList(java.util.ArrayList) CompileCommandDatabaseParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandDatabaseParser) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ClangPackageManager(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager) DependencyFileDetailGenerator(com.synopsys.integration.detectable.detectables.clang.dependencyfile.DependencyFileDetailGenerator) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Forge(com.synopsys.integration.bdio.model.Forge) IOException(java.io.IOException) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) Extraction(com.synopsys.integration.detectable.extraction.Extraction) PackageDetailsResult(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetailsResult) File(java.io.File)

Example 2 with ClangPackageManager

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);
}
Also used : ClangPackageManager(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ClangPackageManagerRunner(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerRunner) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) ArrayList(java.util.ArrayList) File(java.io.File)

Example 3 with ClangPackageManager

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));
}
Also used : LinuxDistroToForgeMapper(com.synopsys.integration.detectable.detectables.clang.LinuxDistroToForgeMapper) ClangPackageManager(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager) Forge(com.synopsys.integration.bdio.model.Forge) ForgeChooser(com.synopsys.integration.detectable.detectables.clang.ForgeChooser) LinuxDistro(com.synopsys.integration.detectable.detectables.clang.linux.LinuxDistro) Test(org.junit.jupiter.api.Test)

Example 4 with ClangPackageManager

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));
}
Also used : LinuxDistroToForgeMapper(com.synopsys.integration.detectable.detectables.clang.LinuxDistroToForgeMapper) ClangPackageManager(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager) ClangPackageManagerInfo(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfo) Forge(com.synopsys.integration.bdio.model.Forge) ForgeChooser(com.synopsys.integration.detectable.detectables.clang.ForgeChooser) LinuxDistro(com.synopsys.integration.detectable.detectables.clang.linux.LinuxDistro) Test(org.junit.jupiter.api.Test)

Example 5 with ClangPackageManager

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());
}
Also used : ClangPackageManager(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager) ClangExtractor(com.synopsys.integration.detectable.detectables.clang.ClangExtractor) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ClangPackageManagerRunner(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerRunner) ClangDetectable(com.synopsys.integration.detectable.detectables.clang.ClangDetectable) ArrayList(java.util.ArrayList) MockFileFinder(com.synopsys.integration.detectable.util.MockFileFinder) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) ClangDetectableOptions(com.synopsys.integration.detectable.detectables.clang.ClangDetectableOptions) MockDetectableEnvironment(com.synopsys.integration.detectable.util.MockDetectableEnvironment) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

ClangPackageManager (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager)5 Forge (com.synopsys.integration.bdio.model.Forge)3 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)3 ClangPackageManagerRunner (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerRunner)3 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)3 ForgeChooser (com.synopsys.integration.detectable.detectables.clang.ForgeChooser)2 LinuxDistroToForgeMapper (com.synopsys.integration.detectable.detectables.clang.LinuxDistroToForgeMapper)2 LinuxDistro (com.synopsys.integration.detectable.detectables.clang.linux.LinuxDistro)2 File (java.io.File)2 FileFinder (com.synopsys.integration.common.util.finder.FileFinder)1 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 ClangDetectable (com.synopsys.integration.detectable.detectables.clang.ClangDetectable)1 ClangDetectableOptions (com.synopsys.integration.detectable.detectables.clang.ClangDetectableOptions)1 ClangExtractor (com.synopsys.integration.detectable.detectables.clang.ClangExtractor)1 CompileCommand (com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand)1 CompileCommandDatabaseParser (com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandDatabaseParser)1 ClangPackageDetailsTransformer (com.synopsys.integration.detectable.detectables.clang.dependencyfile.ClangPackageDetailsTransformer)1 DependencyFileDetailGenerator (com.synopsys.integration.detectable.detectables.clang.dependencyfile.DependencyFileDetailGenerator)1