Example #1
0
func getLatestInstalledPlugin(pluginDir string) (*PluginInfo, error) {
	files, err := ioutil.ReadDir(pluginDir)
	if err != nil {
		return nil, fmt.Errorf("Error listing files in plugin directory %s: %s", pluginDir, err.Error())
	}
	versionToPlugins := make(map[*version.Version][]PluginInfo, 0)
	pluginName := filepath.Base(pluginDir)

	for _, file := range files {
		if file.IsDir() {
			var v *version.Version
			var err error
			if strings.Contains(file.Name(), "nightly") {
				v, err = version.ParseVersion(file.Name()[:strings.LastIndex(file.Name(), ".")])
			} else {
				v, err = version.ParseVersion(file.Name())
			}
			if err == nil {
				versionToPlugins[v] = append(versionToPlugins[v], PluginInfo{pluginName, v, filepath.Join(pluginDir, file.Name())})
			}
		}
	}

	if len(versionToPlugins) < 1 {
		return nil, fmt.Errorf("No valid versions of plugin %s found in %s", pluginName, pluginDir)
	}
	var availableVersions []*version.Version
	for k := range versionToPlugins {
		availableVersions = append(availableVersions, k)
	}
	latestVersion := version.GetLatestVersion(availableVersions)
	latestBuild := getLatestOf(versionToPlugins[latestVersion], latestVersion)
	return &latestBuild, nil
}
Example #2
0
func createPluginUpdateDetail(currentVersion string, latestVersionDetails installDescription) []UpdateInfo {
	updateInfo := make([]UpdateInfo, 0)
	v, _ := version.ParseVersion(currentVersion)
	v1, _ := version.ParseVersion(latestVersionDetails.Versions[0].Version)
	if v.IsLesserThan(v1) {
		versionDesc, err := latestVersionDetails.getLatestCompatibleVersionTo(version.CurrentGaugeVersion)
		if err != nil {
			return updateInfo
		}
		updateInfo = append(updateInfo, UpdateInfo{latestVersionDetails.Name, versionDesc.Version, fmt.Sprintf("Run 'gauge --update %s'", latestVersionDetails.Name)})
	}
	return updateInfo
}
Example #3
0
func (s *MySuite) TestGetStablePluginAmongGivenPluginsOfAVersion(c *C) {
	v, _ := version.ParseVersion("0.2.2")

	pluginInfo1 := PluginInfo{Version: v, Path: "0.2.2"}
	plugins := []PluginInfo{pluginInfo1}
	latestBuild := getLatestOf(plugins, v)
	c.Assert(latestBuild.Version, Equals, v)

	pluginInfo2 := PluginInfo{Version: v, Path: "0.2.2.nightly-2016-02-09"}
	plugins = []PluginInfo{pluginInfo2}
	latestBuild = getLatestOf(plugins, v)
	c.Assert(latestBuild.Path, Equals, pluginInfo2.Path)
	c.Assert(latestBuild.Version, Equals, v)

	pluginInfo1.Path = "0.2.2.nightly-2015-02-03"
	pluginInfo2.Path = "0.2.2.nightly-2016-02-09"
	pluginInfo3 := PluginInfo{Version: v, Path: "0.2.2.nightly-2017-02-09"}
	plugins = []PluginInfo{pluginInfo1, pluginInfo3, pluginInfo2}
	latestBuild = getLatestOf(plugins, v)
	c.Assert(latestBuild.Path, Equals, pluginInfo3.Path)
	c.Assert(latestBuild.Version, Equals, v)

	pluginInfo1.Path = "0.2.2.nightly-2015-02-03"
	pluginInfo2.Path = "0.2.2.nightly-2016-02-04"
	plugins = []PluginInfo{pluginInfo1, pluginInfo2}
	latestBuild = getLatestOf(plugins, v)
	c.Assert(latestBuild.Path, Equals, pluginInfo2.Path)
	c.Assert(latestBuild.Version, Equals, v)

	pluginInfo1.Path = "0.2.2.nightly-2015-01-03"
	pluginInfo2.Path = "0.2.2.nightly-2015-02-03"
	plugins = []PluginInfo{pluginInfo1, pluginInfo2}
	latestBuild = getLatestOf(plugins, v)
	c.Assert(latestBuild.Path, Equals, pluginInfo2.Path)

	pluginInfo1.Path = "0.2.2.nightly-2015-01-03"
	pluginInfo2.Path = "0.2.2.nightly-2016-02-03"
	plugins = []PluginInfo{pluginInfo1, pluginInfo2}
	latestBuild = getLatestOf(plugins, v)
	c.Assert(latestBuild.Path, Equals, pluginInfo2.Path)

	pluginInfo1.Path = "0.2.2.nightly-2015-01-03"
	pluginInfo2.Path = "0.2.2.nightly-2017-02-03"
	pluginInfo2.Path = "0.2.2.nightly-2016-02-03"
	plugins = []PluginInfo{pluginInfo1, pluginInfo2}
	latestBuild = getLatestOf(plugins, v)
	c.Assert(latestBuild.Path, Equals, pluginInfo2.Path)

	pluginInfo1.Path = "0.2.2.nightly-2017-01-03"
	pluginInfo2.Path = "0.2.2.nightly-2017-01-05"
	pluginInfo2.Path = "0.2.2.nightly-2017-01-04"
	plugins = []PluginInfo{pluginInfo1, pluginInfo2}
	latestBuild = getLatestOf(plugins, v)
	c.Assert(latestBuild.Path, Equals, pluginInfo2.Path)
}
Example #4
0
func checkCompatibility(currentVersion *version.Version, versionSupport *versionSupport) error {
	minSupportVersion, err := version.ParseVersion(versionSupport.Minimum)
	if err != nil {
		return errors.New(fmt.Sprintf("Invalid minimum support version %s. : %s. ", versionSupport.Minimum, err))
	}
	if versionSupport.Maximum != "" {
		maxSupportVersion, err := version.ParseVersion(versionSupport.Maximum)
		if err != nil {
			return errors.New(fmt.Sprintf("Invalid maximum support version %s. : %s. ", versionSupport.Maximum, err))
		}
		if currentVersion.IsBetween(minSupportVersion, maxSupportVersion) {
			return nil
		} else {
			return errors.New(fmt.Sprintf("Version %s is not between %s and %s", currentVersion, minSupportVersion, maxSupportVersion))
		}
	}

	if minSupportVersion.IsLesserThanEqualTo(currentVersion) {
		return nil
	}
	return errors.New(fmt.Sprintf("Incompatible version. Minimum support version %s is higher than current version %s", minSupportVersion, currentVersion))
}
Example #5
0
func checkGaugeUpdate() []UpdateInfo {
	updateInfos := make([]UpdateInfo, 0)
	tagName, err := getLatestTagName(config.GaugeUpdateUrl())
	if err != nil {
		return updateInfos
	}
	latestVersion, err := version.ParseVersion(getVersion(tagName))
	if err != nil {
		return updateInfos
	}
	isLatestVersion := version.CurrentGaugeVersion.IsLesserThan(latestVersion)
	if isLatestVersion {
		updateInfos = append(updateInfos, UpdateInfo{"Gauge", latestVersion.String(), "Download the installer from http://getgauge.io/get-started/"})
	}
	return updateInfos
}
Example #6
0
func checkGaugeUpdate() []UpdateInfo {
	var updateInfos []UpdateInfo
	url := config.GaugeUpdateUrl()
	if qp := plugin.QueryParams(); qp != "" {
		url += qp
	}
	v, err := getLatestGaugeVersion(url)
	if err != nil {
		return updateInfos
	}
	latestVersion, err := version.ParseVersion(v)
	if err != nil {
		return updateInfos
	}
	isLatestVersion := version.CurrentGaugeVersion.IsLesserThan(latestVersion)
	if isLatestVersion {
		updateInfos = append(updateInfos, UpdateInfo{"Gauge", latestVersion.String(), "Download the installer from http://getgauge.io/get-started/"})
	}
	return updateInfos
}
Example #7
0
func getPluginLatestVersion(pluginDir string) (*version.Version, error) {
	files, err := ioutil.ReadDir(pluginDir)
	if err != nil {
		return nil, fmt.Errorf("Error listing files in plugin directory %s: %s", pluginDir, err.Error())
	}
	availableVersions := make([]*version.Version, 0)

	for _, file := range files {
		if file.IsDir() {
			version, err := version.ParseVersion(file.Name())
			if err == nil {
				availableVersions = append(availableVersions, version)
			}
		}
	}
	pluginName := filepath.Base(pluginDir)

	if len(availableVersions) < 1 {
		return nil, fmt.Errorf("No valid versions of plugin %s found in %s", pluginName, pluginDir)
	}
	latestVersion := version.GetLatestVersion(availableVersions)
	return latestVersion, nil
}
Example #8
0
func (a byDecreasingVersion) Less(i, j int) bool {
	version1, _ := version.ParseVersion(a[i].Version)
	version2, _ := version.ParseVersion(a[j].Version)
	return version1.IsGreaterThan(version2)
}