Search in sources :

Example 1 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class PearCliExtractor method extract.

public Extraction extract(final File directory, final File pearExe, final ExtractionId extractionId) {
    try {
        File workingDirectory = directoryManager.getExtractionOutputDirectory(extractionId);
        final ExecutableOutput pearListing = executableRunner.execute(workingDirectory, pearExe, "list");
        final ExecutableOutput pearDependencies = executableRunner.execute(workingDirectory, pearExe, "package-dependencies", PACKAGE_XML_FILENAME);
        // TODO: Why is this done here?
        final File packageFile = detectFileFinder.findFile(directory, PACKAGE_XML_FILENAME);
        final PearParseResult result = pearParser.parse(packageFile, pearListing, pearDependencies);
        final ExternalId id = externalIdFactory.createNameVersionExternalId(Forge.PEAR, result.name, result.version);
        final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PEAR, directory.toString(), id, result.dependencyGraph).build();
        return new Extraction.Builder().success(detectCodeLocation).projectName(result.name).projectVersion(result.version).build();
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) File(java.io.File)

Example 2 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class PipenvGraphParser method parse.

public PipParseResult parse(final String projectName, final String projectVersionName, final List<String> pipFreezeOutput, final List<String> pipenvGraphOutput, final String sourcePath) {
    final MutableMapDependencyGraph dependencyGraph = new MutableMapDependencyGraph();
    final Stack<Dependency> dependencyStack = new Stack<>();
    final Map<String, String[]> pipFreezeMap = pipFreezeOutput.stream().map(line -> line.split(TOP_LEVEL_SEPARATOR)).filter(splitLine -> splitLine.length == 2).collect(Collectors.toMap(splitLine -> splitLine[0].trim().toLowerCase(), splitLine -> splitLine));
    int lastLevel = -1;
    for (final String line : pipenvGraphOutput) {
        final int currentLevel = getLevel(line);
        final Optional<Dependency> parsedDependency = getDependencyFromLine(pipFreezeMap, line);
        if (!parsedDependency.isPresent()) {
            continue;
        }
        final Dependency dependency = parsedDependency.get();
        if (currentLevel == lastLevel) {
            dependencyStack.pop();
        } else {
            for (; lastLevel >= currentLevel; lastLevel--) {
                dependencyStack.pop();
            }
        }
        if (dependencyStack.size() > 0) {
            dependencyGraph.addChildWithParent(dependency, dependencyStack.peek());
        } else {
            dependencyGraph.addChildrenToRoot(dependency);
        }
        lastLevel = currentLevel;
        dependencyStack.push(dependency);
    }
    if (!dependencyGraph.getRootDependencyExternalIds().isEmpty()) {
        final ExternalId projectExternalId = externalIdFactory.createNameVersionExternalId(Forge.PYPI, projectName, projectVersionName);
        final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PIP, sourcePath, projectExternalId, dependencyGraph).build();
        return new PipParseResult(projectName, projectVersionName, codeLocation);
    } else {
        return null;
    }
}
Also used : Logger(org.slf4j.Logger) Forge(com.synopsys.integration.bdio.model.Forge) LoggerFactory(org.slf4j.LoggerFactory) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) Stack(java.util.Stack) List(java.util.List) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) Map(java.util.Map) DetectCodeLocationType(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocationType) Optional(java.util.Optional) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) Stack(java.util.Stack) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)

Example 3 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class PipInspectorTreeParser method parse.

