Search in sources :

Example 1 with ExtractionId

use of com.blackducksoftware.integration.hub.detect.detector.ExtractionId in project hub-detect by blackducksoftware.

the class ExtractionManager method performExtractions.

public ExtractionResult performExtractions(final List<DetectorEvaluation> results) {
    final List<DetectorEvaluation> extractable = results.stream().filter(result -> result.isExtractable()).collect(Collectors.toList());
    for (int i = 0; i < extractable.size(); i++) {
        final DetectorEvaluation detectorEvaluation = extractable.get(i);
        final String progress = Integer.toString((int) Math.floor((i * 100.0f) / extractable.size()));
        logger.info(String.format("Extracting %d of %d (%s%%)", i + 1, extractable.size(), progress));
        logger.info(ReportConstants.SEPERATOR);
        final ExtractionId extractionId = new ExtractionId(detectorEvaluation.getDetector().getDetectorType(), Integer.toString(i));
        detectorEvaluation.setExtractionId(extractionId);
        extract(extractable.get(i));
    }
    final Set<DetectorType> succesfulBomToolGroups = extractable.stream().filter(it -> it.wasExtractionSuccessful()).map(it -> it.getDetector().getDetectorType()).collect(Collectors.toSet());
    final Set<DetectorType> failedBomToolGroups = extractable.stream().filter(it -> !it.wasExtractionSuccessful()).map(it -> it.getDetector().getDetectorType()).collect(Collectors.toSet());
    final List<DetectCodeLocation> codeLocations = extractable.stream().filter(it -> it.wasExtractionSuccessful()).flatMap(it -> it.getExtraction().codeLocations.stream()).collect(Collectors.toList());
    return new ExtractionResult(codeLocations, succesfulBomToolGroups, failedBomToolGroups);
}
Also used : DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) ExtractionResultType(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction.ExtractionResultType) Logger(org.slf4j.Logger) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) ExtractionId(com.blackducksoftware.integration.hub.detect.detector.ExtractionId) InfoLogReportWriter(com.blackducksoftware.integration.hub.detect.workflow.report.writer.InfoLogReportWriter) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ReportConstants(com.blackducksoftware.integration.hub.detect.workflow.report.util.ReportConstants) ObjectPrinter(com.blackducksoftware.integration.hub.detect.workflow.report.util.ObjectPrinter) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation) ExtractionId(com.blackducksoftware.integration.hub.detect.detector.ExtractionId)

Example 2 with ExtractionId

use of com.blackducksoftware.integration.hub.detect.detector.ExtractionId in project hub-detect by blackducksoftware.

the class NugetSolutionExtractionDebugger method debug.

public void debug(LoggedDetectExtraction extraction, DetectRunInfo detectRunInfo, DetectConfiguration detectConfiguration) {
    String id = extraction.extractionIdentifier;
    try {
        NugetInspectorPackager packager = new NugetInspectorPackager(new Gson(), new ExternalIdFactory());
        DetectFileFinder detectFileFinder = new DetectFileFinder();
        File extractionFolder = new File(detectRunInfo.getExtractionsFolder(), extraction.extractionIdentifier);
        List<File> extractionFiles = Arrays.asList(extractionFolder.listFiles());
        DetectFileFinder mock = Mockito.mock(DetectFileFinder.class);
        Mockito.when(mock.findFiles(Mockito.any(), Mockito.any())).thenReturn(extractionFiles);
        NugetInspectorExtractor nugetInspectorExtractor = new NugetInspectorExtractor(packager, mock, detectConfiguration);
        NugetInspector inspector = Mockito.mock(NugetInspector.class);
        Mockito.when(inspector.execute(Mockito.any(), Mockito.any())).thenReturn(new ExecutableOutput("", ""));
        File mockTarget = Mockito.mock(File.class);
        Mockito.when(mockTarget.toString()).thenReturn("mock/target");
        File mockOutput = Mockito.mock(File.class);
        Mockito.when(mockOutput.getCanonicalPath()).thenReturn("mock/output");
        Mockito.when(mockOutput.toString()).thenReturn("mock/output");
        Extraction newExtraction = nugetInspectorExtractor.extract(mockTarget, mockOutput, inspector, new ExtractionId(DetectorType.NUGET, id));
        logger.info("We did it: " + newExtraction.result.toString());
    } catch (Exception e) {
        logger.info("We did not do it: " + e.toString());
        throw new RuntimeException(e);
    }
}
Also used : NugetInspectorExtractor(com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorExtractor) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Gson(com.google.gson.Gson) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) NugetInspectorPackager(com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorPackager) NugetInspector(com.blackducksoftware.integration.hub.detect.detector.nuget.inspector.NugetInspector) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) LoggedDetectExtraction(com.synopsys.detect.doctor.logparser.LoggedDetectExtraction) ExtractionId(com.blackducksoftware.integration.hub.detect.detector.ExtractionId) File(java.io.File)

