use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class NugetAirGapCreator method installThenCopy.
private void installThenCopy(File nugetFolder, String folderName, ThrowingBiFunction<File, String, File, DetectableException> installer) throws DetectUserFriendlyException {
try {
File inspectorFolder = new File(nugetFolder, folderName);
File installTarget = installer.apply(inspectorFolder, null);
FileUtils.copyDirectory(installTarget, inspectorFolder);
FileUtils.deleteDirectory(installTarget);
} catch (DetectableException | IOException e) {
throw new DetectUserFriendlyException("An error occurred installing to the " + folderName + " inspector folder.", e, ExitCodeType.FAILURE_GENERAL_ERROR);
}
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class PnpmYamlTransformer method buildGraph.
private void buildGraph(MutableDependencyGraph graphBuilder, List<String> rootPackageIds, @Nullable Map<String, PnpmPackageInfo> packageMap, PnpmLinkedPackageResolver linkedPackageResolver, @Nullable String reportingProjectPackagePath) throws IntegrationException {
if (packageMap == null) {
throw new DetectableException("Could not parse 'packages' section of the pnpm-lock.yaml file.");
}
for (Map.Entry<String, PnpmPackageInfo> packageEntry : packageMap.entrySet()) {
String packageId = packageEntry.getKey();
Optional<Dependency> pnpmPackage = buildDependencyFromPackageEntry(packageEntry);
if (!pnpmPackage.isPresent()) {
logger.debug(String.format("Could not add package %s to the graph.", packageId));
continue;
}
if (isRootPackage(packageId, rootPackageIds)) {
graphBuilder.addChildToRoot(pnpmPackage.get());
}
PnpmPackageInfo packageInfo = packageEntry.getValue();
if (dependencyTypeFilter.shouldInclude(packageInfo.getDependencyType())) {
for (Map.Entry<String, String> packageDependency : packageInfo.getDependencies().entrySet()) {
String dependencyPackageId = convertRawEntryToPackageId(packageDependency, linkedPackageResolver, reportingProjectPackagePath);
Optional<Dependency> child = buildDependencyFromPackageId(dependencyPackageId);
child.ifPresent(c -> graphBuilder.addChildWithParent(child.get(), pnpmPackage.get()));
}
}
}
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class LocatorNugetInspectorResolver method install.
private NugetInspector install() throws IntegrationException {
// dotnet
ExecutableTarget dotnetExecutable = executableResolver.resolveDotNet();
boolean useDotnet = true;
if (shouldForceExeInspector(detectInfo)) {
logger.debug("Will use the classic inspector.");
useDotnet = false;
} else if (dotnetExecutable == null) {
if (isNotWindows(detectInfo)) {
throw new DetectableException("When not on Windows, the nuget inspector requires the dotnet executable to run.");
} else {
useDotnet = false;
}
}
if (useDotnet) {
File dotnetFolder;
if (dotNetRuntimeManager.isRuntimeAvailable(5)) {
dotnetFolder = nugetInspectorLocator.locateDotnet5Inspector();
return findDotnetCoreInspector(dotnetFolder, dotnetExecutable, "NugetDotnet5Inspector.dll");
} else if (dotNetRuntimeManager.isRuntimeAvailable(3, 1)) {
dotnetFolder = nugetInspectorLocator.locateDotnet3Inspector();
return findDotnetCoreInspector(dotnetFolder, dotnetExecutable, "NugetDotnet3Inspector.dll");
} else {
dotnetFolder = nugetInspectorLocator.locateDotnetInspector();
return findDotnetCoreInspector(dotnetFolder, dotnetExecutable, "BlackduckNugetInspector.dll");
}
} else {
File classicFolder = nugetInspectorLocator.locateExeInspector();
return findExeInspector(classicFolder);
}
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class OnlineNugetInspectorLocator method locateInspector.
private File locateInspector(ThrowingBiFunction<File, String, File, DetectableException> inspectorInstaller, String inspectorKey) throws DetectableException {
try {
File nugetDirectory = directoryManager.getPermanentDirectory("nuget");
File inspector = inspectorInstaller.apply(nugetDirectory, overrideVersion);
installedToolManager.saveInstalledToolLocation(inspectorKey, inspector.getAbsolutePath());
return inspector;
} catch (Exception e) {
logger.debug("Attempting to download nuget inspector from previous install.");
return installedToolLocator.locateTool(inspectorKey).orElseThrow(() -> new DetectableException("Unable to install the nuget inspector from Artifactory.", e));
}
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class NugetInspectorExtractor method executeTarget.
private NugetTargetResult executeTarget(NugetInspector 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));
}
ExecutableOutput executableOutput = inspector.execute(outputDirectory, targetFile, outputDirectory, nugetInspectorOptions);
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