public Optional<PipParseResult> parse(final List<String> pipInspectorOutputAsList, final String sourcePath) {
    PipParseResult parseResult = null;
    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    final DependencyHistory history = new DependencyHistory();
    Dependency project = null;
    for (final String line : pipInspectorOutputAsList) {
        final String trimmedLine = StringUtils.trimToEmpty(line);
        if (StringUtils.isEmpty(trimmedLine) || !trimmedLine.contains(SEPARATOR) || trimmedLine.startsWith(UNKNOWN_REQUIREMENTS_PREFIX) || trimmedLine.startsWith(UNPARSEABLE_REQUIREMENTS_PREFIX) || trimmedLine.startsWith(UNKNOWN_PACKAGE_PREFIX)) {
            parseErrorsFromLine(trimmedLine);
            continue;
        }
        final Dependency currentDependency = parseDependencyFromLine(trimmedLine, sourcePath);
        final int lineLevel = getLineLevel(trimmedLine);
        try {
            history.clearDependenciesDeeperThan(lineLevel);
        } catch (final IllegalStateException e) {
            logger.warn(String.format("Problem parsing line '%s': %s", line, e.getMessage()));
        }
        if (project == null) {
            project = currentDependency;
        } else if (project.equals(history.getLastDependency())) {
            graph.addChildToRoot(currentDependency);
        } else if (history.isEmpty()) {
            graph.addChildToRoot(currentDependency);
        } else {
            graph.addChildWithParents(currentDependency, history.getLastDependency());
        }
        history.add(currentDependency);
    }
    if (project != null) {
        final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PIP, sourcePath, project.externalId, graph).build();
        parseResult = new PipParseResult(project.name, project.version, codeLocation);
    }
    return Optional.ofNullable(parseResult);
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) DependencyHistory(com.blackducksoftware.integration.hub.detect.util.DependencyHistory) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 4 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class NugetInspectorPackager method createDetectCodeLocationFromNugetContainer.

private Optional<NugetParseResult> createDetectCodeLocationFromNugetContainer(final NugetContainer nugetContainer) {
    final NugetParseResult parseResult;
    String projectName = "";
    String projectVersionName = "";
    if (NugetContainerType.SOLUTION == nugetContainer.type) {
        projectName = nugetContainer.name;
        projectVersionName = nugetContainer.version;
        final List<DetectCodeLocation> codeLocations = new ArrayList<>();
        for (final NugetContainer container : nugetContainer.children) {
            final NugetDependencyNodeBuilder builder = new NugetDependencyNodeBuilder(externalIdFactory);
            builder.addPackageSets(container.packages);
            final DependencyGraph children = builder.createDependencyGraph(container.dependencies);
            final String sourcePath = container.sourcePath;
            if (StringUtils.isBlank(projectVersionName)) {
                projectVersionName = container.version;
            }
            final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.NUGET, sourcePath, externalIdFactory.createNameVersionExternalId(Forge.NUGET, projectName, projectVersionName), children).build();
            codeLocations.add(codeLocation);
        }
        parseResult = new NugetParseResult(projectName, projectVersionName, codeLocations);
    } else if (NugetContainerType.PROJECT == nugetContainer.type) {
        projectName = nugetContainer.name;
        projectVersionName = nugetContainer.version;
        final String sourcePath = nugetContainer.sourcePath;
        final NugetDependencyNodeBuilder builder = new NugetDependencyNodeBuilder(externalIdFactory);
        builder.addPackageSets(nugetContainer.packages);
        final DependencyGraph children = builder.createDependencyGraph(nugetContainer.dependencies);
        final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.NUGET, sourcePath, externalIdFactory.createNameVersionExternalId(Forge.NUGET, projectName, projectVersionName), children).build();
        parseResult = new NugetParseResult(projectName, projectVersionName, codeLocation);
    } else {
        parseResult = null;
    }
    return Optional.ofNullable(parseResult);
}
Also used : DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) NugetContainer(com.blackducksoftware.integration.hub.detect.detector.nuget.model.NugetContainer) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph)

Example 5 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class BazelCodeLocationBuilder method build.

public List<DetectCodeLocation> build() {
    Forge forge = new Forge("/", "/", "DETECT");
    final ExternalId externalId = externalIdFactory.createPathExternalId(forge, workspaceDir.toString());
    final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.BAZEL, workspaceDir.toString(), externalId, dependencyGraph).build();
    List<DetectCodeLocation> codeLocations = new ArrayList<>(1);
    codeLocations.add(codeLocation);
    return codeLocations;
}
Also used : DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) Forge(com.synopsys.integration.bdio.model.Forge)

Aggregations

DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)44 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)22 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)18 File (java.io.File)17 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)15 ArrayList (java.util.ArrayList)10 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)9 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)9 MutableDependencyGraph (com.synopsys.integration.bdio.graph.MutableDependencyGraph)8 MutableMapDependencyGraph (com.synopsys.integration.bdio.graph.MutableMapDependencyGraph)8 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)7 Test (org.junit.Test)7 Executable (com.blackducksoftware.integration.hub.detect.util.executable.Executable)5 List (java.util.List)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4