Search in sources :

Example 1 with FormattedOutputManager

use of com.synopsys.integration.detect.workflow.report.output.FormattedOutputManager in project synopsys-detect by blackducksoftware.

the class FormattedOutputManagerTest method detectorOutputStatusDataTest.

@Test
public <T extends Detectable> void detectorOutputStatusDataTest() throws IllegalAccessException {
    EventSystem eventSystem = new EventSystem();
    FormattedOutputManager formattedOutputManager = new FormattedOutputManager(eventSystem);
    DetectorRule rule = Mockito.mock(DetectorRule.class);
    Mockito.when(rule.getDescriptiveName()).thenReturn("");
    Mockito.when(rule.getName()).thenReturn("");
    Mockito.when(rule.getDetectorType()).thenReturn(DetectorType.GO_MOD);
    DetectorEvaluation detectorEvaluation = new DetectorEvaluation(rule);
    ExecutableNotFoundDetectableResult result = new ExecutableNotFoundDetectableResult("go");
    DetectorResult extractableResult = new DetectorResult(result.getPassed(), result.toDescription(), result.getClass(), Collections.emptyList(), Collections.emptyList());
    detectorEvaluation.setExtractable(extractableResult);
    detectorEvaluation.setApplicable(new DetectorResult(true, "", Collections.emptyList(), Collections.emptyList()));
    detectorEvaluation.setSearchable(new DetectorResult(true, "", Collections.emptyList(), Collections.emptyList()));
    detectorEvaluation.setDetectableEnvironment(new DetectableEnvironment(new File("")));
    DetectorToolResult detectorToolResult = new DetectorToolResult(null, null, null, new HashSet<>(), new DetectorEvaluationTree(null, 0, null, Collections.singletonList(detectorEvaluation), new HashSet<>()), null);
    eventSystem.publishEvent(Event.DetectorsComplete, detectorToolResult);
    DetectInfo detectInfo = new DetectInfo("", null, "");
    FormattedOutput formattedOutput = formattedOutputManager.createFormattedOutput(detectInfo);
    FormattedDetectorOutput detectorOutput = formattedOutput.detectors.get(0);
    Assertions.assertEquals("FAILURE", detectorOutput.status);
    Assertions.assertEquals(DetectorStatusCode.EXECUTABLE_NOT_FOUND, detectorOutput.statusCode);
    Assertions.assertEquals("No go executable was found.", detectorOutput.statusReason);
}
Also used : ExecutableNotFoundDetectableResult(com.synopsys.integration.detectable.detectable.result.ExecutableNotFoundDetectableResult) DetectInfo(com.synopsys.integration.detect.configuration.DetectInfo) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) FormattedOutputManager(com.synopsys.integration.detect.workflow.report.output.FormattedOutputManager) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) FormattedOutput(com.synopsys.integration.detect.workflow.report.output.FormattedOutput) DetectorToolResult(com.synopsys.integration.detect.tool.detector.DetectorToolResult) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) FormattedDetectorOutput(com.synopsys.integration.detect.workflow.report.output.FormattedDetectorOutput) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with FormattedOutputManager

use of com.synopsys.integration.detect.workflow.report.output.FormattedOutputManager in project synopsys-detect by blackducksoftware.

the class Application method run.

