use of com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation in project synopsys-detect by blackducksoftware.
the class FullAggregateGraphCreator method aggregateCodeLocations.
public DependencyGraph aggregateCodeLocations(ProjectNodeCreator projectDependencyCreator, File sourcePath, List<DetectCodeLocation> codeLocations) throws DetectUserFriendlyException {
MutableDependencyGraph aggregateDependencyGraph = simpleBdioFactory.createMutableDependencyGraph();
for (DetectCodeLocation detectCodeLocation : codeLocations) {
Dependency codeLocationDependency = createAggregateNode(projectDependencyCreator, sourcePath, detectCodeLocation);
aggregateDependencyGraph.addChildrenToRoot(codeLocationDependency);
aggregateDependencyGraph.addGraphAsChildrenToParent(codeLocationDependency, detectCodeLocation.getDependencyGraph());
}
return aggregateDependencyGraph;
}
use of com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation in project synopsys-detect by blackducksoftware.
the class UniversalStepRunner method generateAggregateBdio.
private BdioResult generateAggregateBdio(AggregateDecision aggregateDecision, UniversalToolsResult universalToolsResult, NameVersion projectNameVersion, String aggregateName) throws OperationException, DetectUserFriendlyException {
DependencyGraph aggregateDependencyGraph;
if (aggregateDecision.getAggregateMode() == AggregateMode.DIRECT) {
aggregateDependencyGraph = operationFactory.aggregateDirect(universalToolsResult.getDetectCodeLocations());
} else if (aggregateDecision.getAggregateMode() == AggregateMode.TRANSITIVE) {
aggregateDependencyGraph = operationFactory.aggregateTransitive(universalToolsResult.getDetectCodeLocations());
} else if (aggregateDecision.getAggregateMode() == AggregateMode.SUBPROJECT) {
aggregateDependencyGraph = operationFactory.aggregateSubProject(universalToolsResult.getDetectCodeLocations());
} else {
throw new DetectUserFriendlyException(String.format("The %s property was set to an unsupported aggregation mode, will not aggregate at this time.", DetectProperties.DETECT_BOM_AGGREGATE_REMEDIATION_MODE.getKey()), ExitCodeType.FAILURE_GENERAL_ERROR);
}
boolean isBdio2 = operationFactory.calculateBdioOptions().isBdio2Enabled();
String aggregateExtension = isBdio2 ? ".bdio" : ".jsonld";
AggregateCodeLocation aggregateCodeLocation = operationFactory.createAggregateCodeLocation(aggregateDependencyGraph, projectNameVersion, aggregateName, aggregateExtension);
if (isBdio2) {
operationFactory.createAggregateBdio2File(aggregateCodeLocation);
} else {
operationFactory.createAggregateBdio1File(aggregateCodeLocation);
}
List<UploadTarget> uploadTargets = new ArrayList<>();
Map<DetectCodeLocation, String> codeLocationNamesResult = new HashMap<>();
universalToolsResult.getDetectCodeLocations().forEach(cl -> codeLocationNamesResult.put(cl, aggregateCodeLocation.getCodeLocationName()));
// TODO: This doesn't seem right, it should just be the aggregate CL name right?
if (aggregateCodeLocation.getAggregateDependencyGraph().getRootDependencies().size() > 0 || aggregateDecision.shouldUploadEmptyAggregate()) {
uploadTargets.add(UploadTarget.createDefault(projectNameVersion, aggregateCodeLocation.getCodeLocationName(), aggregateCodeLocation.getAggregateFile()));
} else {
logger.warn("The aggregate contained no dependencies, will not upload aggregate at this time.");
}
return new BdioResult(uploadTargets, new DetectCodeLocationNamesResult(codeLocationNamesResult), isBdio2);
}
use of com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation in project synopsys-detect by blackducksoftware.
the class CodeLocationConverter method toDetectCodeLocation.
public Map<CodeLocation, DetectCodeLocation> toDetectCodeLocation(File detectSourcePath, Extraction extraction, File overridePath, String overrideName) {
Map<CodeLocation, DetectCodeLocation> detectCodeLocations = new HashMap<>();
for (CodeLocation codeLocation : extraction.getCodeLocations()) {
File sourcePath = codeLocation.getSourcePath().orElse(overridePath);
ExternalId externalId;
if (!codeLocation.getExternalId().isPresent()) {
logger.debug("The detector was unable to determine an external id for this code location, so an external id will be created using the file path.");
String relativePath = FileNameUtils.relativize(detectSourcePath.getAbsolutePath(), sourcePath.getAbsolutePath());
if (StringUtils.isNotBlank(relativePath)) {
externalId = externalIdFactory.createPathExternalId(DETECT_FORGE, relativePath);
} else {
// Relativize from the parent.
externalId = externalIdFactory.createPathExternalId(DETECT_FORGE, FileNameUtils.relativizeParent(detectSourcePath.getAbsolutePath(), sourcePath.getAbsolutePath()));
}
logger.debug("The external id that was created is: {}", Arrays.asList(externalId.getExternalIdPieces()));
} else {
externalId = codeLocation.getExternalId().get();
}
Optional<String> dockerImageName = extraction.getMetaData(DockerExtractor.DOCKER_IMAGE_NAME_META_DATA);
DetectCodeLocation detectCodeLocation = dockerImageName.map(s -> DetectCodeLocation.forDocker(codeLocation.getDependencyGraph(), sourcePath, externalId, s)).orElseGet(() -> DetectCodeLocation.forCreator(codeLocation.getDependencyGraph(), sourcePath, externalId, overrideName));
detectCodeLocations.put(codeLocation, detectCodeLocation);
}
return detectCodeLocations;
}
use of com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation in project synopsys-detect by blackducksoftware.
the class DetectorTool method performDetectors.
public DetectorToolResult performDetectors(File directory, DetectorRuleSet detectorRuleSet, DetectorFinderOptions detectorFinderOptions, DetectorEvaluationOptions evaluationOptions, String projectDetector, List<DetectorType> requiredDetectors, FileFinder fileFinder) {
logger.debug("Initializing detector system.");
Optional<DetectorEvaluationTree> possibleRootEvaluation;
logger.debug("Starting detector file system traversal.");
possibleRootEvaluation = detectorFinder.findDetectors(directory, detectorRuleSet, detectorFinderOptions, fileFinder);
if (!possibleRootEvaluation.isPresent()) {
logger.error("The source directory could not be searched for detectors - detector tool failed.");
logger.error("Please ensure the provided source path is a directory and detect has access.");
exitCodePublisher.publishExitCode(ExitCodeType.FAILURE_CONFIGURATION, "Detector tool failed to run on the configured source path.");
return new DetectorToolResult();
}
DetectorEvaluationTree rootEvaluation = possibleRootEvaluation.get();
List<DetectorEvaluation> detectorEvaluations = rootEvaluation.allDescendentEvaluations();
logger.trace("Setting up detector events.");
// DetectorNameVersionHandler detectorNameVersionHandler = createNameVersionHandler(projectDetector);
DetectorEvaluatorBroadcaster eventBroadcaster = new DetectorEvaluatorBroadcaster(eventSystem);
DetectorEvaluator detectorEvaluator = new DetectorEvaluator(evaluationOptions, extractionEnvironmentProvider::createExtractionEnvironment);
detectorEvaluator.setDetectorEvaluatorListener(eventBroadcaster);
detectorEvaluator.registerPostApplicableCallback(detectorAggregateEvaluationResult -> {
detectorEventPublisher.publishApplicableCompleted(detectorAggregateEvaluationResult.getApplicableDetectorTypesRecursively());
detectorEventPublisher.publishSearchCompleted(detectorAggregateEvaluationResult.getEvaluationTree());
logger.info("");
});
detectorEvaluator.registerPostExtractableCallback(detectorAggregateEvaluationResult -> {
detectorEventPublisher.publishPreparationsCompleted(detectorAggregateEvaluationResult.getEvaluationTree());
logger.debug("Counting detectors that will be evaluated.");
Integer extractionCount = detectorAggregateEvaluationResult.getExtractionCount();
detectorEventPublisher.publishExtractionCount(extractionCount);
logger.debug("Total number of detectors: {}", extractionCount);
});
detectorEvaluator.registerPostExtractionCallback(detectorAggregateEvaluationResult -> detectorEventPublisher.publishExtractionsCompleted(detectorAggregateEvaluationResult.getEvaluationTree()));
DetectorAggregateEvaluationResult evaluationResult = detectorEvaluator.evaluate(rootEvaluation);
// TODO- finished extractions?
logger.debug("Finished detectors.");
printExplanations(rootEvaluation);
Map<DetectorType, StatusType> statusMap = extractStatus(detectorEvaluations);
publishStatusEvents(statusMap);
publishFileEvents(detectorEvaluations);
detectorIssuePublisher.publishEvents(statusEventPublisher, rootEvaluation);
publishMissingDetectorEvents(requiredDetectors, evaluationResult.getApplicableDetectorTypesRecursively());
Map<CodeLocation, DetectCodeLocation> codeLocationMap = createCodeLocationMap(detectorEvaluations, directory);
DetectorEvaluationNameVersionDecider detectorEvaluationNameVersionDecider = new DetectorEvaluationNameVersionDecider(new DetectorNameVersionDecider());
Optional<NameVersion> bomToolProjectNameVersion = detectorEvaluationNameVersionDecider.decideSuggestion(detectorEvaluations, projectDetector);
logger.debug("Finished evaluating detectors for project info.");
DetectorToolResult detectorToolResult = new DetectorToolResult(bomToolProjectNameVersion.orElse(null), new ArrayList<>(codeLocationMap.values()), evaluationResult.getApplicableDetectorTypes(), new HashSet<>(), rootEvaluation, codeLocationMap);
// Completed.
logger.debug("Finished running detectors.");
detectorEventPublisher.publishDetectorsComplete(detectorToolResult);
return detectorToolResult;
}
use of com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation in project synopsys-detect by blackducksoftware.
the class DetectableTool method extract.
public DetectableToolResult extract() {
// TODO: Move docker/bazel out of detectable and drop this notion of a detctable tool. Will simplify this logic and make this unneccessary.
DetectableResult extractable;
try {
extractable = detectable.extractable();
} catch (DetectableException e) {
extractable = new ExceptionDetectableResult(e);
}
if (!extractable.getPassed()) {
logger.error(String.format("Was not extractable: %s", extractable.toDescription()));
statusEventPublisher.publishIssue(new DetectIssue(DetectIssueType.DETECTABLE_TOOL, "Detectable Tool Issue", Arrays.asList(extractable.toDescription())));
statusEventPublisher.publishStatusSummary(new Status(name, StatusType.FAILURE));
exitCodePublisher.publishExitCode(ExitCodeType.FAILURE_GENERAL_ERROR, extractable.toDescription());
return DetectableToolResult.failed(extractable);
}
logger.debug("Extractable passed.");
ExtractionEnvironment extractionEnvironment = extractionEnvironmentProvider.createExtractionEnvironment(name);
Extraction extraction;
try {
extraction = detectable.extract(extractionEnvironment);
} catch (ExecutableFailedException | ExecutableRunnerException | JsonSyntaxException | IOException | CycleDetectedException | DetectableException | MissingExternalIdException | ParserConfigurationException | SAXException e) {
extraction = new Extraction.Builder().exception(e).build();
}
if (!extraction.isSuccess()) {
logger.error("Extraction was not success.");
List<String> errorMessages = collectErrorMessages(extraction);
statusEventPublisher.publishIssue(new DetectIssue(DetectIssueType.DETECTABLE_TOOL, "Detectable Tool Issue", errorMessages));
statusEventPublisher.publishStatusSummary(new Status(name, StatusType.FAILURE));
exitCodePublisher.publishExitCode(new ExitCodeRequest(ExitCodeType.FAILURE_GENERAL_ERROR, extraction.getDescription()));
return DetectableToolResult.failed();
} else {
logger.debug("Extraction success.");
statusEventPublisher.publishStatusSummary(new Status(name, StatusType.SUCCESS));
}
Map<CodeLocation, DetectCodeLocation> detectCodeLocationMap = codeLocationConverter.toDetectCodeLocation(sourcePath, extraction, sourcePath, name);
List<DetectCodeLocation> detectCodeLocations = new ArrayList<>(detectCodeLocationMap.values());
DockerTargetData dockerTargetData = DockerTargetData.fromExtraction(extraction);
DetectToolProjectInfo projectInfo = null;
if (StringUtils.isNotBlank(extraction.getProjectName()) || StringUtils.isNotBlank(extraction.getProjectVersion())) {
NameVersion nameVersion = new NameVersion(extraction.getProjectName(), extraction.getProjectVersion());
projectInfo = new DetectToolProjectInfo(detectTool, nameVersion);
}
logger.debug("Tool finished.");
return DetectableToolResult.success(detectCodeLocations, projectInfo, dockerTargetData);
}
Aggregations