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);
}
}
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);
}
}
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);
}
}
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);
}
}
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();
}
Aggregations