use of com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest 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);
}
use of com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest in project synopsys-detect by blackducksoftware.
the class ExitManager method exit.
public ExitResult exit(ExitOptions exitOptions) {
long startTime = exitOptions.getStartTime();
boolean forceSuccessExit = exitOptions.shouldForceSuccessExit();
boolean shouldExit = exitOptions.shouldExit();
// Generally, when requesting a failure status, an exit code is also requested, but if it is not, we default to an unknown error.
if (statusManager.hasAnyFailure()) {
eventSystem.publishEvent(Event.ExitCode, new ExitCodeRequest(ExitCodeType.FAILURE_UNKNOWN_ERROR, "A failure status was requested by one or more of Detect's tools."));
}
// Find the final (as requested) exit code
ExitCodeType finalExitCode = exitCodeManager.getWinningExitCode();
// Print detect's status
statusManager.logDetectResults(new Slf4jIntLogger(logger), finalExitCode);
// Print duration of run
long endTime = System.currentTimeMillis();
String duration = DurationFormatUtils.formatPeriod(startTime, endTime, "HH'h' mm'm' ss's' SSS'ms'");
logger.info("Detect duration: {}", duration);
// Exit with formal exit code
if (finalExitCode != ExitCodeType.SUCCESS && forceSuccessExit) {
logger.warn("Forcing success: Exiting with exit code 0. Ignored exit code was {}.", finalExitCode.getExitCode());
} else if (finalExitCode != ExitCodeType.SUCCESS) {
logger.error("Exiting with code {} - {}", finalExitCode.getExitCode(), finalExitCode);
}
if (!shouldExit) {
logger.info("Would normally exit({}) but it is overridden.", finalExitCode.getExitCode());
}
return new ExitResult(finalExitCode, forceSuccessExit, shouldExit);
}
use of com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest in project synopsys-detect by blackducksoftware.
the class ExitManagerTest method testForceExit.
@Test
public void testForceExit() {
long startTime = System.currentTimeMillis();
EventSystem eventSystem = new EventSystem();
DetectStatusManager statusManager = new DetectStatusManager(eventSystem);
ExceptionUtility exitCodeUtility = new ExceptionUtility();
ExitCodeManager exitCodeManager = new ExitCodeManager(eventSystem, exitCodeUtility);
exitCodeManager.addExitCodeRequest(new ExitCodeRequest(ExitCodeType.FAILURE_CONFIGURATION, "JUnit failure code."));
ExitManager exitManager = new ExitManager(eventSystem, exitCodeManager, statusManager);
ExitOptions exitOptions = new ExitOptions(startTime, true, true);
ExitResult exitResult = exitManager.exit(exitOptions);
assertEquals(startTime, exitOptions.getStartTime());
assertTrue(exitResult.shouldForceSuccess());
assertTrue(exitResult.shouldPerformExit());
assertEquals(ExitCodeType.FAILURE_CONFIGURATION, exitResult.getExitCodeType());
}
use of com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest in project synopsys-detect by blackducksoftware.
the class ExitManagerTest method testSkipExit.
@Test
public void testSkipExit() {
long startTime = System.currentTimeMillis();
EventSystem eventSystem = new EventSystem();
DetectStatusManager statusManager = new DetectStatusManager(eventSystem);
ExceptionUtility exitCodeUtility = new ExceptionUtility();
ExitCodeManager exitCodeManager = new ExitCodeManager(eventSystem, exitCodeUtility);
exitCodeManager.addExitCodeRequest(new ExitCodeRequest(ExitCodeType.FAILURE_CONFIGURATION, "JUnit failure code."));
ExitManager exitManager = new ExitManager(eventSystem, exitCodeManager, statusManager);
ExitOptions exitOptions = new ExitOptions(startTime, false, false);
ExitResult exitResult = exitManager.exit(exitOptions);
assertEquals(startTime, exitOptions.getStartTime());
assertFalse(exitResult.shouldForceSuccess());
assertFalse(exitResult.shouldPerformExit());
assertEquals(ExitCodeType.FAILURE_CONFIGURATION, exitResult.getExitCodeType());
}
use of com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest in project synopsys-detect by blackducksoftware.
the class DetectorTool method publishMissingDetectorEvents.
private void publishMissingDetectorEvents(List<DetectorType> requiredDetectors, Set<DetectorType> applicable) {
Set<DetectorType> missingDetectors = requiredDetectors.stream().filter(it -> !applicable.contains(it)).collect(Collectors.toSet());
if (!missingDetectors.isEmpty()) {
String missingDetectorDisplay = missingDetectors.stream().map(Enum::toString).collect(Collectors.joining(","));
logger.error("One or more required detector types were not found: {}", missingDetectorDisplay);
exitCodePublisher.publishExitCode(new ExitCodeRequest(ExitCodeType.FAILURE_DETECTOR_REQUIRED));
}
}
Aggregations