Search in sources :

Example 6 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.

the class DockerExtractor method loadDockerImage.

private void loadDockerImage(File directory, Map<String, String> environmentVariables, ExecutableTarget dockerExe, File imageToImport) throws IOException, ExecutableRunnerException, IntegrationException {
    List<String> dockerImportArguments = Arrays.asList("load", "-i", imageToImport.getCanonicalPath());
    Executable dockerImportImageExecutable = ExecutableUtils.createFromTarget(directory, environmentVariables, dockerExe, dockerImportArguments);
    ExecutableOutput exeOut = executableRunner.execute(dockerImportImageExecutable);
    if (exeOut.getReturnCode() != 0) {
        throw new IntegrationException(String.format("Command %s %s returned %d: %s", dockerExe.toCommand(), dockerImportArguments, exeOut.getReturnCode(), exeOut.getErrorOutput()));
    }
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) IntegrationException(com.synopsys.integration.exception.IntegrationException) Executable(com.synopsys.integration.executable.Executable)

Example 7 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput 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 8 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput 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 9 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.

the class BitbakeDetectableTest method setup.

@Override
protected void setup() throws IOException {
    addFile("oe-init-build-env");
    addExecutableOutput(// Command generates task-depends.dot
    createStandardOutput(""), createBitbakeCommand("bitbake -g core-image-minimal"));
    addFile(Paths.get("task-depends.dot"), "digraph depends {", "\"acl.do_build\" [label = \"acl do_build\\n:2.2.52-r0\\n/home/bit/poky/meta/recipes-support/attr/acl_2.2.52.bb\"]", "\"acl.do_build\" -> \"acl.do_package_qa\"", "\"acl.do_package\" -> \"attr.do_packagedata\"", "\"attr.do_build\" [label = \"attr do_build\\n:2.4.47-r0\\n/home/bit/poky/meta/recipes-support/attr/attr_2.4.47.bb\"]", "\"attr.do_build\" -> \"base-files.do_package_write_rpm\"", "\"attr.do_build\" -> \"base-passwd.do_package_write_rpm\"", "\"base-files.do_build\" [label = \"base-files do_build\\n:3.0.14-r89\\n/home/bit/poky/meta/recipes-core/base-files/base-files_3.0.14.bb\"]", "\"base-passwd.do_build\" [label = \"base-passwd do_build\\n:3.5.29-r0\\n/home/bit/poky/meta/recipes-core/base-passwd/base-passwd_3.5.29.bb\"]", "}");
    ExecutableOutput bitbakeShowRecipesOutput = createStandardOutput("=== Available recipes: ===", "acl:", "  meta                 2.2.52", "attr:", "  meta                 2.4.47", "base-files:", "  meta                 3.0.14", "base-passwd:", "  meta                 3.5.29");
    addExecutableOutput(bitbakeShowRecipesOutput, createBitbakeCommand("bitbake-layers show-recipes"));
    addExecutableOutput(createStandardOutput(getSourceDirectory().toFile().getAbsolutePath()), createBitbakeCommand("pwd"));
    Path licensesDirectory = Paths.get("licenses/");
    Path licenseManifest = Paths.get(licensesDirectory.toString(), "core-image-minimal-some-arch/license.manifest");
    addFile(licenseManifest, "PACKAGE NAME: libattr", "PACKAGE VERSION: 2.4.47", "RECIPE NAME: attr", "LICENSE: LGPLv2.1+", "", "PACKAGE NAME: base-files", "PACKAGE VERSION: 3.0.14", "RECIPE NAME: base-files", "LICENSE: GPLv2", "", "PACKAGE NAME: base-passwd", "PACKAGE VERSION: 3.5.29", "RECIPE NAME: base-passwd", "LICENSE: GPLv2");
    addExecutableOutput(createStandardOutput("MACHINE_ARCH=\"not-using\"", "LICENSE_DIRECTORY=\"" + licenseManifest.toAbsolutePath() + "\""), createBitbakeCommand("bitbake --environment"));
}
Also used : Path(java.nio.file.Path) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput)

Example 10 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.

the class PearCliDetectableTest method setup.

@Override
protected void setup() throws IOException {
    addFile(Paths.get("package.xml"), "<?xml version=\"1.0\"?>", "<!DOCTYPE package SYSTEM \"http://pear.php.net/dtd/package-1.0\">", "<package xmlns=\"http://pear.php.net/dtd/package-2.0\">", "   <name>couchbase</name>", "   <version>", "       <release>3.0.1</release>", "       <api>3.0.0</api>", "   </version>", "   <dependencies>", "       <required>", "           <php>", "               <min>7.1.0</min>", "           </php>", "           <pearinstaller>", "               <min>1.10.1</min>", "           </pearinstaller>", "       </required>", "   </dependencies>", "</package>");
    ExecutableOutput listOutput = createStandardOutput("==================", "PHP    7.1.0", "PearInstaller  1.10.1");
    addExecutableOutput(listOutput, new HashMap<>(), "pear", "list");
    ExecutableOutput packageDependenciesOutput = createStandardOutput("==================", "Y  Package PHP", "Y  Package PearInstaller");
    addExecutableOutput(packageDependenciesOutput, new HashMap<>(), "pear", "package-dependencies", "package.xml");
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput)

Aggregations

ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)53 File (java.io.File)18 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)14 ArrayList (java.util.ArrayList)14 Extraction (com.synopsys.integration.detectable.extraction.Extraction)13 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)13 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)10 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)9 Executable (com.synopsys.integration.executable.Executable)9 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)8 Test (org.junit.jupiter.api.Test)7 NameVersion (com.synopsys.integration.util.NameVersion)6 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)5 HashMap (java.util.HashMap)5 List (java.util.List)5 StringUtils (org.apache.commons.lang3.StringUtils)5 ExecutableUtils (com.synopsys.integration.detectable.ExecutableUtils)4 IOException (java.io.IOException)4 Optional (java.util.Optional)4 Gson (com.google.gson.Gson)3