Example 3 with ExtractionId

use of com.blackducksoftware.integration.hub.detect.detector.ExtractionId in project hub-detect by blackducksoftware.

the class ClangExtractorTest method testMultipleCommandsDependenciesPackages.

@Test
public void testMultipleCommandsDependenciesPackages() throws ExecutableRunnerException {
    Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS);
    final CompileCommand compileCommandWrapperHelloWorld = createCompileCommand("src/test/resources/clang/source/hello_world.cpp", "gcc hello_world.cpp", null);
    final CompileCommand compileCommandWrapperGoodbyeWorld = createCompileCommand("src/test/resources/clang/source/goodbye_world.cpp", "gcc goodbye_world.cpp", null);
    final Set<String> dependencyFilePathsHelloWorld = createDependencyFilePaths(new File("src/test/resources/clang/source/myinclude.h"), new File("/usr/include/nonexistentfile1.h"), new File("/usr/include/nonexistentfile2.h"));
    final Set<String> dependencyFilePathsGoodbyeWorld = createDependencyFilePaths(new File("/usr/include/nonexistentfile4.h"), new File("/usr/include/nonexistentfile3.h"));
    final ExecutableRunner executableRunner = Mockito.mock(ExecutableRunner.class);
    final DirectoryManager directoryManager = Mockito.mock(DirectoryManager.class);
    final DependenciesListFileManager dependenciesListFileManager = Mockito.mock(DependenciesListFileManager.class);
    Mockito.when(dependenciesListFileManager.generateDependencyFilePaths(outputDir, compileCommandWrapperHelloWorld, true)).thenReturn(dependencyFilePathsHelloWorld);
    Mockito.when(dependenciesListFileManager.generateDependencyFilePaths(outputDir, compileCommandWrapperGoodbyeWorld, true)).thenReturn(dependencyFilePathsGoodbyeWorld);
    Mockito.when(executableRunner.executeFromDirQuietly(Mockito.any(File.class), Mockito.anyString(), Mockito.anyList())).thenReturn(new ExecutableOutput(0, "", ""));
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final CodeLocationAssembler codeLocationAssembler = new CodeLocationAssembler(externalIdFactory);
    final ClangExtractor extractor = new ClangExtractor(null, executableRunner, gson, new DetectFileFinder(), directoryManager, dependenciesListFileManager, codeLocationAssembler);
    final ClangLinuxPackageManager pkgMgr = Mockito.mock(ClangLinuxPackageManager.class);
    final File givenDir = new File("src/test/resources/clang/source/build");
    final int depth = 1;
    final ExtractionId extractionId = new ExtractionId(DetectorType.CLANG, EXTRACTION_ID);
    final File jsonCompilationDatabaseFile = new File("src/test/resources/clang/source/build/compile_commands.json");
    Mockito.when(directoryManager.getExtractionOutputDirectory(Mockito.any(ExtractionId.class))).thenReturn(outputDir);
    final List<PackageDetails> packages = new ArrayList<>();
    packages.add(new PackageDetails("testPackageName1", "testPackageVersion1", "testPackageArch1"));
    packages.add(new PackageDetails("testPackageName2", "testPackageVersion2", "testPackageArch2"));
    Mockito.when(pkgMgr.getDefaultForge()).thenReturn(Forge.CENTOS);
    Mockito.when(pkgMgr.getPackages(Mockito.any(File.class), Mockito.any(ExecutableRunner.class), Mockito.any(Set.class), Mockito.any(DependencyFileDetails.class))).thenReturn(packages);
    Mockito.when(pkgMgr.getForges()).thenReturn(Arrays.asList(Forge.CENTOS, Forge.FEDORA, Forge.REDHAT));
    final Extraction extraction = extractor.extract(pkgMgr, givenDir, depth, extractionId, jsonCompilationDatabaseFile);
    checkGeneratedDependenciesComplex(extraction);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) DirectoryManager(com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager) ArrayList(java.util.ArrayList) ExecutableRunner(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) ExtractionId(com.blackducksoftware.integration.hub.detect.detector.ExtractionId) File(java.io.File) Test(org.junit.Test)

