Search in sources :

Example 1 with ExecutableTarget

use of com.synopsys.integration.detectable.ExecutableTarget 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 2 with ExecutableTarget

use of com.synopsys.integration.detectable.ExecutableTarget 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();
}
Also used : GoListParser(com.synopsys.integration.detectable.detectables.go.gomod.parse.GoListParser) JsonSyntaxException(com.google.gson.JsonSyntaxException) Extraction(com.synopsys.integration.detectable.extraction.Extraction) GoListModule(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListModule) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Set(java.util.Set) GoModGraphGenerator(com.synopsys.integration.detectable.detectables.go.gomod.process.GoModGraphGenerator) Collectors(java.util.stream.Collectors) GoVersionParser(com.synopsys.integration.detectable.detectables.go.gomod.parse.GoVersionParser) GoRelationshipManager(com.synopsys.integration.detectable.detectables.go.gomod.process.GoRelationshipManager) File(java.io.File) GoModDependencyManager(com.synopsys.integration.detectable.detectables.go.gomod.process.GoModDependencyManager) List(java.util.List) GoGraphRelationship(com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) GoListAllData(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListAllData) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) GoGraphParser(com.synopsys.integration.detectable.detectables.go.gomod.parse.GoGraphParser) Collections(java.util.Collections) GoModWhyParser(com.synopsys.integration.detectable.detectables.go.gomod.parse.GoModWhyParser) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) GoListModule(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListModule) GoGraphRelationship(com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship) GoRelationshipManager(com.synopsys.integration.detectable.detectables.go.gomod.process.GoRelationshipManager) GoModDependencyManager(com.synopsys.integration.detectable.detectables.go.gomod.process.GoModDependencyManager) GoListAllData(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListAllData)

Example 3 with ExecutableTarget

use of com.synopsys.integration.detectable.ExecutableTarget in project synopsys-detect by blackducksoftware.

the class LernaPackageDiscoverer method discoverLernaPackages.

public List<LernaPackage> discoverLernaPackages(File workingDirectory, ExecutableTarget lernaExecutable) throws ExecutableRunnerException {
    ExecutableOutput lernaLsExecutableOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, lernaExecutable, "ls", "--all", "--json"));
    String lernaLsOutput = lernaLsExecutableOutput.getStandardOutput();
    Type lernaPackageListType = new TypeToken<ArrayList<LernaPackage>>() {
    }.getType();
    List<LernaPackage> lernaPackages = gson.fromJson(lernaLsOutput, lernaPackageListType);
    return lernaPackages.stream().filter(Objects::nonNull).filter(lernaPackage -> excludedIncludedFilter.shouldInclude(lernaPackage.getName())).collect(Collectors.toList());
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) Collectors(java.util.stream.Collectors) File(java.io.File) ExcludedIncludedWildcardFilter(com.synopsys.integration.util.ExcludedIncludedWildcardFilter) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) LernaPackage(com.synopsys.integration.detectable.detectables.lerna.model.LernaPackage) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) Type(java.lang.reflect.Type) Gson(com.google.gson.Gson) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableUtils(com.synopsys.integration.detectable.ExecutableUtils) Type(java.lang.reflect.Type) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) ArrayList(java.util.ArrayList) Objects(java.util.Objects) LernaPackage(com.synopsys.integration.detectable.detectables.lerna.model.LernaPackage)

Example 4 with ExecutableTarget

use of com.synopsys.integration.detectable.ExecutableTarget 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;
}
Also used : Extraction(com.synopsys.integration.detectable.extraction.Extraction) 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) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) Map(java.util.Map) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) 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) Executable(com.synopsys.integration.executable.Executable) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) Optional(java.util.Optional) ExecutableUtils(com.synopsys.integration.detectable.ExecutableUtils) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) NameVersion(com.synopsys.integration.util.NameVersion) ArrayList(java.util.ArrayList) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) NugetParseResult(com.synopsys.integration.detectable.detectables.nuget.parse.NugetParseResult) Executable(com.synopsys.integration.executable.Executable) File(java.io.File) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 5 with ExecutableTarget

use of com.synopsys.integration.detectable.ExecutableTarget in project synopsys-detect by blackducksoftware.

the class ProjectInspectorExtractor method extract.

public Extraction extract(ProjectInspectorOptions projectInspectorOptions, List<String> extra, File targetDirectory, File outputDirectory, ExecutableTarget inspector) throws ExecutableFailedException {
    File outputFile = new File(outputDirectory, "inspection.json");
    List<String> arguments = new LinkedList<>();
    arguments.add("inspect");
    arguments.add("--dir");
    arguments.add(targetDirectory.toString());
    arguments.add("--output-file");
    arguments.add(outputFile.toString());
    arguments.addAll(extra);
    Optional.ofNullable(projectInspectorOptions.getAdditionalArguments()).map(arg -> arg.split(" ")).ifPresent(additionalArguments -> arguments.addAll(Arrays.asList(additionalArguments)));
    executableRunner.executeSuccessfully(ExecutableUtils.createFromTarget(targetDirectory, inspector, arguments));
    try {
        String outputContents = FileUtils.readFileToString(outputFile, StandardCharsets.UTF_8);
        List<CodeLocation> codeLocations = projectInspectorParser.parse(outputContents);
        return new Extraction.Builder().success(codeLocations).build();
    } catch (IOException e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : Arrays(java.util.Arrays) Extraction(com.synopsys.integration.detectable.extraction.Extraction) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) Optional(java.util.Optional) ExecutableUtils(com.synopsys.integration.detectable.ExecutableUtils) LinkedList(java.util.LinkedList) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Extraction(com.synopsys.integration.detectable.extraction.Extraction) IOException(java.io.IOException) File(java.io.File) LinkedList(java.util.LinkedList)

Aggregations

ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)15 File (java.io.File)15 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)10 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)10 Extraction (com.synopsys.integration.detectable.extraction.Extraction)9 List (java.util.List)8 ExecutableUtils (com.synopsys.integration.detectable.ExecutableUtils)6 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)6 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)6 Executable (com.synopsys.integration.executable.Executable)6 IOException (java.io.IOException)6 Optional (java.util.Optional)6 Collectors (java.util.stream.Collectors)6 StandardCharsets (java.nio.charset.StandardCharsets)5 ArrayList (java.util.ArrayList)5 FileUtils (org.apache.commons.io.FileUtils)5 ExecutableFailedException (com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException)4 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)4 HashMap (java.util.HashMap)4 Test (org.junit.jupiter.api.Test)4