Search in sources :

Example 11 with DetectUserFriendlyException

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

the class AirGapCreator method createAirGapZip.

public File createAirGapZip(AirGapType airGapType, File outputPath, String gradleInspectorVersion) throws DetectUserFriendlyException {
    try {
        logger.info("");
        logger.info(ReportConstants.RUN_SEPARATOR);
        logger.info(ReportConstants.RUN_SEPARATOR);
        logger.info("Detect is in Air Gap Creation mode.");
        logger.info("Detect will create an air gap of itself and then exit.");
        logger.info("The created air gap zip will not be cleaned up.");
        logger.info("Specify desired air gap zip type after the -z argument. Available options are FULL or NO_DOCKER. Default is FULL.");
        logger.info(ReportConstants.RUN_SEPARATOR);
        logger.info(ReportConstants.RUN_SEPARATOR);
        logger.info("");
        File detectJar = airGapPathFinder.findDetectJar();
        if (detectJar == null) {
            throw new DetectUserFriendlyException("To create an air gap zip, Detect must be run from a jar and be able to find that jar. Detect was unable to find it's own jar.", ExitCodeType.FAILURE_CONFIGURATION);
        }
        logger.info("The detect jar location: " + detectJar.getCanonicalPath());
        logger.info("Creating zip at location: " + outputPath);
        String basename = FilenameUtils.removeExtension(detectJar.getName());
        String airGapName = basename + "-air-gap";
        if (airGapType == AirGapType.NO_DOCKER) {
            airGapName = airGapName + "-no-docker";
        }
        File target = new File(outputPath, airGapName + ".zip");
        File installFolder = new File(outputPath, basename);
        logger.info("Will build the zip in the following folder: " + installFolder.getCanonicalPath());
        logger.info("Installing dependencies.");
        installAllAirGapDependencies(airGapType, installFolder, gradleInspectorVersion);
        logger.info("Copying detect jar.");
        FileUtils.copyFile(detectJar, new File(installFolder, detectJar.getName()));
        logger.info("Zipping into: " + target.getCanonicalPath());
        ZipUtil.pack(installFolder, target);
        logger.info("Cleaning up working directory: " + installFolder.getCanonicalPath());
        FileUtils.deleteDirectory(installFolder);
        logger.info(ReportConstants.RUN_SEPARATOR);
        String result = target.getCanonicalPath();
        logger.info("Successfully created air gap zip: " + result);
        logger.info(ReportConstants.RUN_SEPARATOR);
        eventSystem.publishEvent(Event.ResultProduced, new AirGapDetectResult(result));
        return target;
    } catch (IOException e) {
        throw new DetectUserFriendlyException("Failed to create detect air gap zip.", e, ExitCodeType.FAILURE_UNKNOWN_ERROR);
    }
}
Also used : AirGapDetectResult(com.synopsys.integration.detect.workflow.result.AirGapDetectResult) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) IOException(java.io.IOException) File(java.io.File)

Example 12 with DetectUserFriendlyException

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

the class GradleAirGapCreator method installGradleDependencies.

