use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class IntermediateStepParseValuesFromXml method process.
@Override
public List<String> process(List<String> input) throws DetectableException {
List<String> results = new ArrayList<>();
for (String xmlDoc : input) {
List<String> values;
try {
values = parseAttributeValuesWithGivenXPathQuery(xmlDoc, xPathToElement, targetAttributeName);
} catch (IOException | SAXException | ParserConfigurationException | XPathExpressionException e) {
String msg = String.format("Error parsing xml %s for xPath query %s, attribute name: %s", xmlDoc, xPathToElement, targetAttributeName);
logger.debug(msg);
throw new DetectableException(msg, e);
}
results.addAll(values);
}
return results;
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class GradleInspectorScriptCreator method createGradleInspector.
private File createGradleInspector(File targetFile, GradleInspectorScriptOptions scriptOptions, String airGapLibraryPaths) throws DetectableException {
logger.debug("Generating the gradle script file.");
Map<String, String> gradleScriptData = new HashMap<>();
gradleScriptData.put("airGapLibsPath", StringEscapeUtils.escapeJava(Optional.ofNullable(airGapLibraryPaths).orElse("")));
gradleScriptData.put("excludedProjectNames", toCommaSeparatedString(scriptOptions.getExcludedProjectNames()));
gradleScriptData.put("includedProjectNames", toCommaSeparatedString(scriptOptions.getIncludedProjectNames()));
gradleScriptData.put("excludedProjectPaths", StringEscapeUtils.escapeJava(toCommaSeparatedString(scriptOptions.getExcludedProjectPaths())));
gradleScriptData.put("includedProjectPaths", StringEscapeUtils.escapeJava(toCommaSeparatedString(scriptOptions.getIncludedProjectPaths())));
gradleScriptData.put("excludedConfigurationNames", toCommaSeparatedString(scriptOptions.getExcludedConfigurationNames()));
gradleScriptData.put("includedConfigurationNames", toCommaSeparatedString(scriptOptions.getIncludedConfigurationNames()));
gradleScriptData.put("customRepositoryUrl", scriptOptions.getGradleInspectorRepositoryUrl());
try {
populateGradleScriptWithData(targetFile, gradleScriptData);
} catch (IOException | TemplateException e) {
throw new DetectableException("Failed to generate the Gradle Inspector script from the given template file: " + targetFile.toString(), e);
}
logger.trace(String.format("Successfully created Gradle Inspector: %s", targetFile.toString()));
return targetFile;
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class GitDetectable method extractable.
@Override
public DetectableResult extractable() throws DetectableException {
try {
gitExecutable = gitResolver.resolveGit();
} catch (DetectableException e) {
gitExecutable = null;
}
if (gitExecutable != null) {
return new PassedDetectableResult(new FoundExecutable(gitExecutable));
} else {
// Couldn't find git executable, so we try to parse git files
gitConfigFile = fileFinder.findFile(gitDirectory, GIT_CONFIG_FILENAME);
gitHeadFile = fileFinder.findFile(gitDirectory, GIT_HEAD_FILENAME);
if ((gitConfigFile != null && gitHeadFile != null)) {
canParse = true;
return new PassedDetectableResult(Arrays.asList(new FoundFile(gitConfigFile), new FoundFile(gitHeadFile)));
}
}
return new PassedDetectableResult();
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class GoModCliExtractor method extract.
public Extraction extract(File directory, ExecutableTarget goExe) throws ExecutableFailedException, JsonSyntaxException, DetectableException {
List<GoListModule> goListModules = listModules(directory, goExe);
List<GoListAllData> goListAllModules = listAllModules(directory, goExe);
List<GoGraphRelationship> goGraphRelationships = listGraphRelationships(directory, goExe);
Set<String> excludedModules = listExcludedModules(directory, goExe);
GoRelationshipManager goRelationshipManager = new GoRelationshipManager(goGraphRelationships, excludedModules);
GoModDependencyManager goModDependencyManager = new GoModDependencyManager(goListAllModules, externalIdFactory);
List<CodeLocation> codeLocations = goListModules.stream().map(goListModule -> goModGraphGenerator.generateGraph(goListModule, goRelationshipManager, goModDependencyManager)).collect(Collectors.toList());
// No project info - hoping git can help with that.
return new Extraction.Builder().success(codeLocations).build();
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class NugetInspectorExtractor method executeTarget.
private NugetTargetResult executeTarget(ExecutableTarget inspector, File targetFile, File outputDirectory, NugetInspectorOptions nugetInspectorOptions) throws ExecutableRunnerException, IOException, DetectableException {
if (!outputDirectory.exists() && !outputDirectory.mkdirs()) {
throw new DetectableException(String.format("Executing the nuget inspector failed, could not create output directory: %s", outputDirectory));
}
List<String> arguments = NugetInspectorArguments.fromInspectorOptions(nugetInspectorOptions, targetFile, outputDirectory);
Executable executable = ExecutableUtils.createFromTarget(outputDirectory, inspector, arguments);
ExecutableOutput executableOutput = executableRunner.execute(executable);
if (executableOutput.getReturnCode() != 0) {
throw new DetectableException(String.format("Executing the nuget inspector failed: %s", executableOutput.getReturnCode()));
}
List<File> dependencyNodeFiles = fileFinder.findFiles(outputDirectory, INSPECTOR_OUTPUT_PATTERN);
List<NugetParseResult> parseResults = new ArrayList<>();
if (dependencyNodeFiles != null) {
for (File dependencyNodeFile : dependencyNodeFiles) {
String text = FileUtils.readFileToString(dependencyNodeFile, StandardCharsets.UTF_8);
NugetParseResult result = nugetInspectorParser.createCodeLocation(text);
parseResults.add(result);
}
}
NugetTargetResult targetResult = new NugetTargetResult();
targetResult.codeLocations = parseResults.stream().flatMap(it -> it.getCodeLocations().stream()).collect(Collectors.toList());
targetResult.nameVersion = parseResults.stream().filter(it -> StringUtils.isNotBlank(it.getProjectName())).map(it -> new NameVersion(it.getProjectName(), it.getProjectVersion())).findFirst().orElse(null);
return targetResult;
}
Aggregations