Search in sources :

Example 6 with EventSystem

use of com.synopsys.integration.detect.workflow.event.EventSystem 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)

Example 7 with EventSystem

use of com.synopsys.integration.detect.workflow.event.EventSystem in project synopsys-detect by blackducksoftware.

the class DetectorToolTest method testFailWhenMisConfigured.

@Test
public void testFailWhenMisConfigured() throws DetectUserFriendlyException {
    ExtractionEnvironmentProvider extractionEnvironmentProvider = Mockito.mock(ExtractionEnvironmentProvider.class);
    DetectorFinder detectorFinder = Mockito.mock(DetectorFinder.class);
    EventSystem eventSystem = Mockito.mock(EventSystem.class);
    CodeLocationConverter codeLocationConverter = Mockito.mock(CodeLocationConverter.class);
    DetectorIssuePublisher detectorIssuePublisher = Mockito.mock(DetectorIssuePublisher.class);
    StatusEventPublisher statusEventPublisher = Mockito.mock(StatusEventPublisher.class);
    ExitCodePublisher exitCodePublisher = Mockito.mock(ExitCodePublisher.class);
    DetectorEventPublisher detectorEventPublisher = Mockito.mock(DetectorEventPublisher.class);
    DetectorTool tool = new DetectorTool(detectorFinder, extractionEnvironmentProvider, eventSystem, codeLocationConverter, detectorIssuePublisher, statusEventPublisher, exitCodePublisher, detectorEventPublisher);
    File directory = new File(".");
    DetectorRuleSet detectorRuleSet = Mockito.mock(DetectorRuleSet.class);
    DetectorFinderOptions detectorFinderOptions = Mockito.mock(DetectorFinderOptions.class);
    DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
    String projectBomTool = "testBomTool";
    tool.performDetectors(directory, detectorRuleSet, detectorFinderOptions, evaluationOptions, projectBomTool, new ArrayList<>(), new SimpleFileFinder());
    Mockito.verify(exitCodePublisher).publishExitCode(Mockito.any(ExitCodeType.class), Mockito.anyString());
}
Also used : DetectorEvaluationOptions(com.synopsys.integration.detector.evaluation.DetectorEvaluationOptions) DetectorFinderOptions(com.synopsys.integration.detector.finder.DetectorFinderOptions) ExtractionEnvironmentProvider(com.synopsys.integration.detect.tool.detector.extraction.ExtractionEnvironmentProvider) ExitCodePublisher(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodePublisher) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) ExitCodeType(com.synopsys.integration.detect.configuration.enumeration.ExitCodeType) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) DetectorFinder(com.synopsys.integration.detector.finder.DetectorFinder) StatusEventPublisher(com.synopsys.integration.detect.workflow.status.StatusEventPublisher) EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 8 with EventSystem

use of com.synopsys.integration.detect.workflow.event.EventSystem in project synopsys-detect by blackducksoftware.

the class ExitManagerTest method testNormalExit.

@Test
public void testNormalExit() {
    long startTime = System.currentTimeMillis();
    EventSystem eventSystem = new EventSystem();
    DetectStatusManager statusManager = new DetectStatusManager(eventSystem);
    ExceptionUtility exitCodeUtility = new ExceptionUtility();
    ExitCodeManager exitCodeManager = new ExitCodeManager(eventSystem, exitCodeUtility);
    ExitManager exitManager = new ExitManager(eventSystem, exitCodeManager, statusManager);
    ExitOptions exitOptions = new ExitOptions(startTime, false, true);
    ExitResult exitResult = exitManager.exit(exitOptions);
    assertEquals(startTime, exitOptions.getStartTime());
    assertFalse(exitResult.shouldForceSuccess());
    assertTrue(exitResult.shouldPerformExit());
    assertEquals(ExitCodeType.SUCCESS, exitResult.getExitCodeType());
}
Also used : 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) Test(org.junit.jupiter.api.Test)

Example 9 with EventSystem

use of com.synopsys.integration.detect.workflow.event.EventSystem in project synopsys-detect by blackducksoftware.

the class BdioCodeLocationCreatorTest method testCreateFromDetectCodeLocations.

