use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.
the class DetectBoot method boot.
public Optional<DetectBootResult> boot(String detectVersion, String detectBuildDate) throws IOException, IllegalAccessException {
if (detectArgumentState.isHelp() || detectArgumentState.isDeprecatedHelp() || detectArgumentState.isVerboseHelp()) {
HelpPrinter helpPrinter = new HelpPrinter();
helpPrinter.printAppropriateHelpMessage(DEFAULT_PRINT_STREAM, DetectProperties.allProperties().getProperties(), Arrays.asList(DetectGroup.values()), DetectGroup.BLACKDUCK_SERVER, detectArgumentState);
return Optional.of(DetectBootResult.exit(new PropertyConfiguration(propertySources)));
}
if (detectArgumentState.isHelpJsonDocument()) {
HelpJsonManager helpJsonManager = detectBootFactory.createHelpJsonManager();
helpJsonManager.createHelpJsonDocument(String.format("synopsys-detect-%s-help.json", detectVersion));
return Optional.of(DetectBootResult.exit(new PropertyConfiguration(propertySources)));
}
DEFAULT_PRINT_STREAM.println();
DEFAULT_PRINT_STREAM.println("Detect Version: " + detectVersion);
DEFAULT_PRINT_STREAM.println();
if (detectArgumentState.isInteractive()) {
InteractiveManager interactiveManager = detectBootFactory.createInteractiveManager(propertySources);
MapPropertySource interactivePropertySource = interactiveManager.executeInteractiveMode();
propertySources.add(0, interactivePropertySource);
}
PropertyConfiguration propertyConfiguration = new PropertyConfiguration(propertySources);
SortedMap<String, String> maskedRawPropertyValues = collectMaskedRawPropertyValues(propertyConfiguration);
publishCollectedPropertyValues(maskedRawPropertyValues);
logger.debug("Configuration processed completely.");
DetectConfigurationBootManager detectConfigurationBootManager = detectBootFactory.createDetectConfigurationBootManager(propertyConfiguration);
DeprecationResult deprecationResult = detectConfigurationBootManager.createDeprecationNotesAndPublishEvents(propertyConfiguration);
detectConfigurationBootManager.printConfiguration(maskedRawPropertyValues, deprecationResult.getAdditionalNotes());
Optional<DetectUserFriendlyException> possiblePropertyParseError = detectConfigurationBootManager.validateForPropertyParseErrors();
if (possiblePropertyParseError.isPresent()) {
return Optional.of(DetectBootResult.exception(possiblePropertyParseError.get(), propertyConfiguration));
}
logger.info("Detect build date: {}", detectBuildDate);
logger.debug("Initializing Detect.");
Configuration freemarkerConfiguration = detectBootFactory.createFreemarkerConfiguration();
PathResolver pathResolver = detectBootFactory.createPathResolver();
DetectPropertyConfiguration detectConfiguration = new DetectPropertyConfiguration(propertyConfiguration, new SimplePathResolver());
DetectConfigurationFactory detectConfigurationFactory = new DetectConfigurationFactory(detectConfiguration, gson);
DirectoryManager directoryManager = detectBootFactory.createDirectoryManager(detectConfigurationFactory);
InstalledToolLocator installedToolLocator = new InstalledToolLocator(directoryManager.getPermanentDirectory().toPath(), gson);
DiagnosticSystem diagnosticSystem = null;
DiagnosticDecision diagnosticDecision = DiagnosticDecision.decide(detectArgumentState, propertyConfiguration);
if (diagnosticDecision.shouldCreateDiagnosticSystem()) {
diagnosticSystem = detectBootFactory.createDiagnosticSystem(diagnosticDecision.isExtended(), propertyConfiguration, directoryManager, maskedRawPropertyValues);
}
logger.debug("Main boot completed. Deciding what Detect should do.");
if (detectArgumentState.isGenerateAirGapZip()) {
try {
AirGapType airGapType = new AirGapTypeDecider().decide(detectArgumentState);
AirGapCreator airGapCreator = detectBootFactory.createAirGapCreator(detectConfigurationFactory.createConnectionDetails(), detectConfigurationFactory.createDetectExecutableOptions(), freemarkerConfiguration, installedToolManager, installedToolLocator);
String gradleInspectorVersion = propertyConfiguration.getValueOrEmpty(DetectProperties.DETECT_GRADLE_INSPECTOR_VERSION).orElse(null);
File airGapZip = airGapCreator.createAirGapZip(airGapType, directoryManager.getRunHomeDirectory(), gradleInspectorVersion);
return Optional.of(DetectBootResult.exit(propertyConfiguration, airGapZip, directoryManager, diagnosticSystem));
} catch (DetectUserFriendlyException e) {
return Optional.of(DetectBootResult.exception(e, propertyConfiguration, directoryManager, diagnosticSystem));
}
}
logger.info("");
ProductRunData productRunData;
try {
ProductDecider productDecider = new ProductDecider();
BlackDuckDecision blackDuckDecision = productDecider.decideBlackDuck(detectConfigurationFactory.createBlackDuckConnectionDetails(), detectConfigurationFactory.createScanMode());
// TODO: Move to proper decision home. -jp
RunDecision runDecision = new RunDecision(detectConfigurationFactory.createDetectTarget() == DetectTargetType.IMAGE);
DetectToolFilter detectToolFilter = detectConfigurationFactory.createToolFilter(runDecision, blackDuckDecision);
oneRequiresTheOther(detectConfigurationFactory.createDetectTarget() == DetectTargetType.IMAGE, detectToolFilter.shouldInclude(DetectTool.DOCKER), "Detect target type is set to IMAGE, but the DOCKER tool was excluded.");
logger.debug("Decided what products will be run. Starting product boot.");
ProductBoot productBoot = detectBootFactory.createProductBoot(detectConfigurationFactory);
productRunData = productBoot.boot(blackDuckDecision, detectToolFilter);
} catch (DetectUserFriendlyException e) {
return Optional.of(DetectBootResult.exception(e, propertyConfiguration, directoryManager, diagnosticSystem));
}
if (productRunData == null) {
logger.info("No products to run, Detect is complete.");
return Optional.of(DetectBootResult.exit(propertyConfiguration, directoryManager, diagnosticSystem));
}
DetectableOptionFactory detectableOptionFactory;
try {
ProxyInfo detectableProxyInfo = detectConfigurationFactory.createBlackDuckProxyInfo();
detectableOptionFactory = new DetectableOptionFactory(detectConfiguration, diagnosticSystem, pathResolver, detectableProxyInfo);
oneRequiresTheOther(detectConfigurationFactory.createDetectTarget() == DetectTargetType.IMAGE, detectableOptionFactory.createDockerDetectableOptions().hasDockerImageOrTar(), "Detect target type is set to IMAGE, but no docker image was specified.");
} catch (DetectUserFriendlyException e) {
return Optional.of(DetectBootResult.exception(e, propertyConfiguration, directoryManager, diagnosticSystem));
}
BootSingletons bootSingletons = detectBootFactory.createRunDependencies(productRunData, propertyConfiguration, detectableOptionFactory, detectConfigurationFactory, directoryManager, freemarkerConfiguration, installedToolManager, installedToolLocator);
return Optional.of(DetectBootResult.run(bootSingletons, propertyConfiguration, productRunData, directoryManager, diagnosticSystem));
}
use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.
the class BlackDuckConnectivityChecker method determineConnectivity.
public BlackDuckConnectivityResult determineConnectivity(BlackDuckServerConfig blackDuckServerConfig) throws DetectUserFriendlyException {
logger.debug("Detect will check communication with the Black Duck server.");
ConnectionResult connectionResult = blackDuckServerConfig.attemptConnection(new SilentIntLogger());
if (connectionResult.isFailure()) {
// TODO: For the logs, when connection result returns the client, can drop this.
blackDuckServerConfig.attemptConnection(new Slf4jIntLogger(logger));
logger.error("Failed to connect to the Black Duck server");
return BlackDuckConnectivityResult.failure(connectionResult.getFailureMessage().orElse("Could not reach the Black Duck server or the credentials were invalid."));
}
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckServerConfig.createBlackDuckServicesFactory(new Slf4jIntLogger(logger));
BlackDuckRegistrationService blackDuckRegistrationService = blackDuckServicesFactory.createBlackDuckRegistrationService();
UserService userService = blackDuckServicesFactory.createUserService();
try {
String version = blackDuckRegistrationService.getBlackDuckServerData().getVersion();
logger.info(String.format("Successfully connected to Black Duck (version %s)!", version));
if (logger.isDebugEnabled()) {
// These (particularly fetching roles) can be very slow operations
UserView userView = userService.findCurrentUser();
logger.debug("Connected as: " + userView.getUserName());
UserGroupService userGroupService = blackDuckServicesFactory.createUserGroupService();
List<RoleAssignmentView> roles = userGroupService.getRolesForUser(userView);
logger.debug("Roles: " + roles.stream().map(RoleAssignmentView::getName).distinct().collect(Collectors.joining(", ")));
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
List<UserGroupView> groups = blackDuckApiClient.getAllResponses(userView.metaMultipleResponses(USERGROUPS));
logger.debug("Group: " + groups.stream().map(UserGroupView::getName).distinct().collect(Collectors.joining(", ")));
}
} catch (IntegrationException e) {
throw new DetectUserFriendlyException("Could not determine which version of Black Duck detect connected to or which user is connecting.", e, ExitCodeType.FAILURE_BLACKDUCK_CONNECTIVITY);
}
return BlackDuckConnectivityResult.success(blackDuckServicesFactory, blackDuckServerConfig);
}
use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.
the class ProductBoot method boot.
public ProductRunData boot(BlackDuckDecision blackDuckDecision, DetectToolFilter detectToolFilter) throws DetectUserFriendlyException {
if (!blackDuckDecision.shouldRun()) {
throw new DetectUserFriendlyException("Your environment was not sufficiently configured to run Black Duck. See online help at: https://detect.synopsys.com/doc/", ExitCodeType.FAILURE_CONFIGURATION);
}
logger.debug("Detect product boot start.");
BlackDuckRunData blackDuckRunData = getBlackDuckRunData(blackDuckDecision, productBootFactory, blackDuckConnectivityChecker, productBootOptions, analyticsConfigurationService);
if (productBootOptions.isTestConnections()) {
logger.debug(String.format("%s is set to 'true' so Detect will not run.", DetectProperties.DETECT_TEST_CONNECTION.getName()));
return null;
}
logger.debug("Detect product boot completed.");
return new ProductRunData(blackDuckRunData, detectToolFilter);
}
use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.
the class ProductBoot method getBlackDuckRunData.
@Nullable
private BlackDuckRunData getBlackDuckRunData(BlackDuckDecision blackDuckDecision, ProductBootFactory productBootFactory, BlackDuckConnectivityChecker blackDuckConnectivityChecker, ProductBootOptions productBootOptions, AnalyticsConfigurationService analyticsConfigurationService) throws DetectUserFriendlyException {
if (!blackDuckDecision.shouldRun()) {
return null;
}
if (blackDuckDecision.isOffline()) {
return BlackDuckRunData.offline();
}
logger.debug("Will boot Black Duck product.");
BlackDuckServerConfig blackDuckServerConfig = productBootFactory.createBlackDuckServerConfig();
BlackDuckConnectivityResult blackDuckConnectivityResult = blackDuckConnectivityChecker.determineConnectivity(blackDuckServerConfig);
if (blackDuckConnectivityResult.isSuccessfullyConnected()) {
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckConnectivityResult.getBlackDuckServicesFactory();
if (shouldUsePhoneHome(analyticsConfigurationService, blackDuckServicesFactory.getApiDiscovery(), blackDuckServicesFactory.getBlackDuckApiClient())) {
PhoneHomeManager phoneHomeManager = productBootFactory.createPhoneHomeManager(blackDuckServicesFactory);
return BlackDuckRunData.online(blackDuckDecision.scanMode(), blackDuckServicesFactory, phoneHomeManager, blackDuckConnectivityResult.getBlackDuckServerConfig());
} else {
logger.debug("Skipping phone home due to Black Duck global settings.");
return BlackDuckRunData.onlineNoPhoneHome(blackDuckDecision.scanMode(), blackDuckServicesFactory, blackDuckConnectivityResult.getBlackDuckServerConfig());
}
} else {
if (productBootOptions.isIgnoreConnectionFailures()) {
logger.info(String.format("Failed to connect to Black Duck: %s", blackDuckConnectivityResult.getFailureReason()));
logger.info(String.format("%s is set to 'true' so Detect will simply disable the Black Duck product.", DetectProperties.DETECT_IGNORE_CONNECTION_FAILURES.getName()));
return null;
} else {
throw new DetectUserFriendlyException("Could not communicate with Black Duck: " + blackDuckConnectivityResult.getFailureReason(), ExitCodeType.FAILURE_BLACKDUCK_CONNECTIVITY);
}
}
}
use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.
the class ExceptionUtility method logException.
public void logException(Exception e) {
if (e instanceof OperationException) {
OperationException operationException = (OperationException) e;
logException(operationException.getException());
} else if (e instanceof DetectUserFriendlyException) {
if (e.getCause() != null) {
logger.debug(e.getCause().getMessage(), e.getCause());
}
logger.error(e.getMessage());
} else if (e instanceof BlackDuckTimeoutExceededException) {
logger.error(BLACKDUCK_TIMEOUT_ERROR_MESSAGE);
logger.error(e.getMessage());
} else if (e instanceof BlackDuckApiException) {
BlackDuckApiException be = (BlackDuckApiException) e;
logger.error(BLACKDUCK_ERROR_MESSAGE);
logger.error(be.getMessage());
logger.debug(be.getBlackDuckErrorCode());
logger.error(be.getOriginalIntegrationRestException().getMessage());
} else if (e instanceof IntegrationRestException) {
logger.error(BLACKDUCK_ERROR_MESSAGE);
logger.debug(e.getMessage(), e);
} else if (e instanceof IntegrationException) {
logger.error(BLACKDUCK_ERROR_MESSAGE);
logger.debug(e.getMessage(), e);
} else if (e instanceof InvalidPropertyException) {
logger.error("A configuration error occured");
logger.debug(e.getMessage(), e);
} else {
logUnrecognizedException(e);
}
}
Aggregations