Search in sources :

Example 21 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class NpmCliParser method convertNpmJsonFileToCodeLocation.

public NpmPackagerResult convertNpmJsonFileToCodeLocation(String npmLsOutput, PackageJson packageJson) {
    JsonObject npmJson = JsonParser.parseString(npmLsOutput).getAsJsonObject();
    DependencyGraph graph = new BasicDependencyGraph();
    JsonElement projectNameElement = npmJson.getAsJsonPrimitive(JSON_NAME);
    JsonElement projectVersionElement = npmJson.getAsJsonPrimitive(JSON_VERSION);
    String projectName = null;
    String projectVersion = null;
    if (projectNameElement != null) {
        projectName = projectNameElement.getAsString();
    }
    if (projectVersionElement != null) {
        projectVersion = projectVersionElement.getAsString();
    }
    populateChildren(graph, null, npmJson.getAsJsonObject(JSON_DEPENDENCIES), true, packageJson);
    ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, projectName, projectVersion);
    CodeLocation codeLocation = new CodeLocation(graph, externalId);
    return new NpmPackagerResult(projectName, projectVersion, codeLocation);
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) JsonElement(com.google.gson.JsonElement) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) JsonObject(com.google.gson.JsonObject) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) NpmPackagerResult(com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult)

Example 22 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation 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 23 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation 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 24 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class YarnTransformerTest method testExcludeDevDependencies.

// Not yet covered by these tests: yarn 1 workspaces' dev dependencies specified in workspace package.json
@Test
void testExcludeDevDependencies() throws MissingExternalIdException {
    YarnLockResult yarnLockResult = buildTestYarnLockResult(noWorkspaces, noWorkspaces, false);
    List<CodeLocation> codeLocations = createTransformer(YarnDependencyType.NON_PRODUCTION).generateCodeLocations(yarnLockResult, new ArrayList<>(0), ExcludedIncludedWildcardFilter.EMPTY);
    assertEquals(1, codeLocations.size());
    CodeLocation codeLocation = codeLocations.get(0);
    DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
    assertEquals(1, dependencyGraph.getRootDependencies().size());
    Set<Dependency> rootDeps = dependencyGraph.getRootDependencies();
    assertEquals("foo", rootDeps.iterator().next().getName());
    ExternalId fooExternalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, "foo", "1.0");
    assertTrue(dependencyGraph.hasDependency(fooExternalId));
    ExternalId yarnExternalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, "yarn", "1.22.5");
    assertTrue(dependencyGraph.hasDependency(yarnExternalId));
}
Also used : YarnLockResult(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockResult) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) YarnLockDependency(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 25 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class YarnTransformerTest method testIncludeDevDependencies.

@Test
void testIncludeDevDependencies() throws MissingExternalIdException {
    YarnLockResult yarnLockResult = buildTestYarnLockResult(noWorkspaces, noWorkspaces, false);
    List<CodeLocation> codeLocations = createTransformer().generateCodeLocations(yarnLockResult, new ArrayList<>(0), ExcludedIncludedWildcardFilter.EMPTY);
    assertEquals(1, codeLocations.size());
    CodeLocation codeLocation = codeLocations.get(0);
    DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
    assertEquals(2, dependencyGraph.getRootDependencies().size());
    ExternalId fooExternalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, "foo", "1.0");
    assertTrue(dependencyGraph.hasDependency(fooExternalId));
    assertTrue(dependencyGraph.getRootDependencies().stream().map(Dependency::getExternalId).anyMatch(fooExternalId::equals));
    ExternalId barExternalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, "bar", "1.0");
    assertTrue(dependencyGraph.hasDependency(barExternalId));
    assertTrue(dependencyGraph.getRootDependencies().stream().map(Dependency::getExternalId).anyMatch(barExternalId::equals));
    ExternalId yarnExternalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, "yarn", "1.22.5");
    assertTrue(dependencyGraph.hasDependency(yarnExternalId));
}
Also used : YarnLockResult(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockResult) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) YarnLockDependency(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Aggregations

CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)104 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)60 Extraction (com.synopsys.integration.detectable.extraction.Extraction)41 File (java.io.File)24 ArrayList (java.util.ArrayList)23 Test (org.junit.jupiter.api.Test)22 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)21 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)20 NameVersion (com.synopsys.integration.util.NameVersion)19 IOException (java.io.IOException)19 BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)16 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)16 List (java.util.List)14 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)13 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)11 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)10 Optional (java.util.Optional)10 Collectors (java.util.stream.Collectors)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10