Search in sources :

Example 31 with ExecutableOutput

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

the class DetectExecutableRunner method execute.

@NotNull
public ExecutableOutput execute(Executable executable, boolean outputContainsSecret) throws ExecutableRunnerException {
    ExecutableRunner targetRunner = runner;
    if (outputContainsSecret) {
        targetRunner = secretRunner;
    }
    ExecutableOutput output = targetRunner.execute(executable);
    eventSystem.publishEvent(Event.Executable, new ExecutedExecutable(output, executable));
    boolean normallyLogOutput = output.getReturnCode() != 0 && shouldLogOutput && !logger.isDebugEnabled() && !logger.isTraceEnabled();
    if (normallyLogOutput && !outputContainsSecret) {
        if (StringUtils.isNotBlank(output.getStandardOutput())) {
            logger.info("Standard Output: ");
            logger.info(output.getStandardOutput());
        }
        if (StringUtils.isNotBlank(output.getErrorOutput())) {
            logger.info("Error Output: ");
            logger.info(output.getErrorOutput());
        }
    }
    return output;
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) ExecutableRunner(com.synopsys.integration.executable.ExecutableRunner) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with ExecutableOutput

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

the class PubDepsExtractor method extract.

public Extraction extract(File directory, @Nullable ExecutableTarget dartExe, @Nullable ExecutableTarget flutterExe, DartPubDepsDetectableOptions dartPubDepsDetectableOptions, File pubSpecYamlFile) {
    try {
        toolVersionLogger.log(directory, dartExe);
        toolVersionLogger.log(directory, flutterExe);
        List<String> pubDepsCommand = new ArrayList<>();
        pubDepsCommand.add("pub");
        pubDepsCommand.add("deps");
        if (dartPubDepsDetectableOptions.getDependencyTypeFilter().shouldExclude(DartPubDependencyType.DEV)) {
            pubDepsCommand.add("--no-dev");
        }
        ExecutableOutput pubDepsOutput = null;
        if (dartExe != null) {
            pubDepsOutput = runPubDepsCommand(directory, dartExe, pubDepsCommand);
        }
        if (pubDepsOutput == null || pubDepsOutput.getReturnCode() != 0) {
            if (flutterExe == null && dartExe != null) {
                return new Extraction.Builder().failure(String.format("An error occurred trying to run %s %s", dartExe.toCommand(), String.join(" ", pubDepsCommand))).build();
            } else {
                // If command does not work with Dart, it could be because at least one of the packages requires Flutter
                logger.debug("Running dart pub deps was not successful.  Going to try running flutter pub deps.");
                pubDepsCommand.add(0, "--no-version-check");
                pubDepsOutput = runPubDepsCommand(directory, flutterExe, pubDepsCommand);
            }
        }
        Optional<NameVersion> nameVersion = Optional.empty();
        if (pubSpecYamlFile != null) {
            List<String> pubSpecYamlLines = Files.readAllLines(pubSpecYamlFile.toPath(), StandardCharsets.UTF_8);
            nameVersion = nameVersionParser.parseNameVersion(pubSpecYamlLines);
        }
        DependencyGraph dependencyGraph = pubDepsParser.parse(pubDepsOutput.getStandardOutputAsList());
        CodeLocation codeLocation = new CodeLocation(dependencyGraph);
        return new Extraction.Builder().success(codeLocation).nameVersionIfPresent(nameVersion).build();
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.synopsys.integration.detectable.extraction.Extraction) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException)

Example 33 with ExecutableOutput

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

the class ConanCliExtractor method extract.

