示例#1
0
文件: install.go 项目: 0-T-0/gauge
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("")
}
示例#2
0
// InstallPluginFromZipFile installs plugin from given zip file
func InstallPluginFromZipFile(zipFile string, pluginName string) InstallResult {
	tempDir := common.GetTempDir()
	defer common.Remove(tempDir)
	unzippedPluginDir, err := common.UnzipArchive(zipFile, tempDir)
	if err != nil {
		return installError(err)
	}

	gp, err := parsePluginJSON(unzippedPluginDir, pluginName)
	if err != nil {
		return installError(err)
	}

	if err = runPlatformCommands(gp.PreInstall, unzippedPluginDir); err != nil {
		return installError(err)
	}

	pluginInstallDir, err := getPluginInstallDir(gp.ID, getVersionedPluginDirName(zipFile))
	if err != nil {
		return installError(err)
	}

	// copy files to gauge plugin install location
	logger.Info("Installing plugin %s %s", gp.ID, filepath.Base(pluginInstallDir))
	if _, err = common.MirrorDir(unzippedPluginDir, pluginInstallDir); err != nil {
		return installError(err)
	}

	if err = runPlatformCommands(gp.PostInstall, pluginInstallDir); err != nil {
		return installError(err)
	}
	return installSuccess("")
}
示例#3
0
文件: install.go 项目: 0-T-0/gauge
func InstallPluginZip(zipFile string, pluginName string) {
	tempDir := common.GetTempDir()
	unzippedPluginDir, err := common.UnzipArchive(zipFile, tempDir)
	defer common.Remove(tempDir)
	if err != nil {
		common.Remove(tempDir)
		logger.Fatalf("Failed to install plugin. %s\n", err.Error())
	}
	logger.Info("Plugin unzipped to => %s\n", unzippedPluginDir)

	hasPluginJSON := common.FileExists(filepath.Join(unzippedPluginDir, pluginJSON))
	if hasPluginJSON {
		err = installPluginFromDir(unzippedPluginDir)
	} else {
		err = installRunnerFromDir(unzippedPluginDir, pluginName)
	}
	if err != nil {
		common.Remove(tempDir)
		logger.Fatalf("Failed to install plugin. %s\n", err.Error())
	}
	logger.Info("Successfully installed plugin from file.")
}
示例#4
0
文件: install.go 项目: 0-T-0/gauge
func getInstallDescription(plugin string) (*installDescription, installResult) {
	versionInstallDescriptionJSONFile := plugin + "-install.json"
	versionInstallDescriptionJSONUrl, result := constructPluginInstallJSONURL(plugin)
	if !result.Success {
		return nil, installError(fmt.Sprintf("Could not construct plugin install json file URL. %s", result.Error))
	}
	tempDir := common.GetTempDir()
	defer common.Remove(tempDir)
	downloadedFile, downloadErr := common.Download(versionInstallDescriptionJSONUrl, tempDir)
	if downloadErr != nil {
		return nil, installError(fmt.Sprintf("Invalid plugin : Could not download %s file. %s", versionInstallDescriptionJSONFile, downloadErr))
	}

	return getInstallDescriptionFromJSON(downloadedFile)
}
示例#5
0
func getInstallDescription(plugin string, silent bool) (*installDescription, InstallResult) {
	versionInstallDescriptionJSONFile := plugin + "-install.json"
	versionInstallDescriptionJSONUrl, result := constructPluginInstallJSONURL(plugin)
	if !result.Success {
		return nil, installError(fmt.Errorf("Could not construct plugin install json file URL. %s", result.Error))
	}
	tempDir := common.GetTempDir()
	defer common.Remove(tempDir)

	downloadedFile, downloadErr := util.Download(versionInstallDescriptionJSONUrl, tempDir, versionInstallDescriptionJSONFile, silent)
	if downloadErr != nil {
		logger.Debug("Failed to download %s file: %s", versionInstallDescriptionJSONFile, downloadErr)
		return nil, installError(fmt.Errorf("Invalid plugin. Could not download %s file.", versionInstallDescriptionJSONFile))
	}

	return getInstallDescriptionFromJSON(downloadedFile)
}
示例#6
0
func installPluginVersion(installDesc *installDescription, versionInstallDescription *versionInstallDescription) InstallResult {
	if common.IsPluginInstalled(installDesc.Name, versionInstallDescription.Version) {
		return installSkipped(fmt.Sprintf("Plugin %s %s is already installed.", installDesc.Name, versionInstallDescription.Version))
	}

	downloadLink, err := getDownloadLink(versionInstallDescription.DownloadUrls)
	if err != nil {
		return installError(fmt.Errorf("Could not get download link: %s", err.Error()))
	}

	tempDir := common.GetTempDir()
	defer common.Remove(tempDir)
	logger.Info("Downloading %s", filepath.Base(downloadLink))
	pluginZip, err := util.Download(downloadLink, tempDir, "", false)
	if err != nil {
		return installError(fmt.Errorf("Failed to download the plugin. %s", err.Error()))
	}
	return InstallPluginFromZipFile(pluginZip, installDesc.Name)
}
示例#7
0
// Remove removes all the files and directories recursively for the given path
func Remove(dir string) {
	err := common.Remove(dir)
	if err != nil {
		logger.Warning("Failed to remove directory %s. Remove it manually. %s", dir, err.Error())
	}
}