Example 4 with ExtractionId

use of com.blackducksoftware.integration.hub.detect.detector.ExtractionId in project hub-detect by blackducksoftware.

the class ClangExtractorTest method testJsonWithArgumentsNotCommand.

@Test
public void testJsonWithArgumentsNotCommand() throws ExecutableRunnerException {
    Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS);
    final String[] argsHello = { "gcc", "hello_world.cpp" };
    final CompileCommand compileCommandWrapperHelloWorld = createCompileCommand("src/test/resources/clang/source/hello_world.cpp", null, argsHello);
    final String[] argsGoodbye = { "gcc", "goodbye_world.cpp" };
    final CompileCommand compileCommandWrapperGoodbyeWorld = createCompileCommand("src/test/resources/clang/source/goodbye_world.cpp", null, argsGoodbye);
    final Set<String> dependencyFilePathsHelloWorld = createDependencyFilePaths(new File("src/test/resources/clang/source/myinclude.h"), new File("/usr/include/nonexistentfile1.h"), new File("/usr/include/nonexistentfile2.h"));
    final Set<String> dependencyFilePathsGoodbyeWorld = createDependencyFilePaths(new File("/usr/include/nonexistentfile4.h"), new File("/usr/include/nonexistentfile3.h"));
    ;
    final ExecutableRunner executableRunner = Mockito.mock(ExecutableRunner.class);
    final DirectoryManager directoryManager = Mockito.mock(DirectoryManager.class);
    final DependenciesListFileManager dependenciesListFileManager = Mockito.mock(DependenciesListFileManager.class);
    Mockito.when(dependenciesListFileManager.generateDependencyFilePaths(outputDir, compileCommandWrapperHelloWorld, true)).thenReturn(dependencyFilePathsHelloWorld);
    Mockito.when(dependenciesListFileManager.generateDependencyFilePaths(outputDir, compileCommandWrapperGoodbyeWorld, true)).thenReturn(dependencyFilePathsGoodbyeWorld);
    Mockito.when(executableRunner.executeFromDirQuietly(Mockito.any(File.class), Mockito.anyString(), Mockito.anyList())).thenReturn(new ExecutableOutput(0, "", ""));
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final CodeLocationAssembler codeLocationAssembler = new CodeLocationAssembler(externalIdFactory);
    final ClangExtractor extractor = new ClangExtractor(null, executableRunner, gson, new DetectFileFinder(), directoryManager, dependenciesListFileManager, codeLocationAssembler);
    final ClangLinuxPackageManager pkgMgr = Mockito.mock(ClangLinuxPackageManager.class);
    final File givenDir = new File("src/test/resources/clang/source/build");
    final int depth = 1;
    final ExtractionId extractionId = new ExtractionId(DetectorType.CLANG, EXTRACTION_ID);
    final File jsonCompilationDatabaseFile = new File("src/test/resources/clang/source/build/compile_commands_usesArguments.json");
    Mockito.when(directoryManager.getExtractionOutputDirectory(Mockito.any(ExtractionId.class))).thenReturn(outputDir);
    final List<PackageDetails> packages = new ArrayList<>();
    packages.add(new PackageDetails("testPackageName1", "testPackageVersion1", "testPackageArch1"));
    packages.add(new PackageDetails("testPackageName2", "testPackageVersion2", "testPackageArch2"));
    Mockito.when(pkgMgr.getDefaultForge()).thenReturn(Forge.CENTOS);
    Mockito.when(pkgMgr.getPackages(Mockito.any(File.class), Mockito.any(ExecutableRunner.class), Mockito.any(Set.class), Mockito.any(DependencyFileDetails.class))).thenReturn(packages);
    Mockito.when(pkgMgr.getForges()).thenReturn(Arrays.asList(Forge.CENTOS, Forge.FEDORA, Forge.REDHAT));
    final Extraction extraction = extractor.extract(pkgMgr, givenDir, depth, extractionId, jsonCompilationDatabaseFile);
    checkGeneratedDependenciesComplex(extraction);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) DirectoryManager(com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager) ArrayList(java.util.ArrayList) ExecutableRunner(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) ExtractionId(com.blackducksoftware.integration.hub.detect.detector.ExtractionId) File(java.io.File) Test(org.junit.Test)

