Search in sources :

Example 51 with Extraction

use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.

the class ConanCliExtractor method extract.

public Extraction extract(File projectDir, ExecutableTarget conanExe) {
    toolVersionLogger.log(projectDir, conanExe);
    ExecutableOutput conanInfoOutput;
    try {
        conanInfoOutput = conanCommandRunner.runConanInfoCommand(projectDir, conanExe);
    } catch (Exception e) {
        logger.error(String.format("Exception thrown executing conan info command: %s", e.getMessage()));
        return new Extraction.Builder().exception(e).build();
    }
    if (!conanCommandRunner.wasSuccess(conanInfoOutput)) {
        return new Extraction.Builder().failure("Conan info command reported errors").build();
    }
    if (!conanCommandRunner.producedOutput(conanInfoOutput)) {
        return new Extraction.Builder().failure("Conan info command produced no output").build();
    }
    try {
        ConanDetectableResult result = conanInfoParser.generateCodeLocationFromConanInfoOutput(conanInfoOutput.getStandardOutput());
        return new Extraction.Builder().success(result.getCodeLocation()).projectName(result.getProjectName()).projectVersion(result.getProjectVersion()).build();
    } catch (DetectableException e) {
        return new Extraction.Builder().failure(e.getMessage()).build();
    }
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) ConanDetectableResult(com.synopsys.integration.detectable.detectables.conan.ConanDetectableResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 52 with Extraction

use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.

the class DetectorToolTest method testPreferredDetectorMissingSuccess.

@Test
public void testPreferredDetectorMissingSuccess() throws DetectableException, ExecutableFailedException {
    Extraction extraction = createSuccessExtraction();
    DetectableResult extractionResult = new PassedDetectableResult();
    String projectBomTool = "testBomTool";
    DetectorToolResult result = executeToolTest(extraction, extractionResult, projectBomTool);
    assertFalse(result.getApplicableDetectorTypes().isEmpty());
    assertTrue(result.getBomToolCodeLocations().isEmpty());
    assertTrue(result.getBomToolProjectNameVersion().isPresent());
    assertTrue(result.getCodeLocationMap().isEmpty());
    assertTrue(result.getFailedDetectorTypes().isEmpty());
    assertTrue(result.getRootDetectorEvaluationTree().isPresent());
}
Also used : DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) Test(org.junit.jupiter.api.Test)

Example 53 with Extraction

use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.

the class DetectorToolTest method testExtractionFailed.

@Test
public void testExtractionFailed() throws DetectableException, ExecutableFailedException {
    Extraction extraction = createFailExtraction();
    DetectableResult extractionResult = new PassedDetectableResult();
    String projectBomTool = DetectorType.GO_MOD.name();
    DetectorToolResult result = executeToolTest(extraction, extractionResult, projectBomTool);
    assertFalse(result.getApplicableDetectorTypes().isEmpty());
    assertTrue(result.getBomToolCodeLocations().isEmpty());
    assertFalse(result.getBomToolProjectNameVersion().isPresent());
    assertTrue(result.getCodeLocationMap().isEmpty());
    assertTrue(result.getFailedDetectorTypes().isEmpty());
    assertTrue(result.getRootDetectorEvaluationTree().isPresent());
}
Also used : DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) Test(org.junit.jupiter.api.Test)

Example 54 with Extraction

use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.

the class DetectorToolTest method testSuccess.

@Test
public void testSuccess() throws DetectableException, ExecutableFailedException {
    Extraction extraction = createSuccessExtraction();
    DetectableResult extractionResult = new PassedDetectableResult();
    String projectBomTool = DetectorType.GO_MOD.name();
    DetectorToolResult result = executeToolTest(extraction, extractionResult, projectBomTool);
    assertFalse(result.getApplicableDetectorTypes().isEmpty());
    assertTrue(result.getBomToolCodeLocations().isEmpty());
    assertTrue(result.getBomToolProjectNameVersion().isPresent());
    assertTrue(result.getCodeLocationMap().isEmpty());
    assertTrue(result.getFailedDetectorTypes().isEmpty());
    assertTrue(result.getRootDetectorEvaluationTree().isPresent());
}
Also used : DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) Test(org.junit.jupiter.api.Test)

Example 55 with Extraction

use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.

the class PackageJsonExtractorFunctionalTest method extractWithPeerDependencies.

@Test
void extractWithPeerDependencies() {
    Extraction extraction = createExtractor(NpmDependencyType.DEV).extract(packageJsonInputStream);
    assertEquals(1, extraction.getCodeLocations().size());
    CodeLocation codeLocation = extraction.getCodeLocations().get(0);
    DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
    GraphAssert graphAssert = new GraphAssert(Forge.RUBYGEMS, dependencyGraph);
    graphAssert.hasRootDependency(testDep1);
    graphAssert.hasRootDependency(testDep2);
    graphAssert.hasRootDependency(testPeerDep1);
    graphAssert.hasRootDependency(testPeerDep2);
    graphAssert.hasNoDependency(testDevDep1);
    graphAssert.hasNoDependency(testDevDep2);
    graphAssert.hasRootSize(4);
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) GraphAssert(com.synopsys.integration.detectable.util.graph.GraphAssert) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.jupiter.api.Test) FunctionalTest(com.synopsys.integration.detectable.annotations.FunctionalTest)

Aggregations

Extraction (com.synopsys.integration.detectable.extraction.Extraction)63 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)38 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)23 IOException (java.io.IOException)19 Test (org.junit.jupiter.api.Test)18 File (java.io.File)17 ArrayList (java.util.ArrayList)14 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)13 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)12 NameVersion (com.synopsys.integration.util.NameVersion)12 Executable (com.synopsys.integration.executable.Executable)11 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)9 List (java.util.List)9 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)8 HashMap (java.util.HashMap)8 Optional (java.util.Optional)8 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)7 Collectors (java.util.stream.Collectors)7 ExecutableFailedException (com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException)6 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)6