Search in sources :

Example 1 with PackageResolvedResult

use of com.synopsys.integration.detectable.detectables.swift.lock.model.PackageResolvedResult 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 PackageResolvedResult

use of com.synopsys.integration.detectable.detectables.swift.lock.model.PackageResolvedResult 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)

Aggregations

CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)2 FailedDetectableResult (com.synopsys.integration.detectable.detectable.result.FailedDetectableResult)2 PackageResolvedResult (com.synopsys.integration.detectable.detectables.swift.lock.model.PackageResolvedResult)2 LinkedList (java.util.LinkedList)2 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 File (java.io.File)1