public void installGradleDependencies(File gradleTemp, File gradleTarget, String inspectorVersion) throws DetectUserFriendlyException {
    logger.info("Checking for gradle on the path.");
    ExecutableTarget gradle;
    try {
        gradle = gradleResolver.resolveGradle(new DetectableEnvironment(gradleTemp));
        if (gradle == null) {
            throw new DetectUserFriendlyException("Gradle must be on the path to make an Air Gap zip.", ExitCodeType.FAILURE_CONFIGURATION);
        }
    } catch (DetectableException e) {
        throw new DetectUserFriendlyException("An error occurred while finding Gradle which is needed to make an Air Gap zip.", e, ExitCodeType.FAILURE_CONFIGURATION);
    }
    File gradleOutput = new File(gradleTemp, "dependencies");
    logger.info("Using temporary gradle dependency directory: " + gradleOutput);
    File buildGradle = new File(gradleTemp, "build.gradle");
    File settingsGradle = new File(gradleTemp, "settings.gradle");
    logger.info("Using temporary gradle build file: " + buildGradle);
    logger.info("Using temporary gradle settings file: " + settingsGradle);
    FileUtil.createMissingParentDirectories(buildGradle);
    FileUtil.createMissingParentDirectories(settingsGradle);
    logger.info("Writing to temporary gradle build file.");
    try {
        Map<String, String> gradleScriptData = new HashMap<>();
        gradleScriptData.put("gradleOutput", StringEscapeUtils.escapeJava(gradleOutput.getCanonicalPath()));
        Template gradleScriptTemplate = configuration.getTemplate("create-gradle-airgap-script.ftl");
        try (Writer fileWriter = new FileWriter(buildGradle)) {
            gradleScriptTemplate.process(gradleScriptData, fileWriter);
        }
        FileUtils.writeStringToFile(settingsGradle, "", StandardCharsets.UTF_8);
    } catch (IOException | TemplateException e) {
        throw new DetectUserFriendlyException("An error occurred creating the temporary build.gradle while creating the Air Gap zip.", e, ExitCodeType.FAILURE_CONFIGURATION);
    }
    logger.info("Invoking gradle install on temporary directory.");
    try {
        ExecutableOutput executableOutput = executableRunner.execute(ExecutableUtils.createFromTarget(gradleTemp, gradle, "installDependencies"));
        if (executableOutput.getReturnCode() != 0) {
            throw new DetectUserFriendlyException("Gradle returned a non-zero exit code while installing Air Gap dependencies.", ExitCodeType.FAILURE_CONFIGURATION);
        }
    } catch (ExecutableRunnerException e) {
        throw new DetectUserFriendlyException("An error occurred using Gradle to make an Air Gap zip.", e, ExitCodeType.FAILURE_CONFIGURATION);
    }
    try {
        logger.info("Moving generated dependencies to final gradle folder: " + gradleTarget.getCanonicalPath());
        FileUtils.moveDirectory(gradleOutput, gradleTarget);
        FileUtils.deleteDirectory(gradleTemp);
    } catch (IOException e) {
        throw new DetectUserFriendlyException("An error occurred moving gradle dependencies to Air Gap folder.", ExitCodeType.FAILURE_CONFIGURATION);
    }
}
Also used : HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) FileWriter(java.io.FileWriter) IOException(java.io.IOException) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) Template(freemarker.template.Template) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) File(java.io.File) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 13 with DetectUserFriendlyException

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

the class NugetInspectorAirGapCreator method install.

private void install(File container, String targetDirectory, String propertyName) throws DetectUserFriendlyException {
    try {
        File destination = new File(container, targetDirectory);
        // actually downloads it to 'destination/zipName'
        File downloaded = inspectorInstaller.downloadZip(propertyName, destination);
        // move 'destination/zipName' to 'destination'
        FileUtils.copyDirectory(downloaded, destination);
        // delete 'destination/zipName'
        FileUtils.deleteDirectory(downloaded);
    } catch (DetectableException | IOException e) {
        throw new DetectUserFriendlyException("An error occurred installing project-inspector to the " + targetDirectory + " folder.", e, ExitCodeType.FAILURE_GENERAL_ERROR);
    }
}
Also used : DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) IOException(java.io.IOException) File(java.io.File) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 14 with DetectUserFriendlyException

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

the class ProjectInspectorAirGapCreator method install.

private void install(File container, String targetDirectory, String propertyName) throws DetectUserFriendlyException {
    try {
        File destination = new File(container, targetDirectory);
        // actually downloads it to 'destination/zipName'
        File downloaded = projectInspectorInstaller.downloadZip(propertyName, destination);
        // move 'destination/zipName' to 'destination'
        FileUtils.copyDirectory(downloaded, destination);
        // delete 'destination/zipName'
        FileUtils.deleteDirectory(downloaded);
    } catch (DetectableException | IOException e) {
        throw new DetectUserFriendlyException("An error occurred installing project-inspector to the " + targetDirectory + " folder.", e, ExitCodeType.FAILURE_GENERAL_ERROR);
    }
}
Also used : DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) IOException(java.io.IOException) File(java.io.File) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 15 with DetectUserFriendlyException

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

the class FindProjectGroupOperation method findProjectGroup.

public HttpUrl findProjectGroup(String projectGroupName) throws IntegrationException, DetectUserFriendlyException {
    BlackDuckRequestBuilder blackDuckRequestBuilder = new BlackDuckRequestBuilder().commonGet().addBlackDuckQuery(new BlackDuckQuery("name", projectGroupName)).addBlackDuckFilter(BlackDuckRequestFilter.createFilterWithSingleValue("exactName", "true"));
    BlackDuckMultipleRequest<ProjectGroupsView> requestMultiple = blackDuckRequestBuilder.buildBlackDuckRequest(projectGroupsResponses);
    List<ProjectGroupsView> response = blackDuckApiClient.getAllResponses(requestMultiple);
    if (response.size() != 1) {
        throw new DetectUserFriendlyException("Project Group Name must have exactly 1 match on Black Duck, instead '" + projectGroupName + "' had " + response.size() + " matches.", ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR);
    }
    ProjectGroupsView result = response.get(0);
    return result.getHref();
}
Also used : DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) ProjectGroupsView(com.synopsys.integration.blackduck.api.generated.view.ProjectGroupsView) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) BlackDuckQuery(com.synopsys.integration.blackduck.http.BlackDuckQuery)

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