public Extraction extract(File projectDir, ExecutableTarget conanExe) {
    toolVersionLogger.log(projectDir, conanExe);
    ExecutableOutput conanInfoOutput;
    try {
        conanInfoOutput = conanCommandRunner.runConanInfoCommand(projectDir, conanExe);
    } catch (Exception e) {
        logger.error(String.format("Exception thrown executing conan info command: %s", e.getMessage()));
        return new Extraction.Builder().exception(e).build();
    }
    if (!conanCommandRunner.wasSuccess(conanInfoOutput)) {
        return new Extraction.Builder().failure("Conan info command reported errors").build();
    }
    if (!conanCommandRunner.producedOutput(conanInfoOutput)) {
        return new Extraction.Builder().failure("Conan info command produced no output").build();
    }
    try {
        ConanDetectableResult result = conanInfoParser.generateCodeLocationFromConanInfoOutput(conanInfoOutput.getStandardOutput());
        return new Extraction.Builder().success(result.getCodeLocation()).projectName(result.getProjectName()).projectVersion(result.getProjectVersion()).build();
    } catch (DetectableException e) {
        return new Extraction.Builder().failure(e.getMessage()).build();
    }
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) ConanDetectableResult(com.synopsys.integration.detectable.detectables.conan.ConanDetectableResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 34 with ExecutableOutput

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

the class SwiftDetectableTest method setup.

@Override
protected void setup() throws IOException {
    addFile(Paths.get("Package.swift"));
    ExecutableOutput rootSwiftPackage = createStandardOutput("Fetching https://github.com/apple/example-package-fisheryates.git", "Completed resolution in 1.03s", "Cloning https://github.com/apple/example-package-fisheryates.git", "Resolving https://github.com/apple/example-package-fisheryates.git at 2.0.5", "{", "   \"name\": \"DeckOfPlayingCards\",", "   \"url\": \"/Users/jakem/bazelWorkspace/sleuthifer/swift/example-package-deckofplayingcards\",", "   \"version\": \"unspecified\",", "   \"path\": \"/Users/jakem/bazelWorkspace/sleuthifer/swift/example-package-deckofplayingcards\",", "   \"dependencies\": [", "       {", "           \"name\": \"FisherYates\",", "           \"url\": \"https://github.com/apple/example-package-fisheryates.git\",", "           \"version\": \"2.0.5\",", "           \"path\": \"/Users/jakem/bazelWorkspace/sleuthifer/swift/example-package-deckofplayingcards/.build/checkouts/example-package-fisheryates\",", "           \"dependencies\": []", "       },", "       {", "           \"name\": \"PlayingCard\",", "           \"url\": \"https://github.com/apple/example-package-playingcard.git\",", "           \"version\": \"3.0.5\",", "           \"path\": \"/Users/jakem/bazelWorkspace/sleuthifer/swift/example-package-deckofplayingcards/.build/checkouts/example-package-playingcard\",", "           \"dependencies\": [", "               {", "                   \"name\": \"GenericLibrary\",", "                   \"url\": \"https://github.com/apple/example-package-genericLibrary.git\",", "                   \"version\": \"1.0.1\",", "                   \"path\": \"/Users/jakem/bazelWorkspace/sleuthifer/swift/example-package-deckofplayingcards/.build/checkouts/example-package-genericLibrary\",", "                   \"dependencies\": []", "               }", "           ]", "       }", "   ]", "}");
    addExecutableOutput(rootSwiftPackage, "swift", "package", "show-dependencies", "--format", "json");
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput)

Example 35 with ExecutableOutput

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

the class RebarDetectableTest method setup.

@Override
public void setup() throws IOException {
    addFile(Paths.get("rebar.config"));
    ExecutableOutput executableOutput = createStandardOutput("└─ project─1.0.0 (project app)", "   ├─ git_inner_parent_dependency─0.0.2 (git repo)", "   │  └─ hex_inner_child_dependency─0.3.0 (hex package)", "   └─ git_outer_parent_dependency─0.0.7 (git repo)", "      └─ git_outer_child_dependency─0.8.0 (git repo)");
    Map<String, String> environment = new HashMap<>();
    environment.put("REBAR_COLOR", "none");
    addExecutableOutput(executableOutput, environment, "rebar", "tree");
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) HashMap(java.util.HashMap)

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