Search in sources :

Example 26 with Extraction

use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction 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 27 with Extraction

use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction 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 28 with Extraction

use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction in project hub-detect by blackducksoftware.

the class ToolRunner method run.

public void run(final RunResult runResult) throws DetectorException {
    logger.info(String.format("Checking if %s applies.", toolDetector.getToolEnum().toString()));
    DetectorResult applicableResult = toolDetector.applicable();
    if (applicableResult.getPassed()) {
        logger.info(String.format("Checking if %s is extractable.", toolDetector.getToolEnum().toString()));
        DetectorResult extractableResult = toolDetector.extractable();
        if (extractableResult.getPassed()) {
            logger.info(String.format("Performing the %s extraction.", toolDetector.getToolEnum().toString()));
            Extraction extractionResults = toolDetector.extract();
            if (extractionResults.result != Extraction.ExtractionResultType.SUCCESS) {
                logger.error(String.format("%s extraction failed: %s", toolDetector.getToolEnum().toString(), extractionResults.description));
            }
            publishExtractionResults(eventSystem, runResult, extractionResults);
        } else {
            publishNotExtractableResults(eventSystem, extractableResult, toolDetector.getToolEnum().toString());
        }
    } else {
        logger.info(String.format("%s was not applicable, will not actually run %s tool.", toolDetector.getToolEnum().toString(), toolDetector.getToolEnum().toString()));
        logger.info(applicableResult.toDescription());
    }
}
Also used : DetectorResult(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorResult) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)

Example 29 with Extraction

use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction 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

Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)29 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)17 File (java.io.File)17 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)14 ArrayList (java.util.ArrayList)12 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)11 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)11 Executable (com.blackducksoftware.integration.hub.detect.util.executable.Executable)8 DetectFileFinder (com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder)7 ExecutableRunner (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)6 ExtractionId (com.blackducksoftware.integration.hub.detect.detector.ExtractionId)5 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)5 IOException (java.io.IOException)4 DetectConfiguration (com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration)3 DetectProperty (com.blackducksoftware.integration.hub.detect.configuration.DetectProperty)3 PropertyAuthority (com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority)3 ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)3 DirectoryManager (com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3