// 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("") }
func installPluginFromZip(zipFile string, language string) error { unzippedPluginDir, err := common.UnzipArchive(zipFile) if err != nil { return fmt.Errorf("Failed to unzip plugin-zip file %s.", err.Error()) } logger.Info("Plugin unzipped to => %s\n", unzippedPluginDir) hasPluginJSON := common.FileExists(filepath.Join(unzippedPluginDir, pluginJSON)) if hasPluginJSON { return installPluginFromDir(unzippedPluginDir) } return installRunnerFromDir(unzippedPluginDir, language) }
func installPluginFromZip(zipFile string, language string) error { unzippedPluginDir, err := common.UnzipArchive(zipFile) if err != nil { return errors.New(fmt.Sprintf("Failed to unzip plugin-zip file %s.", err)) } logger.Log.Info("Plugin unzipped to => %s\n", unzippedPluginDir) hasPluginJson := common.FileExists(filepath.Join(unzippedPluginDir, pluginJson)) if hasPluginJson { return installPluginFromDir(unzippedPluginDir) } else { return installRunnerFromDir(unzippedPluginDir, language) } }
// DownloadAndUnzip downloads the zip file from given download link and unzips it. // Returns the unzipped file path. func DownloadAndUnzip(downloadLink string, tempDir string) (string, error) { logger.Debug("Downloading => %s", downloadLink) downloadedFile, err := common.Download(downloadLink, tempDir) if err != nil { return "", fmt.Errorf("Could not download file %s: %s", downloadLink, err.Error()) } logger.Debug("Downloaded to %s", downloadedFile) unzippedPluginDir, err := common.UnzipArchive(downloadedFile, tempDir) if err != nil { return "", fmt.Errorf("Failed to Unzip file %s: %s", downloadedFile, err.Error()) } logger.Debug("Unzipped to => %s\n", unzippedPluginDir) return unzippedPluginDir, nil }
// DownloadAndUnzip downloads the zip file from given download link and unzips it. // Returns the unzipped file path. func DownloadAndUnzip(downloadLink string, tempDir string) (string, error) { logger.Info("Downloading %s", filepath.Base(downloadLink)) logger.Debug("Download URL %s", downloadLink) downloadedFile, err := Download(downloadLink, tempDir, "", false) if err != nil { return "", err } logger.Debug("Downloaded to %s", downloadedFile) unzippedPluginDir, err := common.UnzipArchive(downloadedFile, tempDir) if err != nil { return "", fmt.Errorf("Failed to Unzip file %s: %s", downloadedFile, err.Error()) } logger.Debug("Unzipped to => %s\n", unzippedPluginDir) return unzippedPluginDir, nil }
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.") }
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.Log.Info("Installing Plugin => %s %s\n", installDesc.Name, versionInstallDescription.Version) pluginZip, err := downloadPluginZip(versionInstallDescription.DownloadUrls) if err != nil { return installError(fmt.Sprintf("Could not download plugin zip: %s.", err)) } unzippedPluginDir, err := common.UnzipArchive(pluginZip) if err != nil { return installError(fmt.Sprintf("Failed to Unzip plugin-zip file %s.", err)) } logger.Log.Info("Plugin unzipped to => %s\n", unzippedPluginDir) if err := runInstallCommands(versionInstallDescription.Install, unzippedPluginDir); err != nil { return installError(fmt.Sprintf("Failed to Run install command. %s.", err)) } err = copyPluginFilesToGauge(installDesc, versionInstallDescription, unzippedPluginDir) if err != nil { installError(err.Error()) } return installSuccess("") }