Search in sources :

Example 1 with DetectableException

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);
    }
}
Also used : DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) IOException(java.io.IOException) File(java.io.File) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 2 with DetectableException

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()));
            }
        }
    }
}
Also used : Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) HashMap(java.util.HashMap) Map(java.util.Map) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) PnpmPackageInfo(com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmPackageInfo)

Example 3 with DetectableException

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);
    }
}
Also used : ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) File(java.io.File) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 4 with DetectableException

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));
    }
}
Also used : File(java.io.File) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 5 with DetectableException

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;
}
Also used : Extraction(com.synopsys.integration.detectable.extraction.Extraction) MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) NugetParseResult(com.synopsys.integration.detectable.detectables.nuget.parse.NugetParseResult) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) ArrayList(java.util.ArrayList) NameVersion(com.synopsys.integration.util.NameVersion) NugetInspectorOptions(com.synopsys.integration.detectable.detectable.inspector.nuget.NugetInspectorOptions) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) Map(java.util.Map) NugetInspector(com.synopsys.integration.detectable.detectable.inspector.nuget.NugetInspector) Logger(org.slf4j.Logger) NugetInspectorParser(com.synopsys.integration.detectable.detectables.nuget.parse.NugetInspectorParser) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) DependencyGraphCombiner(com.synopsys.integration.bdio.graph.DependencyGraphCombiner) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Optional(java.util.Optional) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) NameVersion(com.synopsys.integration.util.NameVersion) ArrayList(java.util.ArrayList) NugetParseResult(com.synopsys.integration.detectable.detectables.nuget.parse.NugetParseResult) File(java.io.File) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Aggregations

DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)39 File (java.io.File)22 IOException (java.io.IOException)13 Extraction (com.synopsys.integration.detectable.extraction.Extraction)8 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)8 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)8 List (java.util.List)8 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)6 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)6 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)6 PassedDetectableResult (com.synopsys.integration.detectable.detectable.result.PassedDetectableResult)6 ExtractionEnvironment (com.synopsys.integration.detectable.extraction.ExtractionEnvironment)6 Collections (java.util.Collections)6 HashMap (java.util.HashMap)6 Test (org.junit.jupiter.api.Test)6 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)5 ExecutableFailedException (com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException)5 NameVersion (com.synopsys.integration.util.NameVersion)5 ArrayList (java.util.ArrayList)5 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)4