Search in sources :

Example 1 with ConanDetectableResult

use of com.synopsys.integration.detectable.detectables.conan.ConanDetectableResult in project synopsys-detect by blackducksoftware.

the class ConanLockfileExtractor method extract.

public Extraction extract(File lockfile) {
    try {
        String conanLockfileContents = FileUtils.readFileToString(lockfile, StandardCharsets.UTF_8);
        ConanDetectableResult result = conanLockfileParser.generateCodeLocationFromConanLockfileContents(conanLockfileContents);
        return new Extraction.Builder().success(result.getCodeLocation()).projectName(result.getProjectName()).projectVersion(result.getProjectVersion()).build();
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : ConanDetectableResult(com.synopsys.integration.detectable.detectables.conan.ConanDetectableResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction)

Example 2 with ConanDetectableResult

use of com.synopsys.integration.detectable.detectables.conan.ConanDetectableResult in project synopsys-detect by blackducksoftware.

the class ConanLockfileParserFunctionalTest method testRelativePath.

@Test
public void testRelativePath() throws IOException, IntegrationException {
    File lockfile = FunctionalTestFiles.asFile("/conan/lockfile/conan_relpath.lock");
    EnumListFilter<ConanDependencyType> dependencyTypeFilter = EnumListFilter.excludeNone();
    ConanLockfileParser parser = new ConanLockfileParser(new Gson(), new ConanCodeLocationGenerator(dependencyTypeFilter, true), new ExternalIdFactory());
    String conanLockfileContents = FileUtils.readFileToString(lockfile, StandardCharsets.UTF_8);
    ConanDetectableResult result = parser.generateCodeLocationFromConanLockfileContents(conanLockfileContents);
    assertEquals(1, result.getCodeLocation().getDependencyGraph().getRootDependencies().size());
}
Also used : ConanCodeLocationGenerator(com.synopsys.integration.detectable.detectables.conan.ConanCodeLocationGenerator) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ConanLockfileParser(com.synopsys.integration.detectable.detectables.conan.lockfile.parser.ConanLockfileParser) Gson(com.google.gson.Gson) ConanDetectableResult(com.synopsys.integration.detectable.detectables.conan.ConanDetectableResult) ConanDependencyType(com.synopsys.integration.detectable.detectables.conan.cli.config.ConanDependencyType) File(java.io.File) Test(org.junit.jupiter.api.Test) FunctionalTest(com.synopsys.integration.detectable.annotations.FunctionalTest)

Example 3 with ConanDetectableResult

use of com.synopsys.integration.detectable.detectables.conan.ConanDetectableResult in project synopsys-detect by blackducksoftware.

the class ConanCliExtractor method extract.

public Extraction extract(File projectDir, ExecutableTarget conanExe) {
    toolVersionLogger.log(projectDir, conanExe);
    ExecutableOutput conanInfoOutput;
    try {
        conanInfoOutput = conanCommandRunner.runConanInfoCommand(projectDir, conanExe);
    } catch (Exception e) {
        logger.error(String.format("Exception thrown executing conan info command: %s", e.getMessage()));
        return new Extraction.Builder().exception(e).build();
    }
    if (!conanCommandRunner.wasSuccess(conanInfoOutput)) {
        return new Extraction.Builder().failure("Conan info command reported errors").build();
    }
    if (!conanCommandRunner.producedOutput(conanInfoOutput)) {
        return new Extraction.Builder().failure("Conan info command produced no output").build();
    }
    try {
        ConanDetectableResult result = conanInfoParser.generateCodeLocationFromConanInfoOutput(conanInfoOutput.getStandardOutput());
        return new Extraction.Builder().success(result.getCodeLocation()).projectName(result.getProjectName()).projectVersion(result.getProjectVersion()).build();
    } catch (DetectableException e) {
        return new Extraction.Builder().failure(e.getMessage()).build();
    }
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) ConanDetectableResult(com.synopsys.integration.detectable.detectables.conan.ConanDetectableResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 4 with ConanDetectableResult

use of com.synopsys.integration.detectable.detectables.conan.ConanDetectableResult in project synopsys-detect by blackducksoftware.

the class ConanCliParserFunctionalTest method test.

@Test
public void test() throws IOException, IntegrationException {
    File conanInfoOutputFile = FunctionalTestFiles.asFile("/conan/cli/conan_info.txt");
    EnumListFilter<ConanDependencyType> dependencyTypeFilter = EnumListFilter.excludeNone();
    ConanCodeLocationGenerator conanCodeLocationGenerator = new ConanCodeLocationGenerator(dependencyTypeFilter, false);
    ConanInfoLineAnalyzer conanInfoLineAnalyzer = new ConanInfoLineAnalyzer();
    NodeElementParser nodeElementParser = new NodeElementParser(conanInfoLineAnalyzer);
    ConanInfoNodeParser conanInfoNodeParser = new ConanInfoNodeParser(conanInfoLineAnalyzer, nodeElementParser);
    ConanInfoParser parser = new ConanInfoParser(conanInfoNodeParser, conanCodeLocationGenerator, new ExternalIdFactory());
    String conanInfoOutput = FileUtils.readFileToString(conanInfoOutputFile, StandardCharsets.UTF_8);
    ConanDetectableResult result = parser.generateCodeLocationFromConanInfoOutput(conanInfoOutput);
    assertEquals(3, result.getCodeLocation().getDependencyGraph().getRootDependencies().size());
    DependencyGraph actualDependencyGraph = result.getCodeLocation().getDependencyGraph();
    GraphCompare.assertEqualsResource("/conan/cli/noProjectRef_graph.json", actualDependencyGraph);
}
Also used : ConanInfoParser(com.synopsys.integration.detectable.detectables.conan.cli.parser.ConanInfoParser) ConanCodeLocationGenerator(com.synopsys.integration.detectable.detectables.conan.ConanCodeLocationGenerator) NodeElementParser(com.synopsys.integration.detectable.detectables.conan.cli.parser.element.NodeElementParser) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ConanInfoLineAnalyzer(com.synopsys.integration.detectable.detectables.conan.cli.parser.ConanInfoLineAnalyzer) ConanInfoNodeParser(com.synopsys.integration.detectable.detectables.conan.cli.parser.ConanInfoNodeParser) ConanDetectableResult(com.synopsys.integration.detectable.detectables.conan.ConanDetectableResult) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) ConanDependencyType(com.synopsys.integration.detectable.detectables.conan.cli.config.ConanDependencyType) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 5 with ConanDetectableResult

use of com.synopsys.integration.detectable.detectables.conan.ConanDetectableResult in project synopsys-detect by blackducksoftware.

the class ConanLockfileParserFunctionalTest method testNoProjectRef.

@Test
public void testNoProjectRef() throws IOException, IntegrationException {
    File lockfile = FunctionalTestFiles.asFile("/conan/lockfile/conan.lock");
    EnumListFilter<ConanDependencyType> dependencyTypeFilter = EnumListFilter.excludeNone();
    ConanLockfileParser parser = new ConanLockfileParser(new Gson(), new ConanCodeLocationGenerator(dependencyTypeFilter, false), new ExternalIdFactory());
    String conanLockfileContents = FileUtils.readFileToString(lockfile, StandardCharsets.UTF_8);
    ConanDetectableResult result = parser.generateCodeLocationFromConanLockfileContents(conanLockfileContents);
    assertEquals(3, result.getCodeLocation().getDependencyGraph().getRootDependencies().size());
    DependencyGraph actualDependencyGraph = result.getCodeLocation().getDependencyGraph();
    GraphCompare.assertEqualsResource("/conan/lockfile/noProjectRef_graph.json", actualDependencyGraph);
}
Also used : ConanCodeLocationGenerator(com.synopsys.integration.detectable.detectables.conan.ConanCodeLocationGenerator) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ConanLockfileParser(com.synopsys.integration.detectable.detectables.conan.lockfile.parser.ConanLockfileParser) Gson(com.google.gson.Gson) ConanDetectableResult(com.synopsys.integration.detectable.detectables.conan.ConanDetectableResult) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) ConanDependencyType(com.synopsys.integration.detectable.detectables.conan.cli.config.ConanDependencyType) File(java.io.File) Test(org.junit.jupiter.api.Test) FunctionalTest(com.synopsys.integration.detectable.annotations.FunctionalTest)

Aggregations

ConanDetectableResult (com.synopsys.integration.detectable.detectables.conan.ConanDetectableResult)8 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)6 ConanCodeLocationGenerator (com.synopsys.integration.detectable.detectables.conan.ConanCodeLocationGenerator)6 ConanDependencyType (com.synopsys.integration.detectable.detectables.conan.cli.config.ConanDependencyType)6 File (java.io.File)6 Test (org.junit.jupiter.api.Test)6 Gson (com.google.gson.Gson)5 FunctionalTest (com.synopsys.integration.detectable.annotations.FunctionalTest)5 ConanLockfileParser (com.synopsys.integration.detectable.detectables.conan.lockfile.parser.ConanLockfileParser)5 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)4 Extraction (com.synopsys.integration.detectable.extraction.Extraction)2 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)1 ConanInfoLineAnalyzer (com.synopsys.integration.detectable.detectables.conan.cli.parser.ConanInfoLineAnalyzer)1 ConanInfoNodeParser (com.synopsys.integration.detectable.detectables.conan.cli.parser.ConanInfoNodeParser)1 ConanInfoParser (com.synopsys.integration.detectable.detectables.conan.cli.parser.ConanInfoParser)1 NodeElementParser (com.synopsys.integration.detectable.detectables.conan.cli.parser.element.NodeElementParser)1 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)1