Search in sources :

Example 6 with DetectUserFriendlyException

use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.

the class CreateScanBatchRunnerWithCustomUrl method createScanBatchRunner.

public ScanBatchRunner createScanBatchRunner(String providedUrl, ConnectionDetails connectionDetails, BlackDuckRegistrationService registrationService, File installDirectory) throws DetectUserFriendlyException {
    logger.debug("Signature scanner will use the provided url to download/update the scanner.");
    HttpUrl baseUrl;
    try {
        baseUrl = new HttpUrl(providedUrl);
    } catch (IntegrationException e) {
        throw new DetectUserFriendlyException("User provided scanner install url could not be parsed: " + providedUrl, e, ExitCodeType.FAILURE_CONFIGURATION);
    }
    CleanupZipExpander cleanupZipExpander = new CleanupZipExpander(slf4jIntLogger);
    SignatureScannerClient signatureScannerClient = new SignatureScannerClient(new SilentIntLogger(), connectionDetails.getGson(), connectionDetails.getTimeout().intValue(), connectionDetails.getAlwaysTrust(), connectionDetails.getProxyInformation());
    KeyStoreHelper keyStoreHelper = new KeyStoreHelper(slf4jIntLogger);
    ScannerZipInstaller scannerZipInstaller = new ScannerZipInstaller(slf4jIntLogger, signatureScannerClient, registrationService, cleanupZipExpander, scanPathsUtility, keyStoreHelper, baseUrl, operatingSystemType, installDirectory);
    return ScanBatchRunner.createComplete(intEnvironmentVariables, scanPathsUtility, scanCommandRunner, scannerZipInstaller);
}
Also used : SilentIntLogger(com.synopsys.integration.log.SilentIntLogger) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) IntegrationException(com.synopsys.integration.exception.IntegrationException) KeyStoreHelper(com.synopsys.integration.blackduck.keystore.KeyStoreHelper) ScannerZipInstaller(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScannerZipInstaller) SignatureScannerClient(com.synopsys.integration.blackduck.http.client.SignatureScannerClient) HttpUrl(com.synopsys.integration.rest.HttpUrl) CleanupZipExpander(com.synopsys.integration.util.CleanupZipExpander)

Example 7 with DetectUserFriendlyException

use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.

the class CreateScanBatchOperation method createScanBatch.

private ScanBatch createScanBatch(NameVersion projectNameVersion, List<SignatureScanPath> signatureScanPaths, @Nullable BlackDuckServerConfig blackDuckServerConfig, @Nullable DockerTargetData dockerTargetData) throws DetectUserFriendlyException {
    ScanBatchBuilder scanJobBuilder = new ScanBatchBuilder();
    scanJobBuilder.scanMemoryInMegabytes(signatureScannerOptions.getScanMemory());
    scanJobBuilder.outputDirectory(directoryManager.getScanOutputDirectory());
    scanJobBuilder.dryRun(signatureScannerOptions.getDryRun());
    scanJobBuilder.cleanupOutput(false);
    signatureScannerOptions.getSnippetMatching().ifPresent(scanJobBuilder::snippetMatching);
    scanJobBuilder.uploadSource(signatureScannerOptions.getUploadSource());
    scanJobBuilder.licenseSearch(signatureScannerOptions.getLicenseSearch());
    scanJobBuilder.copyrightSearch(signatureScannerOptions.getCopyrightSearch());
    signatureScannerOptions.getAdditionalArguments().ifPresent(scanJobBuilder::additionalScanArguments);
    String projectName = projectNameVersion.getName();
    String projectVersionName = projectNameVersion.getVersion();
    scanJobBuilder.projectAndVersionNames(projectName, projectVersionName);
    signatureScannerOptions.getIndividualFileMatching().ifPresent(scanJobBuilder::individualFileMatching);
    File sourcePath = directoryManager.getSourceDirectory();
    for (SignatureScanPath scanPath : signatureScanPaths) {
        File dockerTarget = null;
        if (dockerTargetData != null) {
            dockerTarget = dockerTargetData.getSquashedImage().orElse(dockerTargetData.getProvidedImageTar().orElse(null));
        }
        String codeLocationName = codeLocationNameManager.createScanCodeLocationName(sourcePath, scanPath.getTargetPath(), dockerTarget, projectName, projectVersionName);
        scanJobBuilder.addTarget(ScanTarget.createBasicTarget(scanPath.getTargetCanonicalPath(), scanPath.getExclusions(), codeLocationName));
    }
    // when offline, we must still call this with 'null' as a workaround for library issues, so offline scanner must be created with this set to null.
    scanJobBuilder.fromBlackDuckServerConfig(blackDuckServerConfig);
    try {
        return scanJobBuilder.build();
    } catch (IllegalArgumentException e) {
        throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_CONFIGURATION);
    }
}
Also used : DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) SignatureScanPath(com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath) ScanBatchBuilder(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchBuilder) File(java.io.File)

