Search in sources :

Example 1 with ExtractionEnvironment

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

the class DetectableTool method extract.

public DetectableToolResult extract() {
    // TODO: Move docker/bazel out of detectable and drop this notion of a detctable tool. Will simplify this logic and make this unneccessary.
    DetectableResult extractable;
    try {
        extractable = detectable.extractable();
    } catch (DetectableException e) {
        extractable = new ExceptionDetectableResult(e);
    }
    if (!extractable.getPassed()) {
        logger.error(String.format("Was not extractable: %s", extractable.toDescription()));
        statusEventPublisher.publishIssue(new DetectIssue(DetectIssueType.DETECTABLE_TOOL, "Detectable Tool Issue", Arrays.asList(extractable.toDescription())));
        statusEventPublisher.publishStatusSummary(new Status(name, StatusType.FAILURE));
        exitCodePublisher.publishExitCode(ExitCodeType.FAILURE_GENERAL_ERROR, extractable.toDescription());
        return DetectableToolResult.failed(extractable);
    }
    logger.debug("Extractable passed.");
    ExtractionEnvironment extractionEnvironment = extractionEnvironmentProvider.createExtractionEnvironment(name);
    Extraction extraction;
    try {
        extraction = detectable.extract(extractionEnvironment);
    } catch (ExecutableFailedException | ExecutableRunnerException | JsonSyntaxException | IOException | CycleDetectedException | DetectableException | MissingExternalIdException | ParserConfigurationException | SAXException e) {
        extraction = new Extraction.Builder().exception(e).build();
    }
    if (!extraction.isSuccess()) {
        logger.error("Extraction was not success.");
        List<String> errorMessages = collectErrorMessages(extraction);
        statusEventPublisher.publishIssue(new DetectIssue(DetectIssueType.DETECTABLE_TOOL, "Detectable Tool Issue", errorMessages));
        statusEventPublisher.publishStatusSummary(new Status(name, StatusType.FAILURE));
        exitCodePublisher.publishExitCode(new ExitCodeRequest(ExitCodeType.FAILURE_GENERAL_ERROR, extraction.getDescription()));
        return DetectableToolResult.failed();
    } else {
        logger.debug("Extraction success.");
        statusEventPublisher.publishStatusSummary(new Status(name, StatusType.SUCCESS));
    }
    Map<CodeLocation, DetectCodeLocation> detectCodeLocationMap = codeLocationConverter.toDetectCodeLocation(sourcePath, extraction, sourcePath, name);
    List<DetectCodeLocation> detectCodeLocations = new ArrayList<>(detectCodeLocationMap.values());
    DockerTargetData dockerTargetData = DockerTargetData.fromExtraction(extraction);
    DetectToolProjectInfo projectInfo = null;
    if (StringUtils.isNotBlank(extraction.getProjectName()) || StringUtils.isNotBlank(extraction.getProjectVersion())) {
        NameVersion nameVersion = new NameVersion(extraction.getProjectName(), extraction.getProjectVersion());
        projectInfo = new DetectToolProjectInfo(detectTool, nameVersion);
    }
    logger.debug("Tool finished.");
    return DetectableToolResult.success(detectCodeLocations, projectInfo, dockerTargetData);
}
Also used : ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) NameVersion(com.synopsys.integration.util.NameVersion) CycleDetectedException(com.synopsys.integration.detectable.util.CycleDetectedException) ArrayList(java.util.ArrayList) SAXException(org.xml.sax.SAXException) DetectIssue(com.synopsys.integration.detect.workflow.status.DetectIssue) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) Extraction(com.synopsys.integration.detectable.extraction.Extraction) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DockerTargetData(com.synopsys.integration.detect.lifecycle.run.data.DockerTargetData) Status(com.synopsys.integration.detect.workflow.status.Status) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExitCodeRequest(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest) IOException(java.io.IOException) MissingExternalIdException(com.synopsys.integration.bdio.graph.builder.MissingExternalIdException) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) JsonSyntaxException(com.google.gson.JsonSyntaxException) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) ExceptionDetectableResult(com.synopsys.integration.detectable.detectable.result.ExceptionDetectableResult) ExceptionDetectableResult(com.synopsys.integration.detectable.detectable.result.ExceptionDetectableResult) DetectToolProjectInfo(com.synopsys.integration.detect.workflow.project.DetectToolProjectInfo) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 2 with ExtractionEnvironment

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

