Search in sources :

Example 1 with ExcludedIncludedFilter

use of com.blackducksoftware.integration.util.ExcludedIncludedFilter 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)

Aggregations

DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 ExcludedIncludedFilter (com.blackducksoftware.integration.util.ExcludedIncludedFilter)1 File (java.io.File)1 EnumerablePropertySource (org.springframework.core.env.EnumerablePropertySource)1 MutablePropertySources (org.springframework.core.env.MutablePropertySources)1