Search in sources :

Example 1 with PackageDependency

use of com.synopsys.integration.detectable.detectables.pear.model.PackageDependency in project synopsys-detect by blackducksoftware.

the class PearPackageDependenciesParser method parse.

public List<PackageDependency> parse(List<String> packageDependenciesLines) throws IntegrationException {
    List<PackageDependency> packageDependencies = new ArrayList<>();
    boolean started = false;
    for (String rawLine : packageDependenciesLines) {
        String line = rawLine.trim();
        if (!started) {
            started = line.startsWith(START_TOKEN);
            continue;
        } else if (StringUtils.isBlank(line) || line.startsWith("Required") || line.startsWith("REQUIRED")) {
            continue;
        }
        String[] entry = line.split(" +");
        if (entry.length < 3) {
            throw new IntegrationException("Unable to parse package-dependencies");
        }
        boolean required = BooleanUtils.toBoolean(entry[0]);
        String type = entry[1].trim();
        String[] namePieces = entry[2].split("/");
        String name = namePieces[namePieces.length - 1].trim();
        if ("Package".equalsIgnoreCase(type)) {
            PackageDependency packageDependency = new PackageDependency(name, required);
            packageDependencies.add(packageDependency);
        }
    }
    return packageDependencies;
}
Also used : PackageDependency(com.synopsys.integration.detectable.detectables.pear.model.PackageDependency) IntegrationException(com.synopsys.integration.exception.IntegrationException) ArrayList(java.util.ArrayList)

Example 2 with PackageDependency

use of com.synopsys.integration.detectable.detectables.pear.model.PackageDependency in project synopsys-detect by blackducksoftware.

the class PearDependencyGraphTransformerTest method buildDependencyGraph.

private DependencyGraph buildDependencyGraph(PearDependencyType... excludedTypes) {
    ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    PearDependencyGraphTransformer pearDependencyGraphTransformer = new PearDependencyGraphTransformer(externalIdFactory, EnumListFilter.fromExcluded(excludedTypes));
    Map<String, String> nameVersionMap = new HashMap<>();
    nameVersionMap.put("Archive_Tar", "1.4.3");
    nameVersionMap.put("Console_Getopt", "1.4.1");
    List<PackageDependency> packageDependencies = new ArrayList<>();
    packageDependencies.add(new PackageDependency("Archive_Tar", true));
    packageDependencies.add(new PackageDependency("Console_Getopt", false));
    return pearDependencyGraphTransformer.buildDependencyGraph(nameVersionMap, packageDependencies);
}
Also used : PackageDependency(com.synopsys.integration.detectable.detectables.pear.model.PackageDependency) HashMap(java.util.HashMap) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ArrayList(java.util.ArrayList) PearDependencyGraphTransformer(com.synopsys.integration.detectable.detectables.pear.transform.PearDependencyGraphTransformer)

Example 3 with PackageDependency

use of com.synopsys.integration.detectable.detectables.pear.model.PackageDependency in project synopsys-detect by blackducksoftware.

the class PearCliExtractor method extract.

public Extraction extract(ExecutableTarget pearExe, File packageXmlFile, File workingDirectory) {
    try {
        ExecutableOutput pearListOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, pearExe, "list"));
        ExecutableOutput packageDependenciesOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, pearExe, "package-dependencies", PACKAGE_XML_FILENAME));
        assertValidExecutableOutput(pearListOutput, packageDependenciesOutput);
        Map<String, String> dependencyNameVersionMap = pearListParser.parse(pearListOutput.getStandardOutputAsList());
        List<PackageDependency> packageDependencies = pearPackageDependenciesParser.parse(packageDependenciesOutput.getStandardOutputAsList());
        DependencyGraph dependencyGraph = pearDependencyGraphTransformer.buildDependencyGraph(dependencyNameVersionMap, packageDependencies);
        try (InputStream packageXmlInputStream = new FileInputStream(packageXmlFile)) {
            NameVersion projectNameVersion = pearPackageXmlParser.parse(packageXmlInputStream);
            ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.PEAR, projectNameVersion.getName(), projectNameVersion.getVersion());
            CodeLocation detectCodeLocation = new CodeLocation(dependencyGraph, externalId);
            return new Extraction.Builder().success(detectCodeLocation).projectName(projectNameVersion.getName()).projectVersion(projectNameVersion.getVersion()).build();
        }
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) FileInputStream(java.io.FileInputStream) IntegrationException(com.synopsys.integration.exception.IntegrationException) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) PackageDependency(com.synopsys.integration.detectable.detectables.pear.model.PackageDependency) Extraction(com.synopsys.integration.detectable.extraction.Extraction)

Example 4 with PackageDependency

use of com.synopsys.integration.detectable.detectables.pear.model.PackageDependency in project synopsys-detect by blackducksoftware.

the class PearDependencyGraphTransformer method buildDependencyGraph.