the class DetectorEvaluatorTest method testEvaluation.

@Test
public void testEvaluation() {
    DetectorEvaluatorListener listener = Mockito.mock(DetectorEvaluatorListener.class);
    DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
    ExtractionEnvironment extractionEnvironment = Mockito.mock(ExtractionEnvironment.class);
    Function<DetectorEvaluation, ExtractionEnvironment> extractionEnvironmentProvider = (detectorEvaluation) -> extractionEnvironment;
    DetectorEvaluationTree rootEvaluation = Mockito.mock(DetectorEvaluationTree.class);
    DetectorEvaluator detectorEvaluator = new DetectorEvaluator(evaluationOptions, extractionEnvironmentProvider);
    detectorEvaluator.setDetectorEvaluatorListener(listener);
    DetectorAggregateEvaluationResult result = detectorEvaluator.evaluate(rootEvaluation);
    Optional<DetectorEvaluatorListener> actualListener = detectorEvaluator.getDetectorEvaluatorListener();
    assertTrue(actualListener.isPresent());
    assertEquals(listener, actualListener.get());
    assertEquals(rootEvaluation, result.getEvaluationTree());
}
Also used : Test(org.junit.jupiter.api.Test) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) Mockito(org.mockito.Mockito) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) Function(java.util.function.Function) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) Test(org.junit.jupiter.api.Test)

Example 3 with ExtractionEnvironment

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

the class ExtractableEvaluatorTest method testEvaluationExtractableAlreadyPerformed.

@Test
public void testEvaluationExtractableAlreadyPerformed() throws DetectableException {
    DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
    ExtractionEnvironment extractionEnvironment = Mockito.mock(ExtractionEnvironment.class);
    Function<DetectorEvaluation, ExtractionEnvironment> extractionEnvironmentProvider = (detectorEvaluation) -> extractionEnvironment;
    ExtractableEvaluator evaluator = new ExtractableEvaluator(evaluationOptions, extractionEnvironmentProvider);
    DetectorEvaluationTree detectorEvaluationTree = Mockito.mock(DetectorEvaluationTree.class);
    Mockito.when(detectorEvaluationTree.getDirectory()).thenReturn(new File("."));
    DetectorEvaluatorListener detectorEvaluatorListener = Mockito.mock(DetectorEvaluatorListener.class);
    evaluator.setDetectorEvaluatorListener(detectorEvaluatorListener);
    DetectorEvaluation detectorEvaluation = createEvaluationMocks(evaluationOptions, detectorEvaluationTree, true, false);
    DetectorAggregateEvaluationResult result = evaluator.evaluate(detectorEvaluationTree);
    assertEquals(detectorEvaluationTree, result.getEvaluationTree());
    Mockito.verify(detectorEvaluatorListener).extractableStarted(detectorEvaluation);
    Mockito.verify(detectorEvaluation).setExtractable(Mockito.any(DetectorResult.class));
    Mockito.verify(detectorEvaluatorListener).extractableEnded(detectorEvaluation);
}
Also used : DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) Predicate(java.util.function.Predicate) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) Function(java.util.function.Function) File(java.io.File) Test(org.junit.jupiter.api.Test) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) Mockito(org.mockito.Mockito) List(java.util.List) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) Detectable(com.synopsys.integration.detectable.Detectable) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) Collections(java.util.Collections) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 4 with ExtractionEnvironment

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

the class ExtractableEvaluatorTest method testEvaluationExtractableException.

