use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.
the class GitDetectableCliTest method setup.
@Override
public void setup() throws IOException {
addDirectory(Paths.get(".git"));
String gitRemoteUrlOutput = "https://github.com/blackducksoftware/synopsys-detect";
ExecutableOutput gitConfigExecutableOutput = new ExecutableOutput(0, gitRemoteUrlOutput, "");
addExecutableOutput(gitConfigExecutableOutput, "git", "config", "--get", "remote.origin.url");
String gitBranchOutput = "branch-version";
ExecutableOutput gitBranchExecutableOutput = new ExecutableOutput(0, gitBranchOutput, "");
addExecutableOutput(gitBranchExecutableOutput, "git", "rev-parse", "--abbrev-ref", "HEAD");
}
use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.
the class DartPubDepsDetectableTest method setup.
@Override
protected void setup() throws IOException {
addFile(Paths.get("pubspec.lock"));
addFile(Paths.get("pubspec.yaml"));
ExecutableOutput executableOutput = createStandardOutput("http_parser 3.1.5-dev", "|-- pedantic 1.9.2", "| '-- meta...", "|-- source_span 1.7.0", "| |-- meta 1.2.3", "| |-- path 1.7.0");
addExecutableOutput(executableOutput, new File("dart").getAbsolutePath(), "pub", "deps");
}
use of com.synopsys.integration.executable.ExecutableOutput 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.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.
the class NpmCliExtractor method extract.
public Extraction extract(File directory, ExecutableTarget npmExe, @Nullable String npmArguments, File packageJsonFile) {
toolVersionLogger.log(directory, npmExe);
PackageJson packageJson;
try {
packageJson = parsePackageJson(packageJsonFile);
} catch (IOException e) {
return new Extraction.Builder().exception(e).build();
}
List<String> exeArgs = new ArrayList<>();
exeArgs.add("ls");
exeArgs.add("-json");
Optional.ofNullable(npmArguments).map(arg -> arg.split(" ")).ifPresent(additionalArguments -> exeArgs.addAll(Arrays.asList(additionalArguments)));
ExecutableOutput npmLsOutput;
try {
npmLsOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, npmExe, exeArgs));
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
String standardOutput = npmLsOutput.getStandardOutput();
String errorOutput = npmLsOutput.getErrorOutput();
if (StringUtils.isNotBlank(errorOutput)) {
logger.error("Error when running npm ls -json command");
logger.error(errorOutput);
return new Extraction.Builder().failure("Npm wrote to stderr while running npm ls.").build();
} else if (StringUtils.isNotBlank(standardOutput)) {
logger.debug("Parsing npm ls file.");
logger.debug(standardOutput);
NpmPackagerResult result = npmCliParser.generateCodeLocation(standardOutput, packageJson);
String projectName = result.getProjectName() != null ? result.getProjectName() : packageJson.name;
String projectVersion = result.getProjectVersion() != null ? result.getProjectVersion() : packageJson.version;
return new Extraction.Builder().success(result.getCodeLocation()).projectName(projectName).projectVersion(projectVersion).build();
} else {
logger.error("Nothing returned from npm ls -json command");
return new Extraction.Builder().failure("Npm returned error after running npm ls.").build();
}
}
use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.
the class MavenCliExtractor method extract.
// TODO: Limit 'extractors' to 'execute' and 'read', delegate all other work.
public Extraction extract(File directory, ExecutableTarget mavenExe, MavenCliExtractorOptions mavenCliExtractorOptions) throws ExecutableFailedException {
toolVersionLogger.log(directory, mavenExe);
List<String> commandArguments = commandParser.parseCommandString(mavenCliExtractorOptions.getMavenBuildCommand().orElse("")).stream().filter(arg -> !arg.equals("dependency:tree")).collect(Collectors.toList());
commandArguments.add("dependency:tree");
// Force maven to use a single thread to ensure the tree output is in the correct order.
commandArguments.add("-T1");
ExecutableOutput mvnExecutableResult = executableRunner.executeSuccessfully(ExecutableUtils.createFromTarget(directory, mavenExe, commandArguments));
List<String> mavenOutput = mvnExecutableResult.getStandardOutputAsList();
List<String> excludedScopes = mavenCliExtractorOptions.getMavenExcludedScopes();
List<String> includedScopes = mavenCliExtractorOptions.getMavenIncludedScopes();
List<String> excludedModules = mavenCliExtractorOptions.getMavenExcludedModules();
List<String> includedModules = mavenCliExtractorOptions.getMavenIncludedModules();
List<MavenParseResult> mavenResults = mavenCodeLocationPackager.extractCodeLocations(directory.toString(), mavenOutput, excludedScopes, includedScopes, excludedModules, includedModules);
List<CodeLocation> codeLocations = Bds.of(mavenResults).map(MavenParseResult::getCodeLocation).toList();
Optional<MavenParseResult> firstWithName = Bds.of(mavenResults).firstFiltered(it -> StringUtils.isNotBlank(it.getProjectName()));
Extraction.Builder builder = new Extraction.Builder().success(codeLocations);
if (firstWithName.isPresent()) {
builder.projectName(firstWithName.get().getProjectName());
builder.projectVersion(firstWithName.get().getProjectVersion());
}
return builder.build();
}
Aggregations