public DependencyGraph buildDependencyGraph(Map<String, String> dependencyNameVersionMap, List<PackageDependency> packageDependencies) {
    List<Dependency> dependencies = packageDependencies.stream().filter(this::filterDependencyType).map(PackageDependency::getName).map(dependencyName -> {
        String dependencyVersion = dependencyNameVersionMap.get(dependencyName);
        ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.PEAR, dependencyName, dependencyVersion);
        return new Dependency(dependencyName, dependencyVersion, externalId);
    }).collect(Collectors.toList());
    DependencyGraph mutableDependencyGraph = new BasicDependencyGraph();
    mutableDependencyGraph.addChildrenToRoot(dependencies);
    return mutableDependencyGraph;
}
Also used : PearDependencyType(com.synopsys.integration.detectable.detectables.pear.PearDependencyType) List(java.util.List) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Forge(com.synopsys.integration.bdio.model.Forge) EnumListFilter(com.synopsys.integration.detectable.detectable.util.EnumListFilter) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) Map(java.util.Map) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) PackageDependency(com.synopsys.integration.detectable.detectables.pear.model.PackageDependency) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) Collectors(java.util.stream.Collectors) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) PackageDependency(com.synopsys.integration.detectable.detectables.pear.model.PackageDependency) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) PackageDependency(com.synopsys.integration.detectable.detectables.pear.model.PackageDependency) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph)

Example 5 with PackageDependency

use of com.synopsys.integration.detectable.detectables.pear.model.PackageDependency in project synopsys-detect by blackducksoftware.

the class PearRequiredOnlyTest method TestParse.

@Test
public void TestParse() throws IntegrationException {
    List<String> pearList = Arrays.asList("Installed packages, channel pear.php.net:", "=========================================", "Package           Version State", "Archive_Tar       1.4.3   stable", "Auth_SASL         1.1.0   stable", "Config            1.10.12 stable", "Console_Getopt    1.4.1   stable", "HTML_Template_IT  1.3.0   stable", "MIME_Type         1.4.1   stable", "Net_SMTP          1.8.0   stable", "Net_Socket        1.2.2   stable", "PEAR              1.10.5  stable", "PEAR_Frontend_Gtk 0.4.0   beta", "PEAR_Frontend_Web 0.7.5   beta", "Structures_Graph  1.1.1   stable", "XML_Util          1.4.2   stable");
    List<String> pearPackageDependencies = Arrays.asList("Dependencies for Net_SMTP", "=========================", "Required? Type           Name            Versioning           Group", "Yes       Php                             (version >= 5.4.0)", "Yes       Pear Installer                  (version >= 1.10.1)", "Yes       Package        pear/Net_Socket  (version >= 1.0.7)", "No        Package        pear/Auth_SASL   (version >= 1.0.5)");
    ExternalIdFactory factory = new ExternalIdFactory();
    Map<String, String> dependencyNameVersionMap = new PearListParser().parse(pearList);
    List<PackageDependency> packageDependencies = new PearPackageDependenciesParser().parse(pearPackageDependencies);
    DependencyGraph dependencyGraph = new PearDependencyGraphTransformer(factory, EnumListFilter.excludeNone()).buildDependencyGraph(dependencyNameVersionMap, packageDependencies);
    Assertions.assertTrue(dependencyGraph.hasDependency(factory.createNameVersionExternalId(Forge.PEAR, "Auth_SASL", "1.1.0")), "Must have Auth_SASL even though it was not a required dependency.");
}
Also used : PearListParser(com.synopsys.integration.detectable.detectables.pear.parse.PearListParser) PackageDependency(com.synopsys.integration.detectable.detectables.pear.model.PackageDependency) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) PearDependencyGraphTransformer(com.synopsys.integration.detectable.detectables.pear.transform.PearDependencyGraphTransformer) PearPackageDependenciesParser(com.synopsys.integration.detectable.detectables.pear.parse.PearPackageDependenciesParser) Test(org.junit.jupiter.api.Test)

Aggregations

PackageDependency (com.synopsys.integration.detectable.detectables.pear.model.PackageDependency)5 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)3 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)3 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)2 PearDependencyGraphTransformer (com.synopsys.integration.detectable.detectables.pear.transform.PearDependencyGraphTransformer)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 ArrayList (java.util.ArrayList)2 BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)1 Forge (com.synopsys.integration.bdio.model.Forge)1 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 EnumListFilter (com.synopsys.integration.detectable.detectable.util.EnumListFilter)1 PearDependencyType (com.synopsys.integration.detectable.detectables.pear.PearDependencyType)1 PearListParser (com.synopsys.integration.detectable.detectables.pear.parse.PearListParser)1 PearPackageDependenciesParser (com.synopsys.integration.detectable.detectables.pear.parse.PearPackageDependenciesParser)1 Extraction (com.synopsys.integration.detectable.extraction.Extraction)1 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)1 NameVersion (com.synopsys.integration.util.NameVersion)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1