Skip to content

Commit

Permalink
Adding debug logging statements to init and install flows, #1387
Browse files Browse the repository at this point in the history
  • Loading branch information
nehashri committed Apr 19, 2019
1 parent 96c2695 commit f6442e1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
13 changes: 6 additions & 7 deletions plugin/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ func installPluginVersion(installDesc *installDescription, versionInstallDescrip

tempDir := common.GetTempDir()
defer common.Remove(tempDir)
logger.Debugf(true, "Downloading %s", filepath.Base(downloadLink))
pluginZip, err := util.Download(downloadLink, tempDir, "", silent)
if err != nil {
return installError(fmt.Errorf("Failed to download the plugin. %s", err.Error()))
Expand Down Expand Up @@ -422,11 +421,11 @@ func constructPluginInstallJSONURL(p string) (string, InstallResult) {
if repoURL == "" {
return "", installError(fmt.Errorf("Could not find gauge repository url from configuration."))
}
JSONURL := fmt.Sprintf("%s/%s", repoURL, p)
jsonURL := fmt.Sprintf("%s/%s", repoURL, p)
if qp := plugin.QueryParams(); qp != "" {
JSONURL += qp
jsonURL += qp
}
return JSONURL, installSuccess("")
return jsonURL, installSuccess("")
}

func (installDesc *installDescription) getVersion(version string) (*versionInstallDescription, error) {
Expand Down Expand Up @@ -518,8 +517,8 @@ func HandleInstallResult(result InstallResult, pluginName string, exitIfFailure
return true
}
if !result.Success {
if (result.Version != "") {
logger.Errorf(true, "Failed to install plugin '%s' version %s.\nReason: %s", pluginName, result.Version, result.getMessage())
if result.Version != "" {
logger.Errorf(true, "Failed to install plugin '%s' version %s.\nReason: %s", pluginName, result.Version, result.getMessage())
} else {
logger.Errorf(true, "Failed to install plugin '%s'.\nReason: %s", pluginName, result.getMessage())
}
Expand All @@ -528,7 +527,7 @@ func HandleInstallResult(result InstallResult, pluginName string, exitIfFailure
}
return false
}
if (result.Version != "") {
if result.Version != "" {
logger.Infof(true, "Successfully installed plugin '%s' version %s", pluginName, result.Version)
} else {
logger.Infof(true, "Successfully installed plugin '%s'", pluginName)
Expand Down
7 changes: 5 additions & 2 deletions projectInit/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ type templateMetadata struct {
func initializeTemplate(templateName string) error {
tempDir := common.GetTempDir()
defer util.Remove(tempDir)
unzippedTemplate, err := util.DownloadAndUnzip(getTemplateURL(templateName), tempDir)
templateURL := getTemplateURL(templateName)
logger.Debugf(true, "Initializing template from %s", templateURL)
unzippedTemplate, err := util.DownloadAndUnzip(templateURL, tempDir)
if err != nil {
return err
}
Expand Down Expand Up @@ -71,6 +73,7 @@ func initializeTemplate(templateName string) error {
}

if metadata.PostInstallCmd != "" {
logger.Debugf(true, "Running post install command %s", metadata.PostInstallCmd)
command := strings.Fields(metadata.PostInstallCmd)
cmd, err := common.ExecuteSystemCommand(command, wd, os.Stdout, os.Stderr)
if err != nil {
Expand All @@ -84,7 +87,7 @@ func initializeTemplate(templateName string) error {
return err
}
}
fmt.Printf("Successfully initialized the project. %s\n", metadata.PostInstallMsg)
logger.Infof(true, "Successfully initialized the project. %s\n", metadata.PostInstallMsg)

util.Remove(metadataFile)
return nil
Expand Down
4 changes: 2 additions & 2 deletions projectInit/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ func ListTemplates() {
templatesURL := config.GaugeTemplatesUrl()
_, err := common.UrlExists(templatesURL)
if err != nil {
logger.Fatalf(true, "Gauge templates URL is not reachable: %s", err.Error())
logger.Fatalf(true, "Gauge templates URL %s is not reachable: %s", templatesURL, err.Error())
}
res, err := http.Get(templatesURL)
if err != nil {
logger.Fatalf(true, "Error occurred while downloading templates list: %s", err.Error())
logger.Fatalf(true, "Error occurred while downloading templates list from %s: %s", templatesURL, err.Error())
}
defer res.Body.Close()
if res.StatusCode >= 400 {
Expand Down
1 change: 1 addition & 0 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func ExecuteInitHookForRunner(language string) error {

languageJSONFilePath, err := plugin.GetLanguageJSONFilePath(language)
runnerDir := filepath.Dir(languageJSONFilePath)
logger.Debugf(true, "Running init hook command => %s", command)
cmd, err := common.ExecuteCommand(command, runnerDir, os.Stdout, os.Stderr)

if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions util/httpUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"os"
"path/filepath"

"github.com/getgauge/gauge/logger"

"github.com/getgauge/common"
)

Expand Down Expand Up @@ -63,6 +65,7 @@ func Download(url, targetDir, fileName string, silent bool) (string, error) {
}
targetFile := filepath.Join(targetDir, fileName)

logger.Debugf(true, "Downloading %s", url)
resp, err := http.Get(url)
if err != nil {
return "", err
Expand Down

0 comments on commit f6442e1

Please sign in to comment.