Example 8 with DetectUserFriendlyException

use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.

the class OperationFactory method waitForCodeLocations.

public void waitForCodeLocations(BlackDuckRunData blackDuckRunData, CodeLocationWaitData codeLocationWaitData, NameVersion projectNameVersion) throws OperationException {
    auditLog.namedPublic("Wait for Code Locations", () -> {
        // TODO fix this when NotificationTaskRange doesn't include task start time
        // ekerwin - The start time of the task is the earliest time a code location was created.
        // In order to wait the full timeout, we have to not use that start time and instead use now().
        // TODO: Handle the possible null pointer here.
        NotificationTaskRange notificationTaskRange = new NotificationTaskRange(System.currentTimeMillis(), codeLocationWaitData.getNotificationRange().getStartDate(), codeLocationWaitData.getNotificationRange().getEndDate());
        CodeLocationCreationService codeLocationCreationService = blackDuckRunData.getBlackDuckServicesFactory().createCodeLocationCreationService();
        CodeLocationWaitResult result = codeLocationCreationService.waitForCodeLocations(notificationTaskRange, projectNameVersion, codeLocationWaitData.getCodeLocationNames(), codeLocationWaitData.getExpectedNotificationCount(), detectConfigurationFactory.findTimeoutInSeconds());
        if (result.getStatus() == CodeLocationWaitResult.Status.PARTIAL) {
            throw new DetectUserFriendlyException(result.getErrorMessage().orElse("Timed out waiting for code locations to finish on the Black Duck server."), ExitCodeType.FAILURE_TIMEOUT);
        }
    });
}
Also used : CodeLocationCreationService(com.synopsys.integration.blackduck.codelocation.CodeLocationCreationService) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) CodeLocationWaitResult(com.synopsys.integration.blackduck.codelocation.CodeLocationWaitResult) NotificationTaskRange(com.synopsys.integration.blackduck.service.model.NotificationTaskRange)

Example 9 with DetectUserFriendlyException

use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.

the class AirGapFontLocator method locateFontFile.

private File locateFontFile(String defaultFontFileName, String customFontDirectoryName) throws DetectUserFriendlyException {
    File fontFile = airGapPaths.getFontsAirGapDirectory().map(fontAirGapDirectory -> locateFontFile(fontAirGapDirectory, defaultFontFileName, customFontDirectoryName)).orElseThrow(() -> new DetectUserFriendlyException(String.format("Could not get the font file %s from the air gap path", defaultFontFileName), ExitCodeType.FAILURE_GENERAL_ERROR));
    logger.debug("Locating font file {}", fontFile.getAbsolutePath());
    return fontFile;
}
Also used : DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) Nullable(org.jetbrains.annotations.Nullable) ExitCodeType(com.synopsys.integration.detect.configuration.enumeration.ExitCodeType) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) AirGapInspectorPaths(com.synopsys.integration.detect.workflow.airgap.AirGapInspectorPaths) File(java.io.File) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) File(java.io.File)

Example 10 with DetectUserFriendlyException

use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.

the class OnlineDetectFontLocator method locateFontFile.

private File locateFontFile(String fontFileName, String customFontDirectoryName) throws DetectUserFriendlyException {
    try {
        File fontsDirectory = directoryManager.getPermanentDirectory("fonts");
        File customFontFile = locateCustomFontFile(fontsDirectory, customFontDirectoryName);
        File fontFile;
        if (customFontFile != null) {
            fontFile = customFontFile;
        } else {
            fontFile = new File(fontsDirectory, fontFileName);
        }
        logger.debug("Locating font file {}", fontFile.getAbsolutePath());
        if (!fontFile.exists()) {
            detectFontInstaller.installFonts(fontsDirectory);
        }
        return fontFile;
    } catch (Exception e) {
        throw new DetectUserFriendlyException("Unable to locate font files or install fonts from Artifactory.", e, ExitCodeType.FAILURE_GENERAL_ERROR);
    }
}
Also used : DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) File(java.io.File) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException)

Aggregations

DetectUserFriendlyException (com.synopsys.integration.detect.configuration.DetectUserFriendlyException)33 File (java.io.File)14 IntegrationException (com.synopsys.integration.exception.IntegrationException)12 IOException (java.io.IOException)12 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)5 ExitCodeType (com.synopsys.integration.detect.configuration.enumeration.ExitCodeType)3 ArrayList (java.util.ArrayList)3 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)2 SpdxCreator (com.synopsys.integration.bdio.model.SpdxCreator)2 Bdio2Writer (com.synopsys.integration.blackduck.bdio2.util.Bdio2Writer)2 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)2 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)2 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)2 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)2 ProductRunData (com.synopsys.integration.detect.lifecycle.run.data.ProductRunData)2 CustomFieldOperation (com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldOperation)2 CustomFieldView (com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldView)2 SilentIntLogger (com.synopsys.integration.log.SilentIntLogger)2 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)2 FileOutputStream (java.io.FileOutputStream)2