Search in sources :

Example 1 with DetectableResult

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

the class XcodeWorkspaceDetectable method extractable.

@Override
public DetectableResult extractable() {
    Requirements requirements = new Requirements(fileFinder, environment);
    File swiftPMDirectory = workspaceDirectory.toPath().resolve("xcshareddata/swiftpm").toFile();
    requirements.anyFile(new SearchPattern(swiftPMDirectory, "Package.resolved", packageResolvedFile -> foundPackageResolvedFile = packageResolvedFile), new SearchPattern(workspaceDirectory, "contents.xcworkspacedata", workspaceDataFile -> foundWorkspaceDataFile = workspaceDataFile));
    return requirements.result();
}
Also used : DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) PackageResolvedResult(com.synopsys.integration.detectable.detectables.swift.lock.model.PackageResolvedResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction) XcodeWorkspaceResult(com.synopsys.integration.detectable.detectables.xcode.model.XcodeWorkspaceResult) IOException(java.io.IOException) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) SearchPattern(com.synopsys.integration.detectable.detectable.SearchPattern) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) DetectableInfo(com.synopsys.integration.detectable.detectable.annotation.DetectableInfo) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Requirements(com.synopsys.integration.detectable.detectable.Requirements) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) Detectable(com.synopsys.integration.detectable.Detectable) SAXException(org.xml.sax.SAXException) FailedDetectableResult(com.synopsys.integration.detectable.detectable.result.FailedDetectableResult) Optional(java.util.Optional) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) PackageResolvedExtractor(com.synopsys.integration.detectable.detectables.swift.lock.PackageResolvedExtractor) LinkedList(java.util.LinkedList) SearchPattern(com.synopsys.integration.detectable.detectable.SearchPattern) File(java.io.File) Requirements(com.synopsys.integration.detectable.detectable.Requirements)

Example 2 with DetectableResult

use of com.synopsys.integration.detectable.detectable.result.DetectableResult 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 3 with DetectableResult

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

the class DetectableTool method initializeAndCheckForApplicable.

public boolean initializeAndCheckForApplicable(File sourcePath) {
    // TODO: Move docker/bazel out of detectable and drop this notion of a detctable tool. Will simplify this logic and make this unneccessary.
    logger.trace("Starting a detectable tool.");
    this.sourcePath = sourcePath;
    DetectableEnvironment detectableEnvironment = new DetectableEnvironment(sourcePath);
    detectable = detectableCreatable.createDetectable(detectableEnvironment);
    DetectableResult applicable = detectable.applicable();
    if (!applicable.getPassed()) {
        logger.debug("Was not applicable.");
        return false;
    }
    logger.debug("Applicable passed.");
    return true;
}
Also used : DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) ExceptionDetectableResult(com.synopsys.integration.detectable.detectable.result.ExceptionDetectableResult) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment)

Example 4 with DetectableResult

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

the class PubDepsDetectableTest method testThrowExceptionWhenLockFilePresentButNotYaml.

@Test
public void testThrowExceptionWhenLockFilePresentButNotYaml() throws DetectableException {
    FileFinder fileFinder = Mockito.mock(FileFinder.class);
    Mockito.when(fileFinder.findFile(null, "pubspec.yaml")).thenReturn(null);
    Mockito.when(fileFinder.findFile(null, "pubspec.lock")).thenReturn(new File(""));
    DartPubDepDetectable dartPubDepDetectable = new DartPubDepDetectable(new DetectableEnvironment(null), fileFinder, null, null, null, null);
    DetectableResult applicable = dartPubDepDetectable.applicable();
    Assertions.assertTrue(applicable.getPassed());
    DetectableResult extractable = dartPubDepDetectable.extractable();
    Assertions.assertTrue(extractable instanceof FileNotFoundDetectableResult);
}
Also used : FileNotFoundDetectableResult(com.synopsys.integration.detectable.detectable.result.FileNotFoundDetectableResult) DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) FileNotFoundDetectableResult(com.synopsys.integration.detectable.detectable.result.FileNotFoundDetectableResult) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) File(java.io.File) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) DartPubDepDetectable(com.synopsys.integration.detectable.detectables.dart.pubdep.DartPubDepDetectable) Test(org.junit.jupiter.api.Test)

Example 5 with DetectableResult

use of com.synopsys.integration.detectable.detectable.result.DetectableResult 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)

Aggregations

DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)14 Test (org.junit.jupiter.api.Test)9 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)8 Extraction (com.synopsys.integration.detectable.extraction.Extraction)8 PassedDetectableResult (com.synopsys.integration.detectable.detectable.result.PassedDetectableResult)6 Detectable (com.synopsys.integration.detectable.Detectable)5 ExtractionEnvironment (com.synopsys.integration.detectable.extraction.ExtractionEnvironment)5 DetectorEvaluation (com.synopsys.integration.detector.base.DetectorEvaluation)4 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)4 File (java.io.File)4 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)3 ExceptionDetectableResult (com.synopsys.integration.detectable.detectable.result.ExceptionDetectableResult)3 DetectorResult (com.synopsys.integration.detector.result.DetectorResult)3 DetectorRule (com.synopsys.integration.detector.rule.DetectorRule)3 IOException (java.io.IOException)3 List (java.util.List)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 SAXException (org.xml.sax.SAXException)3 MissingExternalIdException (com.synopsys.integration.bdio.graph.builder.MissingExternalIdException)2 FileFinder (com.synopsys.integration.common.util.finder.FileFinder)2