use of com.synopsys.integration.bdio.graph.DependencyGraph in project hub-detect by blackducksoftware.
the class CodeLocationReporter method writeCodeLocationDetails.
private void writeCodeLocationDetails(final ReportWriter writer, final DetectCodeLocation codeLocation, final Integer dependencyCount, final String codeLocationName, final String extractionId) {
writer.writeSeperator();
writer.writeLine("Name : " + codeLocationName);
writer.writeLine("Directory : " + codeLocation.getSourcePath());
writer.writeLine("Extraction : " + extractionId);
writer.writeLine("Detect Code Location Type : " + codeLocation.getCodeLocationType());
final DependencyGraph graph = codeLocation.getDependencyGraph();
writer.writeLine("Root Dependencies : " + graph.getRootDependencies().size());
writer.writeLine("Total Dependencies : " + dependencyCount);
}
use of com.synopsys.integration.bdio.graph.DependencyGraph 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();
}
}
use of com.synopsys.integration.bdio.graph.DependencyGraph 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();
}
}
use of com.synopsys.integration.bdio.graph.DependencyGraph 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;
}
use of com.synopsys.integration.bdio.graph.DependencyGraph in project hub-detect by blackducksoftware.
the class DockerExtractor method findCodeLocations.
private Extraction.Builder findCodeLocations(final File directoryToSearch, final File directory, final String imageName) {
final File bdioFile = detectFileFinder.findFile(directoryToSearch, DEPENDENCIES_PATTERN);
if (bdioFile != null) {
SimpleBdioDocument simpleBdioDocument = null;
try (final InputStream dockerOutputInputStream = new FileInputStream(bdioFile);
BdioReader bdioReader = new BdioReader(gson, dockerOutputInputStream)) {
simpleBdioDocument = bdioReader.readSimpleBdioDocument();
} catch (final Exception e) {
return new Extraction.Builder().exception(e);
}
if (simpleBdioDocument != null) {
final DependencyGraph dependencyGraph = bdioTransformer.transformToDependencyGraph(simpleBdioDocument.project, simpleBdioDocument.components);
final String projectName = simpleBdioDocument.project.name;
final String projectVersionName = simpleBdioDocument.project.version;
final Forge dockerForge = new Forge(ExternalId.BDIO_ID_SEPARATOR, ExternalId.BDIO_ID_SEPARATOR, simpleBdioDocument.project.bdioExternalIdentifier.forge);
final String externalIdPath = simpleBdioDocument.project.bdioExternalIdentifier.externalId;
final ExternalId projectExternalId = externalIdFactory.createPathExternalId(dockerForge, externalIdPath);
final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.DOCKER, directory.toString(), projectExternalId, dependencyGraph).dockerImage(imageName).build();
return new Extraction.Builder().success(detectCodeLocation).projectName(projectName).projectVersion(projectVersionName);
}
}
return new Extraction.Builder().failure("No files found matching pattern [" + DEPENDENCIES_PATTERN + "]. Expected docker-inspector to produce file in " + directory.toString());
}
Aggregations