Search in sources :

Example 6 with PassedDetectableResult

use of com.synopsys.integration.detectable.detectable.result.PassedDetectableResult in project synopsys-detect by blackducksoftware.

the class SbtDetectable method sbtPluginExtractable.

// Check if SBT & a plugin can be found
private DetectableResult sbtPluginExtractable() throws DetectableException {
    List<Explanation> explanations = new ArrayList<>();
    sbt = sbtResolver.resolveSbt();
    if (sbt == null) {
        return new ExecutableNotFoundDetectableResult("sbt");
    } else {
        explanations.add(new FoundExecutable(sbt));
    }
    foundPlugin = sbtPluginFinder.isPluginInstalled(environment.getDirectory(), sbt, sbtResolutionCacheOptions.getSbtCommandAdditionalArguments());
    if (!foundPlugin) {
        return new SbtMissingPluginDetectableResult(environment.getDirectory().toString());
    } else {
        explanations.add(new FoundSbtPlugin("Dependency Graph"));
    }
    return new PassedDetectableResult(explanations);
}
Also used : ExecutableNotFoundDetectableResult(com.synopsys.integration.detectable.detectable.result.ExecutableNotFoundDetectableResult) FoundExecutable(com.synopsys.integration.detectable.detectable.explanation.FoundExecutable) Explanation(com.synopsys.integration.detectable.detectable.explanation.Explanation) SbtMissingPluginDetectableResult(com.synopsys.integration.detectable.detectable.result.SbtMissingPluginDetectableResult) ArrayList(java.util.ArrayList) FoundSbtPlugin(com.synopsys.integration.detectable.detectable.explanation.FoundSbtPlugin) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult)

Example 7 with PassedDetectableResult

use of com.synopsys.integration.detectable.detectable.result.PassedDetectableResult in project synopsys-detect by blackducksoftware.

the class DetectorToolTest method testExtractionException.

@Test
public void testExtractionException() throws DetectableException, ExecutableFailedException {
    Extraction extraction = createExceptionExtraction();
    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 8 with PassedDetectableResult

use of com.synopsys.integration.detectable.detectable.result.PassedDetectableResult in project synopsys-detect by blackducksoftware.

the class ExtractableEvaluatorTest method createEvaluationMocks.

private DetectorEvaluation createEvaluationMocks(DetectorEvaluationOptions evaluationOptions, DetectorEvaluationTree detectorEvaluationTree, boolean extractable, boolean throwException) throws DetectableException {
    DetectorEvaluation detectorEvaluation = Mockito.mock(DetectorEvaluation.class);
    Detectable detectable = Mockito.mock(Detectable.class);
    DetectableResult detectableExtractableResult = Mockito.mock(DetectableResult.class);
    Mockito.when(detectableExtractableResult.getPassed()).thenReturn(true);
    Mockito.when(detectableExtractableResult.toDescription()).thenReturn("test detectable");
    Mockito.when(detectable.extractable()).thenReturn(detectableExtractableResult);
    Mockito.when(detectorEvaluation.getDetectable()).thenReturn(detectable);
    List<DetectorEvaluation> detectorEvaluations = Collections.singletonList(detectorEvaluation);
    Mockito.when(detectorEvaluationTree.getOrderedEvaluations()).thenReturn(detectorEvaluations);
    DetectorRuleSet detectorRuleSet = Mockito.mock(DetectorRuleSet.class);
    Mockito.when(detectorEvaluationTree.getDetectorRuleSet()).thenReturn(detectorRuleSet);
    DetectorRule detectorRule = Mockito.mock(DetectorRule.class);
    Mockito.when(detectorRule.getDescriptiveName()).thenReturn("test rule");
    Mockito.when(detectorEvaluation.getDetectorRule()).thenReturn(detectorRule);
    Mockito.when(detectorEvaluationTree.getDepthFromRoot()).thenReturn(0);
    Mockito.when(evaluationOptions.isForceNested()).thenReturn(true);
    Predicate<DetectorRule> rulePredicate = it -> true;
    Mockito.when(evaluationOptions.getDetectorFilter()).thenReturn(rulePredicate);
    Mockito.when(detectorEvaluation.isSearchable()).thenReturn(true);
    Mockito.when(detectorEvaluation.isApplicable()).thenReturn(true);
    Mockito.when(detectorEvaluation.isExtractable()).thenReturn(extractable);
    Mockito.when(detectorRule.createDetectable(Mockito.any(DetectableEnvironment.class))).thenReturn(detectable);
    Mockito.when(detectable.applicable()).thenReturn(new PassedDetectableResult());
    if (throwException) {
        Mockito.when(detectable.extractable()).thenThrow(new DetectableException("JUnit Expected Exception."));
    } else {
        Mockito.when(detectable.extractable()).thenReturn(detectableExtractableResult);
    }
    return 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) Detectable(com.synopsys.integration.detectable.Detectable) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet)

Example 9 with PassedDetectableResult

use of com.synopsys.integration.detectable.detectable.result.PassedDetectableResult in project synopsys-detect by blackducksoftware.

the class ExtractionEvaluatorTest method createEvaluationMocks.