Example 5 with ExtractionId

use of com.blackducksoftware.integration.hub.detect.detector.ExtractionId in project hub-detect by blackducksoftware.

the class ClangExtractorTest method testSimple.

@Test
public void testSimple() throws ExecutableRunnerException {
    Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS);
    final CompileCommand compileCommandWrapper = createCompileCommand("src/test/resources/clang/source/hello_world.cpp", "gcc hello_world.cpp", null);
    final Set<String> dependencyFilePaths = createDependencyFilePaths(new File("/usr/include/nonexistentfile1.h"), new File("src/test/resources/clang/source/myinclude.h"));
    final ExecutableRunner executableRunner = Mockito.mock(ExecutableRunner.class);
    final DirectoryManager directoryManager = Mockito.mock(DirectoryManager.class);
    final DependenciesListFileManager dependenciesListFileManager = Mockito.mock(DependenciesListFileManager.class);
    Mockito.when(dependenciesListFileManager.generateDependencyFilePaths(outputDir, compileCommandWrapper, true)).thenReturn(dependencyFilePaths);
    Mockito.when(executableRunner.executeFromDirQuietly(Mockito.any(File.class), Mockito.anyString(), Mockito.anyList())).thenReturn(new ExecutableOutput(0, "", ""));
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final CodeLocationAssembler codeLocationAssembler = new CodeLocationAssembler(externalIdFactory);
    final ClangExtractor extractor = new ClangExtractor(null, executableRunner, gson, new DetectFileFinder(), directoryManager, dependenciesListFileManager, codeLocationAssembler);
    final ClangLinuxPackageManager pkgMgr = Mockito.mock(ClangLinuxPackageManager.class);
    final File givenDir = new File("src/test/resources/clang/source/build");
    final int depth = 1;
    final ExtractionId extractionId = new ExtractionId(DetectorType.CLANG, EXTRACTION_ID);
    final File jsonCompilationDatabaseFile = new File("src/test/resources/clang/source/build/compile_commands.json");
    Mockito.when(directoryManager.getExtractionOutputDirectory(Mockito.any(ExtractionId.class))).thenReturn(outputDir);
    final List<PackageDetails> packages = new ArrayList<>();
    packages.add(new PackageDetails("testPackageName", "testPackageVersion", "testPackageArch"));
    Mockito.when(pkgMgr.getDefaultForge()).thenReturn(Forge.UBUNTU);
    Mockito.when(pkgMgr.getPackages(Mockito.any(File.class), Mockito.any(ExecutableRunner.class), Mockito.any(Set.class), Mockito.any(DependencyFileDetails.class))).thenReturn(packages);
    Mockito.when(pkgMgr.getForges()).thenReturn(Arrays.asList(Forge.UBUNTU, Forge.DEBIAN));
    final Extraction extraction = extractor.extract(pkgMgr, givenDir, depth, extractionId, jsonCompilationDatabaseFile);
    checkGeneratedDependenciesSimple(extraction);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) DirectoryManager(com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager) ArrayList(java.util.ArrayList) ExecutableRunner(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) ExtractionId(com.blackducksoftware.integration.hub.detect.detector.ExtractionId) File(java.io.File) Test(org.junit.Test)

Aggregations

ExtractionId (com.blackducksoftware.integration.hub.detect.detector.ExtractionId)6 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)5 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)5 DetectFileFinder (com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder)5 File (java.io.File)5 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)4 ArrayList (java.util.ArrayList)4 Set (java.util.Set)4 ExecutableRunner (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)3 DirectoryManager (com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 NugetInspector (com.blackducksoftware.integration.hub.detect.detector.nuget.inspector.NugetInspector)2 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 DetectConfiguration (com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration)1 DetectProperty (com.blackducksoftware.integration.hub.detect.configuration.DetectProperty)1