Search in sources :

Example 41 with DetectCodeLocation

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

the class SbtResolutionCacheExtractor method extract.

public Extraction extract(final File directory) {
    try {
        final String included = detectConfiguration.getProperty(DetectProperty.DETECT_SBT_INCLUDED_CONFIGURATIONS, PropertyAuthority.None);
        final String excluded = detectConfiguration.getProperty(DetectProperty.DETECT_SBT_EXCLUDED_CONFIGURATIONS, PropertyAuthority.None);
        final int depth = detectConfiguration.getIntegerProperty(DetectProperty.DETECT_SBT_REPORT_DEPTH, PropertyAuthority.None);
        final SbtPackager packager = new SbtPackager(externalIdFactory, detectFileFinder);
        final SbtProject project = packager.extractProject(directory.getAbsolutePath(), depth, included, excluded);
        final List<DetectCodeLocation> codeLocations = new ArrayList<>();
        String projectName = null;
        String projectVersion = null;
        for (final SbtDependencyModule module : project.modules) {
            final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.SBT, directory.toString(), project.projectExternalId, module.graph).build();
            if (projectName == null) {
                projectName = project.projectName;
                projectVersion = project.projectVersion;
            }
            codeLocations.add(codeLocation);
        }
        if (codeLocations.size() > 0) {
            return new Extraction.Builder().success(codeLocations).projectName(projectName).projectVersion(projectVersion).build();
        } else {
            logger.error("Unable to find any dependency information.");
            return new Extraction.Builder().failure("Unable to find any dependency information.").build();
        }
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : ArrayList(java.util.ArrayList) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)

Example 42 with DetectCodeLocation

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

the class YarnLockExtractor method extract.

public Extraction extract(final File directory, final File yarnlock, final String yarnExe) {
    try {
        final List<String> yarnLockText = Files.readAllLines(yarnlock.toPath(), StandardCharsets.UTF_8);
        final List<String> exeArgs = Stream.of("list", "--emoji", "false").collect(Collectors.toCollection(ArrayList::new));
        if (detectConfiguration.getBooleanProperty(DetectProperty.DETECT_YARN_PROD_ONLY, PropertyAuthority.None)) {
            exeArgs.add("--prod");
        }
        final Executable yarnListExe = new Executable(directory, yarnExe, exeArgs);
        final ExecutableOutput executableOutput = executableRunner.execute(yarnListExe);
        if (executableOutput.getReturnCode() != 0) {
            final Extraction.Builder builder = new Extraction.Builder().failure(String.format("Executing command '%s' returned a non-zero exit code %s", String.join(" ", exeArgs), executableOutput.getReturnCode()));
            return builder.build();
        }
        final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(yarnLockText, executableOutput.getStandardOutputAsList());
        final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.NPM, directory.getCanonicalPath());
        final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.YARN, directory.getCanonicalPath(), externalId, dependencyGraph).build();
        return new Extraction.Builder().success(detectCodeLocation).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) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable)

Example 43 with DetectCodeLocation

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

the class NugetInspectorPackager method createDetectCodeLocation.

public NugetParseResult createDetectCodeLocation(final File dependencyNodeFile) throws IOException {
    final String text = FileUtils.readFileToString(dependencyNodeFile, StandardCharsets.UTF_8);
    final NugetInspection nugetInspection = gson.fromJson(text, NugetInspection.class);
    final List<DetectCodeLocation> codeLocations = new ArrayList<>();
    String projectName = "";
    String projectVersion = "";
    for (final NugetContainer it : nugetInspection.containers) {
        final Optional<NugetParseResult> possibleParseResult = createDetectCodeLocationFromNugetContainer(it);
        if (possibleParseResult.isPresent()) {
            final NugetParseResult result = possibleParseResult.get();
            if (StringUtils.isNotBlank(result.projectName)) {
                projectName = result.projectName;
                projectVersion = result.projectVersion;
            }
            codeLocations.addAll(result.codeLocations);
        }
    }
    return new NugetParseResult(projectName, projectVersion, codeLocations);
}
Also used : NugetInspection(com.blackducksoftware.integration.hub.detect.detector.nuget.model.NugetInspection) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) NugetContainer(com.blackducksoftware.integration.hub.detect.detector.nuget.model.NugetContainer) ArrayList(java.util.ArrayList)

Example 44 with DetectCodeLocation

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

the class GemlockExtractor method extract.

public Extraction extract(final File directory, final File gemlock) {
    try {
        final List<String> gemlockText = Files.readAllLines(gemlock.toPath(), StandardCharsets.UTF_8);
        logger.debug(gemlockText.stream().collect(Collectors.joining("\n")));
        final GemlockParser gemlockParser = new GemlockParser(externalIdFactory);
        final DependencyGraph dependencyGraph = gemlockParser.parseProjectDependencies(gemlockText);
        final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.RUBYGEMS, directory.toString());
        final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.RUBYGEMS, directory.toString(), externalId, dependencyGraph).build();
        return new Extraction.Builder().success(codeLocation).build();
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)

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