use of com.synopsys.integration.executable.ExecutableRunnerException in project synopsys-detect by blackducksoftware.
the class FilePathGenerator method generateDepsMkFile.
private Optional<File> generateDepsMkFile(File workingDir, CompileCommand compileCommand) {
String depsMkFilename = deriveDependenciesListFilename(compileCommand);
File depsMkFile = new File(workingDir, depsMkFilename);
Map<String, String> optionOverrides = new HashMap<>(1);
optionOverrides.put(COMPILER_OUTPUT_FILE_OPTION, REPLACEMENT_OUTPUT_FILENAME);
try {
List<String> command = commandParser.parseCommand(compileCommand, optionOverrides);
command.addAll(Arrays.asList("-M", "-MF", depsMkFile.getAbsolutePath()));
Executable executable = Executable.create(new File(compileCommand.getDirectory()), Collections.emptyMap(), command);
executableRunner.execute(executable);
} catch (ExecutableRunnerException e) {
logger.debug(String.format("Error generating dependencies file for command '%s': %s", compileCommand.getCommand(), e.getMessage()));
return Optional.empty();
}
return Optional.of(depsMkFile);
}
use of com.synopsys.integration.executable.ExecutableRunnerException in project synopsys-detect by blackducksoftware.
the class DpkgVersionResolver method resolvePackageVersion.
public Optional<String> resolvePackageVersion(ClangPackageManagerInfo currentPackageManager, DetectableExecutableRunner executableRunner, File workingDirectory, String packageName) {
try {
List<String> args = new ArrayList<>(currentPackageManager.getPkgInfoArgs().get());
args.add(packageName);
ExecutableOutput packageStatusOutput = executableRunner.execute(workingDirectory, currentPackageManager.getPkgMgrCmdString(), args);
logger.debug(String.format("packageStatusOutput: %s", packageStatusOutput));
return parsePackageVersionFromStatusOutput(packageName, packageStatusOutput.getStandardOutput());
} catch (ExecutableRunnerException e) {
logger.error(String.format("Error executing %s to get package info: %s", currentPackageManager.getPkgMgrName(), e.getMessage()));
}
return Optional.empty();
}
use of com.synopsys.integration.executable.ExecutableRunnerException in project synopsys-detect by blackducksoftware.
the class GoModCliExtractorTest method handleGoModWhyExceptionTest.
@Test
public void handleGoModWhyExceptionTest() throws ExecutableRunnerException, ExecutableFailedException, DetectableException {
DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
File directory = new File("");
ExecutableTarget goExe = ExecutableTarget.forFile(new File(""));
Answer<ExecutableOutput> executableAnswer = new Answer<ExecutableOutput>() {
String[] goListArgs = { "list", "-m", "-json" };
String[] goListJsonArgs = { "list", "-m", "-json", "all" };
String[] goModGraphArgs = { "mod", "graph" };
String[] goModWhyArgs = { "mod", "why", "-m", "all" };
@Override
public ExecutableOutput answer(InvocationOnMock invocation) throws Throwable {
Executable executable = invocation.getArgument(0, Executable.class);
List<String> commandLine = executable.getCommandWithArguments();
ExecutableOutput result = null;
if (commandLine.containsAll(Arrays.asList(goListJsonArgs))) {
result = goListJsonOutput();
} else if (commandLine.containsAll(Arrays.asList(goListArgs))) {
result = goListOutput();
} else if (commandLine.containsAll(Arrays.asList(goModGraphArgs))) {
result = goModGraphOutput();
} else if (commandLine.containsAll(Arrays.asList(goModWhyArgs))) {
throw new ExecutableRunnerException(new DetectableException("Unit Test Go Mod Why error"));
} else {
result = new ExecutableOutput(0, "", "");
}
return result;
}
};
GoModCliExtractor goModCliExtractor = buildGoModCliExtractor(executableRunner, executableAnswer);
boolean wasSuccessful = true;
Extraction extraction = goModCliExtractor.extract(directory, goExe);
if (extraction.getError() instanceof ArrayIndexOutOfBoundsException) {
wasSuccessful = false;
}
Assertions.assertTrue(wasSuccessful);
}
use of com.synopsys.integration.executable.ExecutableRunnerException 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.ExecutableRunnerException in project synopsys-detect by blackducksoftware.
the class ExtractionEvaluatorTest method createEvaluationMocks.
private DetectorEvaluation createEvaluationMocks(DetectorEvaluationOptions evaluationOptions, DetectorEvaluationTree detectorEvaluationTree, boolean extractionExists, boolean throwException) throws DetectableException, ExecutableFailedException, IOException, CycleDetectedException, MissingExternalIdException, ExecutableRunnerException, ParserConfigurationException, SAXException {
ExtractionEnvironment extractionEnvironment = Mockito.mock(ExtractionEnvironment.class);
DetectorEvaluation detectorEvaluation = Mockito.mock(DetectorEvaluation.class);
Detectable detectable = Mockito.mock(Detectable.class);
DetectableResult detectableExtractableResult = Mockito.mock(DetectableResult.class);
Mockito.when(detectableExtractableResult.getPassed()).thenReturn(true);
Mockito.when(detectableExtractableResult.toDescription()).thenReturn("test detectable");
Mockito.when(detectable.extractable()).thenReturn(detectableExtractableResult);
Mockito.when(detectorEvaluation.getDetectable()).thenReturn(detectable);
Mockito.when(detectorEvaluation.getExtractionEnvironment()).thenReturn(extractionEnvironment);
Mockito.when(detectorEvaluation.isSearchable()).thenReturn(true);
Mockito.when(detectorEvaluation.isApplicable()).thenReturn(true);
Mockito.when(detectorEvaluation.isExtractable()).thenReturn(true);
List<DetectorEvaluation> detectorEvaluations = Collections.singletonList(detectorEvaluation);
Mockito.when(detectorEvaluationTree.getOrderedEvaluations()).thenReturn(detectorEvaluations);
DetectorRuleSet detectorRuleSet = Mockito.mock(DetectorRuleSet.class);
Mockito.when(detectorEvaluationTree.getDetectorRuleSet()).thenReturn(detectorRuleSet);
DetectorRule detectorRule = Mockito.mock(DetectorRule.class);
Mockito.when(detectorRule.getDescriptiveName()).thenReturn("test rule");
Mockito.when(detectorEvaluation.getDetectorRule()).thenReturn(detectorRule);
Mockito.when(detectorEvaluationTree.getDepthFromRoot()).thenReturn(0);
Mockito.when(evaluationOptions.isForceNested()).thenReturn(true);
Predicate<DetectorRule> rulePredicate = it -> true;
Mockito.when(evaluationOptions.getDetectorFilter()).thenReturn(rulePredicate);
Mockito.when(detectorRule.createDetectable(Mockito.any(DetectableEnvironment.class))).thenReturn(detectable);
Mockito.when(detectable.applicable()).thenReturn(new PassedDetectableResult());
if (throwException) {
Mockito.when(detectable.extract(Mockito.eq(extractionEnvironment))).thenThrow(new RuntimeException("JUnit expected exception"));
} else {
Mockito.when(detectable.extract(Mockito.eq(extractionEnvironment))).thenReturn(new Extraction.Builder().success().build());
}
return detectorEvaluation;
}
Aggregations