private DetectorEvaluation createEvaluationMocks(DetectorEvaluationOptions evaluationOptions, DetectorEvaluationTree detectorEvaluationTree, boolean extractionExists, boolean throwException) throws DetectableException, ExecutableFailedException, IOException, CycleDetectedException, MissingExternalIdException, ExecutableRunnerException, ParserConfigurationException, SAXException {
    ExtractionEnvironment extractionEnvironment = Mockito.mock(ExtractionEnvironment.class);
    DetectorEvaluation detectorEvaluation = Mockito.mock(DetectorEvaluation.class);
    Detectable detectable = Mockito.mock(Detectable.class);
    DetectableResult detectableExtractableResult = Mockito.mock(DetectableResult.class);
    Mockito.when(detectableExtractableResult.getPassed()).thenReturn(true);
    Mockito.when(detectableExtractableResult.toDescription()).thenReturn("test detectable");
    Mockito.when(detectable.extractable()).thenReturn(detectableExtractableResult);
    Mockito.when(detectorEvaluation.getDetectable()).thenReturn(detectable);
    Mockito.when(detectorEvaluation.getExtractionEnvironment()).thenReturn(extractionEnvironment);
    Mockito.when(detectorEvaluation.isSearchable()).thenReturn(true);
    Mockito.when(detectorEvaluation.isApplicable()).thenReturn(true);
    Mockito.when(detectorEvaluation.isExtractable()).thenReturn(true);
    List<DetectorEvaluation> detectorEvaluations = Collections.singletonList(detectorEvaluation);
    Mockito.when(detectorEvaluationTree.getOrderedEvaluations()).thenReturn(detectorEvaluations);
    DetectorRuleSet detectorRuleSet = Mockito.mock(DetectorRuleSet.class);
    Mockito.when(detectorEvaluationTree.getDetectorRuleSet()).thenReturn(detectorRuleSet);
    DetectorRule detectorRule = Mockito.mock(DetectorRule.class);
    Mockito.when(detectorRule.getDescriptiveName()).thenReturn("test rule");
    Mockito.when(detectorEvaluation.getDetectorRule()).thenReturn(detectorRule);
    Mockito.when(detectorEvaluationTree.getDepthFromRoot()).thenReturn(0);
    Mockito.when(evaluationOptions.isForceNested()).thenReturn(true);
    Predicate<DetectorRule> rulePredicate = it -> true;
    Mockito.when(evaluationOptions.getDetectorFilter()).thenReturn(rulePredicate);
    Mockito.when(detectorRule.createDetectable(Mockito.any(DetectableEnvironment.class))).thenReturn(detectable);
    Mockito.when(detectable.applicable()).thenReturn(new PassedDetectableResult());
    if (throwException) {
        Mockito.when(detectable.extract(Mockito.eq(extractionEnvironment))).thenThrow(new RuntimeException("JUnit expected exception"));
    } else {
        Mockito.when(detectable.extract(Mockito.eq(extractionEnvironment))).thenReturn(new Extraction.Builder().success().build());
    }
    return detectorEvaluation;
}
Also used : DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) Detectable(com.synopsys.integration.detectable.Detectable) CycleDetectedException(com.synopsys.integration.detectable.util.CycleDetectedException) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) Predicate(java.util.function.Predicate) IOException(java.io.IOException) MissingExternalIdException(com.synopsys.integration.bdio.graph.builder.MissingExternalIdException) 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) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) Collections(java.util.Collections) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) Detectable(com.synopsys.integration.detectable.Detectable) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction)

Example 10 with PassedDetectableResult

use of com.synopsys.integration.detectable.detectable.result.PassedDetectableResult in project synopsys-detect by blackducksoftware.

the class ConanLockfileDetectable method applicable.

@Override
public DetectableResult applicable() {
    if (conanLockfileExtractorOptions.getLockfilePath().isPresent()) {
        Path conanLockFile = conanLockfileExtractorOptions.getLockfilePath().get();
        logger.debug("Conan Lockfile detectable applies because user supplied lockfile path {}", conanLockFile);
        // TODO: Should lock file be reported as a relevant file?
        return new PassedDetectableResult(new FoundFile(conanLockFile.toFile()));
    }
    Requirements requirements = new Requirements(fileFinder, environment);
    lockfile = requirements.file(CONANLOCKFILE);
    return requirements.result();
}
Also used : Path(java.nio.file.Path) FoundFile(com.synopsys.integration.detectable.detectable.explanation.FoundFile) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) Requirements(com.synopsys.integration.detectable.detectable.Requirements)

Aggregations

PassedDetectableResult (com.synopsys.integration.detectable.detectable.result.PassedDetectableResult)14 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)6 Test (org.junit.jupiter.api.Test)6 Extraction (com.synopsys.integration.detectable.extraction.Extraction)5 File (java.io.File)5 FoundFile (com.synopsys.integration.detectable.detectable.explanation.FoundFile)4 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)3 FoundExecutable (com.synopsys.integration.detectable.detectable.explanation.FoundExecutable)3 Detectable (com.synopsys.integration.detectable.Detectable)2 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)2 Explanation (com.synopsys.integration.detectable.detectable.explanation.Explanation)2 ExecutableNotFoundDetectableResult (com.synopsys.integration.detectable.detectable.result.ExecutableNotFoundDetectableResult)2 ExtractionEnvironment (com.synopsys.integration.detectable.extraction.ExtractionEnvironment)2 DetectorEvaluation (com.synopsys.integration.detector.base.DetectorEvaluation)2 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)2 DetectorRule (com.synopsys.integration.detector.rule.DetectorRule)2 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2