Search in sources :

Example 21 with Extraction

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

the class GoDepExtractor method extract.

public Extraction extract(final File directory, final File goExe, final String goDepInspector) {
    try {
        DependencyGraph graph = depPackager.makeDependencyGraph(directory.toString(), goDepInspector);
        if (graph == null) {
            graph = new MutableMapDependencyGraph();
        }
        final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.GOLANG, directory.toString());
        final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.GO_DEP, directory.toString(), externalId, graph).build();
        return new Extraction.Builder().success(detectCodeLocation).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) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)

Example 22 with Extraction

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

the class GoVendorExtractor method extract.

public Extraction extract(final File directory, final File vendorJsonFile) {
    try {
        final GoVendorJsonParser vendorJsonParser = new GoVendorJsonParser(externalIdFactory);
        final String vendorJsonContents = FileUtils.readFileToString(vendorJsonFile, StandardCharsets.UTF_8);
        logger.debug(vendorJsonContents);
        final DependencyGraph dependencyGraph = vendorJsonParser.parseVendorJson(gson, vendorJsonContents);
        final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.GOLANG, directory.toString());
        final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.GO_VENDOR, 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)

Example 23 with Extraction

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

the class BitbakeExtractor method extract.

public Extraction extract(final ExtractionId extractionId, final File buildEnvScript, final File sourcePath, String[] packageNames, File bash) {
    final File outputDirectory = directoryManager.getExtractionOutputDirectory(extractionId);
    final File bitbakeBuildDirectory = new File(outputDirectory, "build");
    final List<DetectCodeLocation> detectCodeLocations = new ArrayList<>();
    for (final String packageName : packageNames) {
        final File dependsFile = executeBitbakeForRecipeDependsFile(outputDirectory, bitbakeBuildDirectory, buildEnvScript, packageName, bash);
        final String targetArchitecture = executeBitbakeForTargetArchitecture(outputDirectory, buildEnvScript, packageName, bash);
        try {
            if (dependsFile == null) {
                throw new IntegrationException(String.format("Failed to find %s. This may be due to this project being a version of The Yocto Project earlier than 2.3 (Pyro) which is the minimum version for Detect", RECIPE_DEPENDS_FILE_NAME));
            }
            if (StringUtils.isBlank(targetArchitecture)) {
                throw new IntegrationException("Failed to find a target architecture");
            }
            logger.debug(FileUtils.readFileToString(dependsFile, Charset.defaultCharset()));
            final InputStream recipeDependsInputStream = FileUtils.openInputStream(dependsFile);
            final GraphParser graphParser = new GraphParser(recipeDependsInputStream);
            final DependencyGraph dependencyGraph = graphParserTransformer.transform(graphParser, targetArchitecture);
            final ExternalId externalId = new ExternalId(Forge.YOCTO);
            final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.BITBAKE, sourcePath.getCanonicalPath(), externalId, dependencyGraph).build();
            detectCodeLocations.add(detectCodeLocation);
        } catch (final IOException | IntegrationException | NullPointerException e) {
            logger.error(String.format("Failed to extract a Code Location while running Bitbake against package '%s'", packageName));
            logger.debug(e.getMessage(), e);
        }
    }
    final Extraction extraction;
    if (detectCodeLocations.isEmpty()) {
        extraction = new Extraction.Builder().failure("No Code Locations were generated during extraction").build();
    } else {
        extraction = new Extraction.Builder().success(detectCodeLocations).build();
    }
    return extraction;
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) InputStream(java.io.InputStream) GraphParser(com.paypal.digraph.parser.GraphParser) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) IOException(java.io.IOException) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) File(java.io.File)

Example 24 with Extraction

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

the class GradleExtractionDebugger method debug.

public void debug(LoggedDetectExtraction extraction, DetectRunInfo detectRunInfo, DetectConfiguration detectConfiguration) throws ExecutableRunnerException {
    String id = extraction.extractionIdentifier;
    ExecutableRunner executableRunner = Mockito.mock(ExecutableRunner.class);
    Mockito.when(executableRunner.execute(Mockito.any())).thenReturn(new ExecutableOutput("", ""));
    DetectFileFinder detectFileFinder = new DetectFileFinder();
    File mockSourceFile = Mockito.mock(File.class);
    File outputDirectory = new File(detectRunInfo.getExtractionsFolder(), extraction.extractionIdentifier);
    GradleInspectorExtractor gradleInspectorExtractor = new GradleInspectorExtractor(executableRunner, detectFileFinder, new GradleReportParser(new ExternalIdFactory()), detectConfiguration);
    Extraction extractionResult = gradleInspectorExtractor.extract(mockSourceFile, "", "", outputDirectory);
}
Also used : GradleInspectorExtractor(com.blackducksoftware.integration.hub.detect.detector.gradle.GradleInspectorExtractor) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) GradleReportParser(com.blackducksoftware.integration.hub.detect.detector.gradle.GradleReportParser) ExternalIdFactory(com.synopsys.integration.hub.bdio.model.externalid.ExternalIdFactory) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) LoggedDetectExtraction(com.synopsys.detect.doctor.logparser.LoggedDetectExtraction) File(java.io.File) ExecutableRunner(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)

Example 25 with Extraction

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

the class DockerExtractor method extract.

public Extraction extract(final File directory, final File outputDirectory, final File bashExe, final File javaExe, final String image, final String tar, final DockerInspectorInfo dockerInspectorInfo) {
    try {
        String imageArgument = null;
        String imagePiece = null;
        if (StringUtils.isNotBlank(tar)) {
            final File dockerTarFile = new File(tar);
            imageArgument = String.format("--docker.tar=%s", dockerTarFile.getCanonicalPath());
            imagePiece = detectFileFinder.extractFinalPieceFromPath(dockerTarFile.getCanonicalPath());
        } else if (StringUtils.isNotBlank(image)) {
            imagePiece = image;
            imageArgument = String.format("--docker.image=%s", image);
        }
        if (StringUtils.isBlank(imageArgument) || StringUtils.isBlank(imagePiece)) {
            return new Extraction.Builder().failure("No docker image found.").build();
        } else {
            return executeDocker(outputDirectory, imageArgument, imagePiece, tar, directory, javaExe, bashExe, dockerInspectorInfo);
        }
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) File(java.io.File) IOException(java.io.IOException) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

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