Example #1
0
func InstallPlugin(pluginName, version string) installResult {
	installDescription, result := getInstallDescription(pluginName)
	if !result.Success {
		return result
	}
	defer util.RemoveTempDir()
	return installPluginWithDescription(installDescription, version)
}
Example #2
0
// InstallPlugin download and install the latest plugin(if version not specified) of given plugin name
func InstallPlugin(pluginName, version string) InstallResult {
	logger.Info("Gathering metadata for %s", pluginName)
	installDescription, result := getInstallDescription(pluginName, false)
	defer util.RemoveTempDir()
	if !result.Success {
		return result
	}
	return installPluginWithDescription(installDescription, version)
}
Example #3
0
func initializeTemplate(templateName string) error {
	defer util.RemoveTempDir()

	unzippedTemplate, err := util.DownloadAndUnzip(getTemplateURL(templateName))
	if err != nil {
		return err
	}

	wd := config.ProjectRoot

	logger.Log.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 != "" {
		cmd, err := common.ExecuteCommand([]string{metadata.PostInstallCmd}, 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
}