use of com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException in project hub-detect by blackducksoftware.
the class DetectProjectManager method writeBdioFile.
private void writeBdioFile(final File outputFile, final SimpleBdioDocument simpleBdioDocument) throws DetectUserFriendlyException {
try {
simpleBdioFactory.writeSimpleBdioDocumentToFile(outputFile, simpleBdioDocument);
logger.info(String.format("BDIO Generated: %s", outputFile.getAbsolutePath()));
} catch (final IOException e) {
throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_GENERAL_ERROR);
}
}
use of com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException in project hub-detect by blackducksoftware.
the class Application method populateExitCodeFromExceptionDetails.
private void populateExitCodeFromExceptionDetails(final Exception e) {
if (e instanceof DetectUserFriendlyException) {
if (e.getCause() != null) {
logger.debug(e.getCause().getMessage(), e.getCause());
}
final DetectUserFriendlyException friendlyException = (DetectUserFriendlyException) e;
exitCodeType = friendlyException.getExitCodeType();
} else if (e instanceof IntegrationException) {
logger.error("An unrecoverable error occurred - most likely this is due to your environment and/or configuration. Please double check the Hub Detect documentation: https://blackducksoftware.atlassian.net/wiki/x/Y7HtAg");
logger.debug(e.getMessage(), e);
exitCodeType = ExitCodeType.FAILURE_GENERAL_ERROR;
} else {
logger.error("An unknown/unexpected error occurred");
logger.debug(e.getMessage(), e);
exitCodeType = ExitCodeType.FAILURE_UNKNOWN_ERROR;
}
logger.error(e.getMessage());
}
use of com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException in project hub-detect by blackducksoftware.
the class DetectConfiguration method getHubProxyInfo.
public ProxyInfo getHubProxyInfo() throws DetectUserFriendlyException {
final ProxyInfoBuilder proxyInfoBuilder = new ProxyInfoBuilder();
proxyInfoBuilder.setHost(hubProxyHost);
proxyInfoBuilder.setPort(hubProxyPort);
proxyInfoBuilder.setUsername(hubProxyUsername);
proxyInfoBuilder.setPassword(hubProxyPassword);
proxyInfoBuilder.setNtlmDomain(hubProxyNtlmDomain);
proxyInfoBuilder.setNtlmWorkstation(hubProxyNtlmWorkstation);
ProxyInfo proxyInfo = ProxyInfo.NO_PROXY_INFO;
try {
proxyInfo = proxyInfoBuilder.build();
} catch (final IllegalStateException e) {
throw new DetectUserFriendlyException(String.format("Your proxy configuration is not valid: %s", e.getMessage()), e, ExitCodeType.FAILURE_PROXY_CONNECTIVITY);
}
return proxyInfo;
}
use of com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException in project hub-detect by blackducksoftware.
the class DetectConfiguration method init.
public void init() throws DetectUserFriendlyException, IOException, IllegalArgumentException, IllegalAccessException {
final String systemUserHome = System.getProperty("user.home");
if (resolveTildeInPaths) {
tildeInPathResolver.resolveTildeInAllPathFields(systemUserHome, this);
}
if (StringUtils.isBlank(sourcePath)) {
usingDefaultSourcePath = true;
sourcePath = System.getProperty("user.dir");
}
sourceDirectory = new File(sourcePath);
if (!sourceDirectory.exists() || !sourceDirectory.isDirectory()) {
throw new DetectUserFriendlyException("The source path ${sourcePath} either doesn't exist, isn't a directory, or doesn't have appropriate permissions.", ExitCodeType.FAILURE_GENERAL_ERROR);
}
// make sure the path is absolute
sourcePath = sourceDirectory.getCanonicalPath();
usingDefaultOutputPath = StringUtils.isBlank(outputDirectoryPath);
outputDirectoryPath = createDirectoryPath(outputDirectoryPath, systemUserHome, "blackduck");
bdioOutputDirectoryPath = createDirectoryPath(bdioOutputDirectoryPath, outputDirectoryPath, "bdio");
scanOutputDirectoryPath = createDirectoryPath(scanOutputDirectoryPath, outputDirectoryPath, "scan");
ensureDirectoryExists(outputDirectoryPath, "The system property 'user.home' will be used by default, but the output directory must exist.");
ensureDirectoryExists(bdioOutputDirectoryPath, "By default, the directory 'bdio' will be created in the outputDirectory, but the directory must exist.");
ensureDirectoryExists(scanOutputDirectoryPath, "By default, the directory 'scan' will be created in the outputDirectory, but the directory must exist.");
outputDirectory = new File(outputDirectoryPath);
nugetInspectorPackageName = nugetInspectorPackageName.trim();
nugetInspectorPackageVersion = nugetInspectorPackageVersion.trim();
final MutablePropertySources mutablePropertySources = configurableEnvironment.getPropertySources();
for (final PropertySource<?> propertySource : mutablePropertySources) {
if (propertySource instanceof EnumerablePropertySource) {
final EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) propertySource;
for (final String propertyName : enumerablePropertySource.getPropertyNames()) {
if (StringUtils.isNotBlank(propertyName) && propertyName.startsWith(DETECT_PROPERTY_PREFIX)) {
allDetectPropertyKeys.add(propertyName);
}
}
}
}
if (hubSignatureScannerParallelProcessors == -1) {
hubSignatureScannerParallelProcessors = Runtime.getRuntime().availableProcessors();
}
bomToolFilter = new ExcludedIncludedFilter(getExcludedBomToolTypes(), getIncludedBomToolTypes());
if (dockerBomTool.isBomToolApplicable() && bomToolFilter.shouldInclude(dockerBomTool.getBomToolType().toString())) {
configureForDocker();
}
if (hubSignatureScannerRelativePathsToExclude != null && hubSignatureScannerRelativePathsToExclude.length > 0) {
for (final String path : hubSignatureScannerRelativePathsToExclude) {
excludedScanPaths.add(new File(sourceDirectory, path).getCanonicalPath());
}
}
if (StringUtils.isNotBlank(hubSignatureScannerHostUrl) && StringUtils.isNotBlank(hubSignatureScannerOfflineLocalPath)) {
throw new DetectUserFriendlyException("You have provided both a hub signature scanner url AND a local hub signature scanner path. Only one of these properties can be set at a time. If both are used together, the *correct* source of the signature scanner can not be determined.", ExitCodeType.FAILURE_GENERAL_ERROR);
}
if (StringUtils.isNotBlank(hubSignatureScannerHostUrl)) {
logger.info("A hub signature scanner url was provided, which requires hub offline mode. Setting hub offline mode to true.");
hubOfflineMode = true;
}
if (StringUtils.isNotBlank(hubSignatureScannerOfflineLocalPath)) {
logger.info("A local hub signature scanner path was provided, which requires hub offline mode. Setting hub offline mode to true.");
hubOfflineMode = true;
}
if (gradleBomTool.isBomToolApplicable() && bomToolFilter.shouldInclude(gradleBomTool.getBomToolType().toString())) {
gradleInspectorVersion = gradleBomTool.getInspectorVersion();
}
if (nugetBomTool.isBomToolApplicable() && bomToolFilter.shouldInclude(nugetBomTool.getBomToolType().toString())) {
nugetInspectorPackageVersion = nugetBomTool.getInspectorVersion();
}
if (dockerBomTool.isBomToolApplicable() && bomToolFilter.shouldInclude(dockerBomTool.getBomToolType().toString())) {
dockerInspectorVersion = dockerBomTool.getInspectorVersion();
}
configureForPhoneHome();
}
use of com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException in project hub-detect by blackducksoftware.
the class OfflineScanner method installSignatureScannerFromUrl.
private void installSignatureScannerFromUrl(final IntLogger intLogger, final HubScanConfig hubScanConfig, final CIEnvironmentVariables ciEnvironmentVariables) throws DetectUserFriendlyException {
try {
OfflineScanner.logger.info(String.format("Attempting to download the signature scanner from %s", detectConfiguration.getHubSignatureScannerHostUrl()));
final UnauthenticatedRestConnectionBuilder restConnectionBuilder = new UnauthenticatedRestConnectionBuilder();
restConnectionBuilder.setBaseUrl(detectConfiguration.getHubSignatureScannerHostUrl());
restConnectionBuilder.setTimeout(detectConfiguration.getHubTimeout());
restConnectionBuilder.applyProxyInfo(detectConfiguration.getHubProxyInfo());
restConnectionBuilder.setLogger(intLogger);
final RestConnection restConnection = restConnectionBuilder.build();
final CLIDownloadUtility cliDownloadUtility = new CLIDownloadUtility(intLogger, restConnection);
cliDownloadUtility.performInstallation(hubScanConfig.getToolsDir(), ciEnvironmentVariables, detectConfiguration.getHubSignatureScannerHostUrl(), "unknown", "hub-detect");
} catch (final Exception e) {
throw new DetectUserFriendlyException(String.format("There was a problem downloading the signature scanner from %s: %s", detectConfiguration.getHubSignatureScannerHostUrl(), e.getMessage()), e, ExitCodeType.FAILURE_GENERAL_ERROR);
}
}
Aggregations