// TODO: This test seems suspiciously long and like it might not be testing much. -jp
@Test
public void testCreateFromDetectCodeLocations() throws IOException, DetectUserFriendlyException {
    File sourceDir = new File("src/test/resource");
    CodeLocationNameManager codeLocationNameManager = Mockito.mock(CodeLocationNameManager.class);
    DirectoryManager directoryManager = Mockito.mock(DirectoryManager.class);
    Mockito.when(directoryManager.getSourceDirectory()).thenReturn(sourceDir);
    EventSystem eventSystem = Mockito.mock(EventSystem.class);
    CreateBdioCodeLocationsFromDetectCodeLocationsOperation creator = new CreateBdioCodeLocationsFromDetectCodeLocationsOperation(codeLocationNameManager, directoryManager);
    NameVersion projectNameVersion = new NameVersion("testName", "testVersion");
    DependencyGraph dependencyGraph = Mockito.mock(DependencyGraph.class);
    Set<Dependency> dependencies = new HashSet<>();
    Dependency dependency = Mockito.mock(Dependency.class);
    dependencies.add(dependency);
    Mockito.when(dependencyGraph.getRootDependencies()).thenReturn(dependencies);
    ExternalId externalId = new ExternalId(Forge.MAVEN);
    externalId.setName("testExternalIdName");
    externalId.setVersion("testExternalIdVersion");
    externalId.setArchitecture("testExternalIdArch");
    DetectCodeLocation detectCodeLocation = DetectCodeLocation.forCreator(dependencyGraph, sourceDir, externalId, "testCreator");
    List<DetectCodeLocation> detectCodeLocations = new ArrayList<>();
    detectCodeLocations.add(detectCodeLocation);
    Mockito.when(codeLocationNameManager.createCodeLocationName(detectCodeLocation, sourceDir, projectNameVersion.getName(), projectNameVersion.getVersion(), "", "")).thenReturn("testCodeLocationName");
    BdioCodeLocationResult result = creator.transformDetectCodeLocations(detectCodeLocations, "", "", projectNameVersion);
    assertEquals("testCodeLocationName", result.getBdioCodeLocations().get(0).getCodeLocationName());
    File resultDir = result.getBdioCodeLocations().get(0).getDetectCodeLocation().getSourcePath();
    assertTrue(resultDir.getCanonicalPath().contains("test"));
    assertTrue(resultDir.getCanonicalPath().contains("resource"));
}
Also used : NameVersion(com.synopsys.integration.util.NameVersion) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DirectoryManager(com.synopsys.integration.detect.workflow.file.DirectoryManager) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

EventSystem (com.synopsys.integration.detect.workflow.event.EventSystem)9 Test (org.junit.jupiter.api.Test)6 ExceptionUtility (com.synopsys.integration.detect.lifecycle.shutdown.ExceptionUtility)4 ExitCodeManager (com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeManager)4 DetectStatusManager (com.synopsys.integration.detect.workflow.status.DetectStatusManager)4 File (java.io.File)4 SimpleFileFinder (com.synopsys.integration.common.util.finder.SimpleFileFinder)3 DetectInfo (com.synopsys.integration.detect.configuration.DetectInfo)2 ExitCodePublisher (com.synopsys.integration.detect.lifecycle.shutdown.ExitCodePublisher)2 ExitCodeRequest (com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest)2 ExtractionEnvironmentProvider (com.synopsys.integration.detect.tool.detector.extraction.ExtractionEnvironmentProvider)2 FormattedOutputManager (com.synopsys.integration.detect.workflow.report.output.FormattedOutputManager)2 StatusEventPublisher (com.synopsys.integration.detect.workflow.status.StatusEventPublisher)2 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)2 DetectorEvaluationOptions (com.synopsys.integration.detector.evaluation.DetectorEvaluationOptions)2 DetectorFinder (com.synopsys.integration.detector.finder.DetectorFinder)2 DetectorFinderOptions (com.synopsys.integration.detector.finder.DetectorFinderOptions)2 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)2 HashSet (java.util.HashSet)2 Gson (com.google.gson.Gson)1