Search in sources :

Example 1 with ProductRunData

use of com.synopsys.integration.detect.lifecycle.run.data.ProductRunData in project synopsys-detect by blackducksoftware.

the class Application method runApplication.

private void runApplication(EventSystem eventSystem, ExitCodeManager exitCodeManager, DetectBootResult detectBootResult, ExceptionUtility exceptionUtility) {
    Optional<BootSingletons> optionalRunContext = detectBootResult.getBootSingletons();
    Optional<ProductRunData> optionalProductRunData = detectBootResult.getProductRunData();
    if (detectBootResult.getBootType() == DetectBootResult.BootType.RUN && optionalProductRunData.isPresent() && optionalRunContext.isPresent()) {
        logger.debug("Detect will attempt to run.");
        DetectRun detectRun = new DetectRun(exitCodeManager, exceptionUtility);
        detectRun.run(optionalRunContext.get());
    } else {
        logger.debug("Detect will NOT attempt to run.");
        detectBootResult.getException().ifPresent(exitCodeManager::requestExitCode);
        detectBootResult.getException().ifPresent(e -> DetectIssue.publish(eventSystem, DetectIssueType.EXCEPTION, "Detect Boot Error", e.getMessage()));
    }
}
Also used : BootSingletons(com.synopsys.integration.detect.lifecycle.run.singleton.BootSingletons) DetectRun(com.synopsys.integration.detect.lifecycle.run.DetectRun) ProductRunData(com.synopsys.integration.detect.lifecycle.run.data.ProductRunData)

Example 2 with ProductRunData

use of com.synopsys.integration.detect.lifecycle.run.data.ProductRunData in project synopsys-detect by blackducksoftware.

the class ProductBootTest method blackDuckConnectionSuccessWithTestReturnsNull.

@Test
public void blackDuckConnectionSuccessWithTestReturnsNull() throws DetectUserFriendlyException, IOException, IntegrationException {
    BlackDuckConnectivityResult connectivityResult = BlackDuckConnectivityResult.success(Mockito.mock(BlackDuckServicesFactory.class), Mockito.mock(BlackDuckServerConfig.class));
    ProductRunData productRunData = testBoot(BlackDuckDecision.runOnline(BlackduckScanMode.INTELLIGENT), new ProductBootOptions(false, true), connectivityResult);
    Assertions.assertNull(productRunData);
}
Also used : BlackDuckConnectivityResult(com.synopsys.integration.detect.lifecycle.boot.product.BlackDuckConnectivityResult) ProductBootOptions(com.synopsys.integration.detect.lifecycle.boot.product.ProductBootOptions) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProductRunData(com.synopsys.integration.detect.lifecycle.run.data.ProductRunData) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) Test(org.junit.jupiter.api.Test)

Example 3 with ProductRunData

use of com.synopsys.integration.detect.lifecycle.run.data.ProductRunData 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 4 with ProductRunData

use of com.synopsys.integration.detect.lifecycle.run.data.ProductRunData in project synopsys-detect by blackducksoftware.

the class ProductBootTest method blackDuckFailureWithIgnoreReturnsFalse.

@Test
public void blackDuckFailureWithIgnoreReturnsFalse() throws DetectUserFriendlyException, IOException, IntegrationException {
    BlackDuckConnectivityResult connectivityResult = BlackDuckConnectivityResult.failure("Failed to connect");
    ProductRunData productRunData = testBoot(BlackDuckDecision.runOnline(BlackduckScanMode.INTELLIGENT), new ProductBootOptions(true, false), connectivityResult);
    Assertions.assertFalse(productRunData.shouldUseBlackDuckProduct());
}
Also used : BlackDuckConnectivityResult(com.synopsys.integration.detect.lifecycle.boot.product.BlackDuckConnectivityResult) ProductBootOptions(com.synopsys.integration.detect.lifecycle.boot.product.ProductBootOptions) ProductRunData(com.synopsys.integration.detect.lifecycle.run.data.ProductRunData) Test(org.junit.jupiter.api.Test)

Example 5 with ProductRunData

use of com.synopsys.integration.detect.lifecycle.run.data.ProductRunData in project synopsys-detect by blackducksoftware.

the class ProductBootTest method blackDuckOnlyWorks.

@Test
public void blackDuckOnlyWorks() throws DetectUserFriendlyException, IOException, IntegrationException {
    BlackDuckConnectivityResult connectivityResult = BlackDuckConnectivityResult.success(Mockito.mock(BlackDuckServicesFactory.class), Mockito.mock(BlackDuckServerConfig.class));
    ProductRunData productRunData = testBoot(BlackDuckDecision.runOnline(BlackduckScanMode.INTELLIGENT), new ProductBootOptions(false, false), connectivityResult);
    Assertions.assertTrue(productRunData.shouldUseBlackDuckProduct());
}
Also used : BlackDuckConnectivityResult(com.synopsys.integration.detect.lifecycle.boot.product.BlackDuckConnectivityResult) ProductBootOptions(com.synopsys.integration.detect.lifecycle.boot.product.ProductBootOptions) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProductRunData(com.synopsys.integration.detect.lifecycle.run.data.ProductRunData) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ProductRunData (com.synopsys.integration.detect.lifecycle.run.data.ProductRunData)10 Test (org.junit.jupiter.api.Test)4 DetectUserFriendlyException (com.synopsys.integration.detect.configuration.DetectUserFriendlyException)3 BlackDuckConnectivityResult (com.synopsys.integration.detect.lifecycle.boot.product.BlackDuckConnectivityResult)3 ProductBootOptions (com.synopsys.integration.detect.lifecycle.boot.product.ProductBootOptions)3 BlackDuckServerConfig (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig)2 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)2 BlackDuckRunData (com.synopsys.integration.detect.lifecycle.run.data.BlackDuckRunData)2 BootSingletons (com.synopsys.integration.detect.lifecycle.run.singleton.BootSingletons)2 DiagnosticSystem (com.synopsys.integration.detect.workflow.diagnostic.DiagnosticSystem)2 PhoneHomeManager (com.synopsys.integration.detect.workflow.phonehome.PhoneHomeManager)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 PropertyConfiguration (com.synopsys.integration.configuration.config.PropertyConfiguration)1 PathResolver (com.synopsys.integration.configuration.property.types.path.PathResolver)1 SimplePathResolver (com.synopsys.integration.configuration.property.types.path.SimplePathResolver)1 MapPropertySource (com.synopsys.integration.configuration.source.MapPropertySource)1 DetectConfigurationFactory (com.synopsys.integration.detect.configuration.DetectConfigurationFactory)1 DetectInfo (com.synopsys.integration.detect.configuration.DetectInfo)1