@Override
public void run(ApplicationArguments applicationArguments) {
    long startTime = System.currentTimeMillis();
    // Events, Status and Exit Codes are required even if boot fails.
    EventSystem eventSystem = new EventSystem();
    DetectStatusManager statusManager = new DetectStatusManager(eventSystem);
    ExceptionUtility exceptionUtility = new ExceptionUtility();
    ExitCodeManager exitCodeManager = new ExitCodeManager(eventSystem, exceptionUtility);
    ExitManager exitManager = new ExitManager(eventSystem, exitCodeManager, statusManager);
    ReportListener.createDefault(eventSystem);
    FormattedOutputManager formattedOutputManager = new FormattedOutputManager(eventSystem);
    InstalledToolManager installedToolManager = new InstalledToolManager();
    // Before boot even begins, we create a new Spring context for Detect to work within.
    logger.debug("Initializing detect.");
    DetectRunId detectRunId = DetectRunId.createDefault();
    Gson gson = BlackDuckServicesFactory.createDefaultGsonBuilder().setPrettyPrinting().create();
    DetectInfo detectInfo = DetectInfoUtility.createDefaultDetectInfo();
    FileFinder fileFinder = new SimpleFileFinder();
    boolean shouldForceSuccess = false;
    Optional<DetectBootResult> detectBootResultOptional = bootApplication(detectRunId, applicationArguments.getSourceArgs(), eventSystem, exitCodeManager, gson, detectInfo, fileFinder, installedToolManager, exceptionUtility);
    if (detectBootResultOptional.isPresent()) {
        DetectBootResult detectBootResult = detectBootResultOptional.get();
        shouldForceSuccess = detectBootResult.shouldForceSuccess();
        runApplication(eventSystem, exitCodeManager, detectBootResult, exceptionUtility);
        detectBootResult.getProductRunData().filter(ProductRunData::shouldUseBlackDuckProduct).map(ProductRunData::getBlackDuckRunData).flatMap(BlackDuckRunData::getPhoneHomeManager).ifPresent(PhoneHomeManager::phoneHomeOperations);
        // Create status output file.
        logger.info("");
        detectBootResult.getDirectoryManager().ifPresent(directoryManager -> createStatusOutputFile(formattedOutputManager, detectInfo, directoryManager));
        // Create installed tool data file.
        detectBootResult.getDirectoryManager().ifPresent(directoryManager -> createOrUpdateInstalledToolsFile(installedToolManager, directoryManager.getPermanentDirectory()));
        shutdownApplication(detectBootResult, exitCodeManager);
    } else {
        logger.info("Will not create status file, detect did not boot.");
    }
    logger.debug("All Detect actions completed.");
    exitApplication(exitManager, startTime, shouldForceSuccess);
}
Also used : ExitManager(com.synopsys.integration.detect.lifecycle.exit.ExitManager) DetectRunId(com.synopsys.integration.detect.workflow.DetectRunId) DetectInfo(com.synopsys.integration.detect.configuration.DetectInfo) Gson(com.google.gson.Gson) DetectBootResult(com.synopsys.integration.detect.lifecycle.boot.DetectBootResult) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) PhoneHomeManager(com.synopsys.integration.detect.workflow.phonehome.PhoneHomeManager) FormattedOutputManager(com.synopsys.integration.detect.workflow.report.output.FormattedOutputManager) ProductRunData(com.synopsys.integration.detect.lifecycle.run.data.ProductRunData) InstalledToolManager(com.synopsys.integration.detect.tool.cache.InstalledToolManager) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) ExceptionUtility(com.synopsys.integration.detect.lifecycle.shutdown.ExceptionUtility) EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) DetectStatusManager(com.synopsys.integration.detect.workflow.status.DetectStatusManager) ExitCodeManager(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeManager)

Aggregations

DetectInfo (com.synopsys.integration.detect.configuration.DetectInfo)2 EventSystem (com.synopsys.integration.detect.workflow.event.EventSystem)2 FormattedOutputManager (com.synopsys.integration.detect.workflow.report.output.FormattedOutputManager)2 Gson (com.google.gson.Gson)1 FileFinder (com.synopsys.integration.common.util.finder.FileFinder)1 SimpleFileFinder (com.synopsys.integration.common.util.finder.SimpleFileFinder)1 DetectBootResult (com.synopsys.integration.detect.lifecycle.boot.DetectBootResult)1 ExitManager (com.synopsys.integration.detect.lifecycle.exit.ExitManager)1 ProductRunData (com.synopsys.integration.detect.lifecycle.run.data.ProductRunData)1 ExceptionUtility (com.synopsys.integration.detect.lifecycle.shutdown.ExceptionUtility)1 ExitCodeManager (com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeManager)1 InstalledToolManager (com.synopsys.integration.detect.tool.cache.InstalledToolManager)1 DetectorToolResult (com.synopsys.integration.detect.tool.detector.DetectorToolResult)1 DetectRunId (com.synopsys.integration.detect.workflow.DetectRunId)1 PhoneHomeManager (com.synopsys.integration.detect.workflow.phonehome.PhoneHomeManager)1 FormattedDetectorOutput (com.synopsys.integration.detect.workflow.report.output.FormattedDetectorOutput)1 FormattedOutput (com.synopsys.integration.detect.workflow.report.output.FormattedOutput)1 DetectStatusManager (com.synopsys.integration.detect.workflow.status.DetectStatusManager)1 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)1 ExecutableNotFoundDetectableResult (com.synopsys.integration.detectable.detectable.result.ExecutableNotFoundDetectableResult)1