func installPluginVersion(installDesc *installDescription, versionInstallDescription *versionInstallDescription) installResult { if common.IsPluginInstalled(installDesc.Name, versionInstallDescription.Version) { return installSuccess(fmt.Sprintf("Plugin %s %s is already installed.", installDesc.Name, versionInstallDescription.Version)) } logger.Info("Installing Plugin => %s %s\n", installDesc.Name, versionInstallDescription.Version) downloadLink, err := getDownloadLink(versionInstallDescription.DownloadUrls) if err != nil { return installError(fmt.Sprintf("Could not get download link: %s", err.Error())) } tempDir := common.GetTempDir() defer common.Remove(tempDir) unzippedPluginDir, err := util.DownloadAndUnzip(downloadLink, tempDir) if err != nil { return installError(err.Error()) } if err := runInstallCommands(versionInstallDescription.Install, unzippedPluginDir); err != nil { return installError(fmt.Sprintf("Failed to Run install command. %s.", err.Error())) } err = copyPluginFilesToGauge(installDesc, versionInstallDescription, unzippedPluginDir) if err != nil { installError(err.Error()) } return installSuccess("") }
func initializeTemplate(templateName string) error { tempDir := common.GetTempDir() defer util.Remove(tempDir) unzippedTemplate, err := util.DownloadAndUnzip(getTemplateURL(templateName), tempDir) if err != nil { return err } wd := config.ProjectRoot logger.Info("Copying Gauge template %s to current directory ...", templateName) filesAdded, err := common.MirrorDir(filepath.Join(unzippedTemplate, templateName), wd) if err != nil { return fmt.Errorf("Failed to copy Gauge template: %s", err.Error()) } metadataFile := filepath.Join(wd, metadataFileName) metadataContents, err := common.ReadFileContents(metadataFile) if err != nil { return fmt.Errorf("Failed to read file contents of %s: %s", metadataFile, err.Error()) } metadata := &templateMetadata{} err = json.Unmarshal([]byte(metadataContents), metadata) if err != nil { return err } if metadata.PostInstallCmd != "" { command := strings.Split(metadata.PostInstallCmd, " ") cmd, err := common.ExecuteSystemCommand(command, wd, os.Stdout, os.Stderr) cmd.Wait() if err != nil { for _, file := range filesAdded { pathSegments := strings.Split(file, string(filepath.Separator)) util.Remove(filepath.Join(wd, pathSegments[0])) } return fmt.Errorf("Failed to run post install commands: %s", err.Error()) } } util.Remove(metadataFile) return nil }