ensureDependenciesTo installs missing dependencies, writing progress to w.
(runtime, dir, venv string, w io.Writer)
| 895 | |
| 896 | // ensureDependenciesTo installs missing dependencies, writing progress to w. |
| 897 | func ensureDependenciesTo(runtime, dir, venv string, w io.Writer) error { |
| 898 | switch runtime { |
| 899 | case "go": |
| 900 | fmt.Fprintln(w, "Downloading Go modules…") |
| 901 | c := exec.Command("go", "mod", "download") |
| 902 | c.Dir = dir |
| 903 | c.Stdout = w |
| 904 | c.Stderr = os.Stderr |
| 905 | return c.Run() |
| 906 | |
| 907 | case "nodejs", "node": |
| 908 | fmt.Fprintln(w, "Running npm install…") |
| 909 | c := exec.Command("npm", "install") |
| 910 | c.Dir = dir |
| 911 | c.Stdout = w |
| 912 | c.Stderr = os.Stderr |
| 913 | return c.Run() |
| 914 | |
| 915 | case "python": |
| 916 | return ensurePythonDependenciesTo(dir, venv, w) |
| 917 | |
| 918 | case "dotnet": |
| 919 | fmt.Fprintln(w, "Restoring .NET packages…") |
| 920 | c := exec.Command("dotnet", "restore") |
| 921 | c.Dir = dir |
| 922 | c.Stdout = w |
| 923 | c.Stderr = os.Stderr |
| 924 | return c.Run() |
| 925 | |
| 926 | case "java": |
| 927 | if fileExists(filepath.Join(dir, "pom.xml")) { |
| 928 | fmt.Fprintln(w, "Compiling Java project with Maven…") |
| 929 | c := exec.Command("mvn", "-q", "compile") |
| 930 | c.Dir = dir |
| 931 | c.Stdout = w |
| 932 | c.Stderr = os.Stderr |
| 933 | return c.Run() |
| 934 | } else if fileExists(filepath.Join(dir, "build.gradle")) || fileExists(filepath.Join(dir, "build.gradle.kts")) { |
| 935 | fmt.Fprintln(w, "Compiling Java project with Gradle…") |
| 936 | c := exec.Command("gradle", "-q", "classes") |
| 937 | c.Dir = dir |
| 938 | c.Stdout = w |
| 939 | c.Stderr = os.Stderr |
| 940 | return c.Run() |
| 941 | } |
| 942 | return fmt.Errorf("java runtime: no pom.xml or build.gradle found in %s", dir) |
| 943 | |
| 944 | case "yaml": |
| 945 | // No dependencies to install for YAML projects. |
| 946 | return nil |
| 947 | } |
| 948 | return nil |
| 949 | } |
| 950 | |
| 951 | // ensurePythonDependencies creates a venv and installs packages from |
| 952 | // requirements.txt. Uses `uv` when available for faster installs, otherwise |
no test coverage detected