Search in sources :

Example 1 with FailedDetectableResult

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

the class XcodeWorkspaceDetectable method extract.

@Override
public Extraction extract(ExtractionEnvironment extractionEnvironment) throws IOException, ParserConfigurationException, SAXException {
    List<CodeLocation> codeLocations = new LinkedList<>();
    if (foundPackageResolvedFile != null) {
        PackageResolvedResult localResult = packageResolvedExtractor.extract(foundPackageResolvedFile);
        Optional<FailedDetectableResult> failedDetectableResult = localResult.getFailedDetectableResult();
        if (failedDetectableResult.isPresent()) {
            return Extraction.failure(failedDetectableResult.get());
        }
        codeLocations.add(new CodeLocation(localResult.getDependencyGraph(), environment.getDirectory()));
    }
    if (foundWorkspaceDataFile != null) {
        XcodeWorkspaceResult xcodeWorkspaceResult = xcodeWorkspaceExtractor.extract(foundWorkspaceDataFile, workspaceDirectory);
        if (xcodeWorkspaceResult.isFailure()) {
            return Extraction.failure(xcodeWorkspaceResult.getFailedDetectableResults());
        }
        codeLocations.addAll(xcodeWorkspaceResult.getCodeLocations());
    }
    return Extraction.success(codeLocations);
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) FailedDetectableResult(com.synopsys.integration.detectable.detectable.result.FailedDetectableResult) PackageResolvedResult(com.synopsys.integration.detectable.detectables.swift.lock.model.PackageResolvedResult) XcodeWorkspaceResult(com.synopsys.integration.detectable.detectables.xcode.model.XcodeWorkspaceResult) LinkedList(java.util.LinkedList)

Example 2 with FailedDetectableResult

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

the class XcodeWorkspaceExtractor method extract.

public XcodeWorkspaceResult extract(File workspaceDataFile, File workspaceDirectory) throws IOException, ParserConfigurationException, SAXException {
    String workspaceFileContents = FileUtils.readFileToString(workspaceDataFile, Charset.defaultCharset());
    XcodeWorkspace xcodeWorkspace = xcodeWorkspaceParser.parse(workspaceFileContents);
    xcodeWorkspaceFormatChecker.checkForVersionCompatibility(xcodeWorkspace);
    List<CodeLocation> codeLocations = new LinkedList<>();
    List<FailedDetectableResult> failedDetectableResults = new LinkedList<>();
    for (XcodeFileReference fileReference : xcodeWorkspace.getFileReferences()) {
        File workspaceReferencedDirectory = workspaceDirectory.getParentFile().toPath().resolve(fileReference.getRelativeLocation()).toFile();
        if (!workspaceReferencedDirectory.exists()) {
            logger.warn("Failed to find subproject '{}' as defined in the workspace at '{}'", workspaceReferencedDirectory, workspaceDataFile.getParentFile().getAbsolutePath());
            continue;
        }
        switch(fileReference.getFileReferenceType()) {
            case DIRECTORY:
                PackageResolvedResult swiftProjectResult = extractStandalonePackageResolved(workspaceReferencedDirectory);
                swiftProjectResult.getFailedDetectableResult().ifPresent(failedDetectableResults::add);
                codeLocations.add(new CodeLocation(swiftProjectResult.getDependencyGraph(), workspaceReferencedDirectory));
                break;
            case XCODE_PROJECT:
                PackageResolvedResult xcodeProjectResult = extractFromXcodeProject(workspaceReferencedDirectory);
                xcodeProjectResult.getFailedDetectableResult().ifPresent(failedDetectableResults::add);
                codeLocations.add(new CodeLocation(xcodeProjectResult.getDependencyGraph(), workspaceReferencedDirectory));
                break;
            default:
                throw new UnsupportedOperationException(String.format("Unrecognized FileReferenceType: %s", fileReference.getFileReferenceType()));
        }
    }
    if (CollectionUtils.isNotEmpty(failedDetectableResults)) {
        return XcodeWorkspaceResult.failure(failedDetectableResults);
    }
    return XcodeWorkspaceResult.success(codeLocations);
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) FailedDetectableResult(com.synopsys.integration.detectable.detectable.result.FailedDetectableResult) XcodeFileReference(com.synopsys.integration.detectable.detectables.xcode.model.XcodeFileReference) PackageResolvedResult(com.synopsys.integration.detectable.detectables.swift.lock.model.PackageResolvedResult) XcodeWorkspace(com.synopsys.integration.detectable.detectables.xcode.model.XcodeWorkspace) File(java.io.File) LinkedList(java.util.LinkedList)

Example 3 with FailedDetectableResult

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

the class ApplicableEvaluatorTest method createEvaluationMocks.

private DetectorEvaluation createEvaluationMocks(DetectorEvaluationOptions evaluationOptions, DetectorEvaluationTree detectorEvaluationTree, boolean alreadyApplicable, boolean searchable) {
    DetectorEvaluation detectorEvaluation = Mockito.mock(DetectorEvaluation.class);
    List<DetectorEvaluation> detectorEvaluations = Collections.singletonList(detectorEvaluation);
    Mockito.when(detectorEvaluationTree.getOrderedEvaluations()).thenReturn(detectorEvaluations);
    DetectorRule detectorRule = Mockito.mock(DetectorRule.class);
    Mockito.when(detectorRule.getDescriptiveName()).thenReturn("test rule");
    Mockito.when(detectorEvaluation.getDetectorRule()).thenReturn(detectorRule);
    Mockito.when(detectorEvaluation.isApplicable()).thenReturn(alreadyApplicable);
    Mockito.when(detectorEvaluation.isSearchable()).thenReturn(searchable);
    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);
    Detectable detectable = Mockito.mock(Detectable.class);
    Mockito.when(detectorRule.createDetectable(Mockito.any(DetectableEnvironment.class))).thenReturn(detectable);
    Mockito.when(detectable.applicable()).thenReturn(new FailedDetectableResult());
    return detectorEvaluation;
}
Also used : Predicate(java.util.function.Predicate) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) 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) Detectable(com.synopsys.integration.detectable.Detectable) FailedDetectableResult(com.synopsys.integration.detectable.detectable.result.FailedDetectableResult) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collections(java.util.Collections) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) Detectable(com.synopsys.integration.detectable.Detectable) FailedDetectableResult(com.synopsys.integration.detectable.detectable.result.FailedDetectableResult) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment)

Aggregations

FailedDetectableResult (com.synopsys.integration.detectable.detectable.result.FailedDetectableResult)3 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)2 PackageResolvedResult (com.synopsys.integration.detectable.detectables.swift.lock.model.PackageResolvedResult)2 File (java.io.File)2 LinkedList (java.util.LinkedList)2 Detectable (com.synopsys.integration.detectable.Detectable)1 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)1 XcodeFileReference (com.synopsys.integration.detectable.detectables.xcode.model.XcodeFileReference)1 XcodeWorkspace (com.synopsys.integration.detectable.detectables.xcode.model.XcodeWorkspace)1 XcodeWorkspaceResult (com.synopsys.integration.detectable.detectables.xcode.model.XcodeWorkspaceResult)1 DetectorEvaluation (com.synopsys.integration.detector.base.DetectorEvaluation)1 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)1 DetectorRule (com.synopsys.integration.detector.rule.DetectorRule)1 Collections (java.util.Collections)1 List (java.util.List)1 Predicate (java.util.function.Predicate)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Test (org.junit.jupiter.api.Test)1 Mockito (org.mockito.Mockito)1