Search in sources :

Example 1 with DetectUserFriendlyException

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);
    }
}
Also used : DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) IOException(java.io.IOException)

Example 2 with DetectUserFriendlyException

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());
}
Also used : DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException)

Example 3 with DetectUserFriendlyException

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;
}
Also used : ProxyInfo(com.blackducksoftware.integration.hub.proxy.ProxyInfo) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) ProxyInfoBuilder(com.blackducksoftware.integration.hub.proxy.ProxyInfoBuilder)

Example 4 with DetectUserFriendlyException

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();
}
Also used : DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) ExcludedIncludedFilter(com.blackducksoftware.integration.util.ExcludedIncludedFilter) MutablePropertySources(org.springframework.core.env.MutablePropertySources) File(java.io.File)

Example 5 with DetectUserFriendlyException

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);
    }
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) UnauthenticatedRestConnectionBuilder(com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnectionBuilder) CLIDownloadUtility(com.blackducksoftware.integration.hub.cli.CLIDownloadUtility) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) IOException(java.io.IOException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException)

Aggregations

DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)9 File (java.io.File)4 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)3 IOException (java.io.IOException)3 HubService (com.blackducksoftware.integration.hub.service.HubService)2 EncryptionException (com.blackducksoftware.integration.exception.EncryptionException)1 CurrentVersionView (com.blackducksoftware.integration.hub.api.generated.response.CurrentVersionView)1 CLIDownloadUtility (com.blackducksoftware.integration.hub.cli.CLIDownloadUtility)1 ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)1 DoesNotExistException (com.blackducksoftware.integration.hub.exception.DoesNotExistException)1 HubTimeoutExceededException (com.blackducksoftware.integration.hub.exception.HubTimeoutExceededException)1 ProxyInfo (com.blackducksoftware.integration.hub.proxy.ProxyInfo)1 ProxyInfoBuilder (com.blackducksoftware.integration.hub.proxy.ProxyInfoBuilder)1 Request (com.blackducksoftware.integration.hub.request.Request)1 Response (com.blackducksoftware.integration.hub.request.Response)1 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)1 UnauthenticatedRestConnection (com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection)1 UnauthenticatedRestConnectionBuilder (com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnectionBuilder)1 IntegrationRestException (com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException)1 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)1