@@ -3,20 +3,44 @@ package config
33import (
44 "codacy/cli-v2/plugins"
55 "codacy/cli-v2/utils"
6+ "codacy/cli-v2/utils/logger"
67 "fmt"
7- "log"
88 "os"
99 "path/filepath"
1010 "strings"
11+
12+ "github.com/sirupsen/logrus"
1113)
1214
1315// InstallRuntimes installs all runtimes defined in the configuration
1416func InstallRuntimes (config * ConfigType ) error {
17+ var failedRuntimes []string
18+
1519 for name , runtimeInfo := range config .Runtimes () {
20+ logger .Info ("Starting runtime installation" , logrus.Fields {
21+ "runtime" : name ,
22+ "version" : runtimeInfo .Version ,
23+ })
24+
1625 err := InstallRuntime (name , runtimeInfo )
1726 if err != nil {
18- return fmt .Errorf ("failed to install runtime %s: %w" , name , err )
27+ logger .Error ("Failed to install runtime" , logrus.Fields {
28+ "runtime" : name ,
29+ "version" : runtimeInfo .Version ,
30+ "error" : err .Error (),
31+ })
32+ failedRuntimes = append (failedRuntimes , name )
33+ continue
1934 }
35+
36+ logger .Info ("Successfully installed runtime" , logrus.Fields {
37+ "runtime" : name ,
38+ "version" : runtimeInfo .Version ,
39+ })
40+ }
41+
42+ if len (failedRuntimes ) > 0 {
43+ return fmt .Errorf ("failed to install the following runtimes: %v" , failedRuntimes )
2044 }
2145 return nil
2246}
@@ -25,6 +49,10 @@ func InstallRuntimes(config *ConfigType) error {
2549func InstallRuntime (name string , runtimeInfo * plugins.RuntimeInfo ) error {
2650 // Check if the runtime is already installed
2751 if isRuntimeInstalled (runtimeInfo ) {
52+ logger .Info ("Runtime already installed" , logrus.Fields {
53+ "runtime" : name ,
54+ "version" : runtimeInfo .Version ,
55+ })
2856 fmt .Printf ("Runtime %s v%s is already installed\n " , name , runtimeInfo .Version )
2957 return nil
3058 }
@@ -67,15 +95,24 @@ func downloadAndExtractRuntime(runtimeInfo *plugins.RuntimeInfo) error {
6795 _ , err := os .Stat (downloadPath )
6896 if os .IsNotExist (err ) {
6997 // Download the file
70- // log.Printf("Downloading %s v%s...\n", runtimeInfo.Name, runtimeInfo.Version)
98+ logger .Debug ("Downloading runtime" , logrus.Fields {
99+ "runtime" : runtimeInfo .Name ,
100+ "version" : runtimeInfo .Version ,
101+ "downloadURL" : runtimeInfo .DownloadURL ,
102+ "downloadPath" : downloadPath ,
103+ })
71104 downloadPath , err = utils .DownloadFile (runtimeInfo .DownloadURL , Config .RuntimesDirectory ())
72105 if err != nil {
73106 return fmt .Errorf ("failed to download runtime: %w" , err )
74107 }
75108 } else if err != nil {
76109 return fmt .Errorf ("error checking for existing download: %w" , err )
77110 } else {
78- log .Printf ("Using existing download for %s v%s\n " , runtimeInfo .Name , runtimeInfo .Version )
111+ logger .Debug ("Using existing runtime download" , logrus.Fields {
112+ "runtime" : runtimeInfo .Name ,
113+ "version" : runtimeInfo .Version ,
114+ "downloadPath" : downloadPath ,
115+ })
79116 }
80117
81118 // Open the downloaded file
@@ -86,7 +123,13 @@ func downloadAndExtractRuntime(runtimeInfo *plugins.RuntimeInfo) error {
86123 defer file .Close ()
87124
88125 // Extract based on file extension
89- // log.Printf("Extracting %s v%s...\n", runtimeInfo.Name, runtimeInfo.Version)
126+ logger .Debug ("Extracting runtime" , logrus.Fields {
127+ "runtime" : runtimeInfo .Name ,
128+ "version" : runtimeInfo .Version ,
129+ "fileName" : fileName ,
130+ "extractDirectory" : Config .RuntimesDirectory (),
131+ })
132+
90133 if strings .HasSuffix (fileName , ".zip" ) {
91134 err = utils .ExtractZip (file .Name (), Config .RuntimesDirectory ())
92135 } else {
@@ -97,6 +140,9 @@ func downloadAndExtractRuntime(runtimeInfo *plugins.RuntimeInfo) error {
97140 return fmt .Errorf ("failed to extract runtime: %w" , err )
98141 }
99142
100- log .Printf ("Successfully installed %s v%s\n " , runtimeInfo .Name , runtimeInfo .Version )
143+ logger .Debug ("Runtime extraction completed" , logrus.Fields {
144+ "runtime" : runtimeInfo .Name ,
145+ "version" : runtimeInfo .Version ,
146+ })
101147 return nil
102148}
0 commit comments