@Test
public void testEvaluationExtractableException() throws DetectableException {
    DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
    ExtractionEnvironment extractionEnvironment = Mockito.mock(ExtractionEnvironment.class);
    Function<DetectorEvaluation, ExtractionEnvironment> extractionEnvironmentProvider = (detectorEvaluation) -> extractionEnvironment;
    ExtractableEvaluator evaluator = new ExtractableEvaluator(evaluationOptions, extractionEnvironmentProvider);
    DetectorEvaluationTree detectorEvaluationTree = Mockito.mock(DetectorEvaluationTree.class);
    Mockito.when(detectorEvaluationTree.getDirectory()).thenReturn(new File("."));
    DetectorEvaluatorListener detectorEvaluatorListener = Mockito.mock(DetectorEvaluatorListener.class);
    evaluator.setDetectorEvaluatorListener(detectorEvaluatorListener);
    DetectorEvaluation detectorEvaluation = createEvaluationMocks(evaluationOptions, detectorEvaluationTree, false, true);
    DetectorAggregateEvaluationResult result = evaluator.evaluate(detectorEvaluationTree);
    assertEquals(detectorEvaluationTree, result.getEvaluationTree());
    Mockito.verify(detectorEvaluatorListener).extractableStarted(detectorEvaluation);
    Mockito.verify(detectorEvaluation).setExtractable(Mockito.any(DetectorResult.class));
    Mockito.verify(detectorEvaluatorListener).extractableEnded(detectorEvaluation);
}
Also used : DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) Predicate(java.util.function.Predicate) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) Function(java.util.function.Function) File(java.io.File) Test(org.junit.jupiter.api.Test) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) Mockito(org.mockito.Mockito) List(java.util.List) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) Detectable(com.synopsys.integration.detectable.Detectable) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) Collections(java.util.Collections) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 5 with ExtractionEnvironment

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

the class ExtractableEvaluatorTest method testEvaluationSuccess.

@Test
public void testEvaluationSuccess() throws DetectableException {
    DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
    ExtractionEnvironment extractionEnvironment = Mockito.mock(ExtractionEnvironment.class);
    Function<DetectorEvaluation, ExtractionEnvironment> extractionEnvironmentProvider = (detectorEvaluation) -> extractionEnvironment;
    ExtractableEvaluator evaluator = new ExtractableEvaluator(evaluationOptions, extractionEnvironmentProvider);
    DetectorEvaluationTree detectorEvaluationTree = Mockito.mock(DetectorEvaluationTree.class);
    Mockito.when(detectorEvaluationTree.getDirectory()).thenReturn(new File("."));
    DetectorEvaluatorListener detectorEvaluatorListener = Mockito.mock(DetectorEvaluatorListener.class);
    evaluator.setDetectorEvaluatorListener(detectorEvaluatorListener);
    DetectorEvaluation detectorEvaluation = createEvaluationMocks(evaluationOptions, detectorEvaluationTree, false, false);
    DetectorAggregateEvaluationResult result = evaluator.evaluate(detectorEvaluationTree);
    assertEquals(detectorEvaluationTree, result.getEvaluationTree());
    Mockito.verify(detectorEvaluatorListener).extractableStarted(detectorEvaluation);
    Mockito.verify(detectorEvaluation).setExtractable(Mockito.any(DetectorResult.class));
    Mockito.verify(detectorEvaluatorListener).extractableEnded(detectorEvaluation);
}
Also used : DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) Predicate(java.util.function.Predicate) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) Function(java.util.function.Function) File(java.io.File) Test(org.junit.jupiter.api.Test) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) Mockito(org.mockito.Mockito) List(java.util.List) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) Detectable(com.synopsys.integration.detectable.Detectable) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) Collections(java.util.Collections) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

ExtractionEnvironment (com.synopsys.integration.detectable.extraction.ExtractionEnvironment)8 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)6 DetectorEvaluation (com.synopsys.integration.detector.base.DetectorEvaluation)6 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)6 Test (org.junit.jupiter.api.Test)6 Detectable (com.synopsys.integration.detectable.Detectable)5 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)5 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 Mockito (org.mockito.Mockito)5 PassedDetectableResult (com.synopsys.integration.detectable.detectable.result.PassedDetectableResult)4 DetectorRule (com.synopsys.integration.detector.rule.DetectorRule)4 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)4 File (java.io.File)4 Collections (java.util.Collections)4 List (java.util.List)4 Function (java.util.function.Function)4 Predicate (java.util.function.Predicate)4 Extraction (com.synopsys.integration.detectable.extraction.Extraction)3 DetectorResult (com.synopsys.integration.detector.result.DetectorResult)3