use of com.blackducksoftware.integration.hub.detect.workflow.profiling.BomToolProfiler in project hub-detect by blackducksoftware.
the class BootManager method boot.
public BootResult boot(DetectRun detectRun, final String[] sourceArgs, ConfigurableEnvironment environment, EventSystem eventSystem, DetectContext detectContext) throws DetectUserFriendlyException, IntegrationException {
Gson gson = bootFactory.createGson();
ObjectMapper objectMapper = bootFactory.createObjectMapper();
DocumentBuilder xml = bootFactory.createXmlDocumentBuilder();
Configuration configuration = bootFactory.createConfiguration();
DetectInfo detectInfo = DetectInfoUtility.createDefaultDetectInfo();
SpringPropertySource springPropertySource = new SpringPropertySource(environment);
DetectPropertySource propertySource = new DetectPropertySource(springPropertySource);
DetectPropertyMap propertyMap = new DetectPropertyMap();
DetectConfiguration detectConfiguration = new DetectConfiguration(propertySource, propertyMap);
DetectOptionManager detectOptionManager = new DetectOptionManager(detectConfiguration, detectInfo);
final List<DetectOption> options = detectOptionManager.getDetectOptions();
DetectArgumentState detectArgumentState = parseDetectArgumentState(sourceArgs);
if (detectArgumentState.isHelp() || detectArgumentState.isDeprecatedHelp() || detectArgumentState.isVerboseHelp()) {
printAppropriateHelp(options, detectArgumentState);
return BootResult.exit(detectConfiguration);
}
if (detectArgumentState.isHelpHtmlDocument()) {
printHelpHtmlDocument(options, detectInfo, configuration);
return BootResult.exit(detectConfiguration);
}
if (detectArgumentState.isHelpJsonDocument()) {
printHelpJsonDocument(options, detectInfo, configuration, gson);
return BootResult.exit(detectConfiguration);
}
printDetectInfo(detectInfo);
if (detectArgumentState.isInteractive()) {
startInteractiveMode(detectOptionManager, detectConfiguration, gson, objectMapper);
}
processDetectConfiguration(detectInfo, detectRun, detectConfiguration, options);
detectOptionManager.postConfigurationProcessedInit();
logger.info("Configuration processed completely.");
printConfiguration(detectConfiguration.getBooleanProperty(DetectProperty.DETECT_SUPPRESS_CONFIGURATION_OUTPUT, PropertyAuthority.None), options);
logger.info("Initializing detect.");
DetectConfigurationFactory factory = new DetectConfigurationFactory(detectConfiguration);
DirectoryManager directoryManager = new DirectoryManager(factory.createDirectoryOptions(), detectRun);
DiagnosticManager diagnosticManager = createDiagnostics(detectOptionManager.getDetectOptions(), detectRun, detectInfo, detectArgumentState, eventSystem, directoryManager);
checkForInvalidOptions(detectOptionManager);
if (detectOptionManager.checkForAnyFailureProperties()) {
eventSystem.publishEvent(Event.ExitCode, new ExitCodeRequest(ExitCodeType.FAILURE_CONFIGURATION));
return BootResult.exit(detectConfiguration);
}
ConnectivityManager connectivityManager;
boolean offline = detectConfiguration.getBooleanProperty(DetectProperty.BLACKDUCK_OFFLINE_MODE, PropertyAuthority.None);
if (offline) {
logger.info("Detect is in offline mode.");
connectivityManager = ConnectivityManager.offline();
} else {
logger.info("Detect is in online mode.");
// check my connectivity
ConnectivityChecker connectivityChecker = new ConnectivityChecker();
ConnectivityResult connectivityResult = connectivityChecker.determineConnectivity(detectConfiguration, detectOptionManager, detectInfo, gson, objectMapper, eventSystem);
if (connectivityResult.isSuccessfullyConnected()) {
logger.info("Detect is capable of communicating with server.");
connectivityManager = ConnectivityManager.online(connectivityResult.getBlackDuckServicesFactory(), connectivityResult.getPhoneHomeManager(), connectivityResult.getBlackDuckServerConfig());
} else {
logger.info("Detect is NOT capable of communicating with server.");
logger.info("Please double check the Detect documentation: https://synopsys.atlassian.net/wiki/spaces/INTDOCS/pages/622633/Hub+Detect");
if (detectConfiguration.getBooleanProperty(DetectProperty.DETECT_DISABLE_WITHOUT_BLACKDUCK, PropertyAuthority.None)) {
logger.info(connectivityResult.getFailureReason());
logger.info(String.format("%s is set to 'true' so Detect will simply exit.", DetectProperty.DETECT_DISABLE_WITHOUT_BLACKDUCK.getPropertyName()));
return BootResult.exit(detectConfiguration);
} else {
throw new DetectUserFriendlyException("Could not communicate with Black Duck: " + connectivityResult.getFailureReason(), ExitCodeType.FAILURE_HUB_CONNECTIVITY);
}
}
}
if (detectConfiguration.getBooleanProperty(DetectProperty.DETECT_TEST_CONNECTION, PropertyAuthority.None)) {
logger.info(String.format("%s is set to 'true' so Detect will not run.", DetectProperty.DETECT_TEST_CONNECTION.getPropertyName()));
return BootResult.exit(detectConfiguration);
}
// TODO: Only need this if in diagnostic or online (for phone home):
BomToolProfiler profiler = new BomToolProfiler(eventSystem);
// lock the configuration, boot has completed.
logger.debug("Configuration is now complete. No changes should occur to configuration.");
detectConfiguration.lock();
// Finished, populate the detect context
detectContext.registerBean(detectRun);
detectContext.registerBean(eventSystem);
detectContext.registerBean(profiler);
detectContext.registerBean(detectConfiguration);
detectContext.registerBean(detectInfo);
detectContext.registerBean(directoryManager);
detectContext.registerBean(diagnosticManager);
detectContext.registerBean(connectivityManager);
detectContext.registerBean(gson);
detectContext.registerBean(objectMapper);
detectContext.registerBean(xml);
detectContext.registerBean(configuration);
detectContext.registerConfiguration(RunBeanConfiguration.class);
detectContext.registerConfiguration(DetectorBeanConfiguration.class);
// can only refresh once, this locks and triggers refresh.
detectContext.lock();
BootResult result = new BootResult();
result.bootType = BootResult.BootType.CONTINUE;
result.detectConfiguration = detectConfiguration;
return result;
}
Aggregations