common

package module
v0.0.0-...-f75e1db Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 16 Imported by: 225

README

common

Contributor Covenant

This is a shared utility code between components written in Golang.

Prerequisite

Golang

License

common is released under the Apache License, Version 2.0. See LICENSE for the full license text.

Copyright 2015 ThoughtWorks, Inc.

Documentation

Overview

Package common functions shared across all files

Index

Constants

View Source
const (
	ManifestFile            = "manifest.json"
	PluginJSONFile          = "plugin.json"
	NewDirectoryPermissions = 0755
	NewFilePermissions      = 0644
	DefaultEnvFileName      = "default.properties"
	EnvDirectoryName        = "env"
	DefaultEnvDir           = "default"
	ProductName             = "gauge"
	DotGauge                = ".gauge"

	SpecsDirectoryName   = "specs"
	ConceptFileExtension = ".cpt"
	Plugins              = "plugins"

	GaugePropertiesFile = "gauge.properties"
	NightlyDatelayout   = "2006-01-02"
)
View Source
const (
	GaugeProjectRootEnv      = "GAUGE_PROJECT_ROOT"
	GaugeHome                = "GAUGE_HOME" //specifies the plugin installation path if installs to non-standard location
	GaugePortEnvName         = "GAUGE_PORT" // user specifies this to use a specific port
	GaugeInternalPortEnvName = "GAUGE_INTERNAL_PORT"
	APIPortEnvVariableName   = "GAUGE_API_PORT"
	APIV2PortEnvVariableName = "GAUGE_API_V2_PORT"
	GaugeDebugOptsEnv        = "GAUGE_DEBUG_OPTS" //specify the debug options to be used while launching the runner
)

Variables

This section is empty.

Functions

func AppendProperties

func AppendProperties(propertiesFile string, properties ...*Property) error

AppendProperties appends the given properties to the end of the properties file.

func AppendToFile

func AppendToFile(srcFile, destFile string) error

Appends contents of source file to destination file. If destination file is not present, Copy file action is performed

func CopyFile

func CopyFile(src, dest string) error

CopyFile creates a copy of source file to destination file

func DirExists

func DirExists(dirPath string) bool

DirExists checks if the given directory exists

func ExecutableName

func ExecutableName() string

ExecutableName returns the Gauge executable name based on user's OS

func ExecuteCommand

func ExecuteCommand(command []string, workingDir string, outputStreamWriter io.Writer, errorStreamWriter io.Writer) (*exec.Cmd, error)

ExecuteCommand executes the given command in the working directory.

func ExecuteCommandWithEnv

func ExecuteCommandWithEnv(command []string, workingDir string, outputStreamWriter io.Writer, errorStreamWriter io.Writer, env []string) (*exec.Cmd, error)

ExecuteCommandWithEnv executes command after setting the given environment

func ExecuteSystemCommand

func ExecuteSystemCommand(command []string, workingDir string, outputStreamWriter io.Writer, errorStreamWriter io.Writer) (*exec.Cmd, error)

ExecuteSystemCommand executes the given system command in the working directory.

func FileExists

func FileExists(path string) bool

FileExists checks if the given file exists

func FindFilesInDir

func FindFilesInDir(dirPath string, isValidFile func(path string) bool, shouldSkip func(path string, f os.FileInfo) bool) []string

FindFilesInDir returns a list of files for which isValidFile func returns true

func GetConfigurationDir

func GetConfigurationDir() (string, error)

GetConfigurationPrefix returns the configuration directory prefix $GAUGE_HOME or $home/.gauge/config

func GetDefaultPropertiesFile

func GetDefaultPropertiesFile() (string, error)

GetDefaultPropertiesFile returns the path of the default.properties file in the default env

func GetDirInProject

func GetDirInProject(dirName string, specPath string) (string, error)

GetDirInProject returns the path of a particular directory in a Gauge project

func GetExecutableCommand

func GetExecutableCommand(isSystemCommand bool, command ...string) *exec.Cmd

GetExecutableCommand returns the path of the executable file

func GetGaugeConfiguration

func GetGaugeConfiguration() (properties.Properties, error)

GetGaugeConfiguration parsed the gauge.properties file from GAUGE_HOME and returns the contents

func GetGaugeConfigurationFor

func GetGaugeConfigurationFor(propertiesFileName string) (properties.Properties, error)

GetGaugeConfiguration parsed the given properties file from GAUGE_HOME and returns the contents

func GetGaugeHomeDirectory

func GetGaugeHomeDirectory() (string, error)

GetGaugeHomeDirectory returns GAUGE_HOME. This is where all the plugins are installed

func GetGaugePluginVersion

func GetGaugePluginVersion(pluginName string) (string, error)

GetGaugePluginVersion returns the latest version installed of the given plugin

func GetInstallationPrefix

func GetInstallationPrefix() (string, error)

GetInstallationPrefix returns the installation directory prefix /usr or /usr/local

func GetPluginInstallPrefixes

func GetPluginInstallPrefixes() ([]string, error)

GetPluginInstallPrefixes returns the installation prefix path for the plugins

func GetPluginProperties

func GetPluginProperties(jsonPropertiesFile string) (map[string]interface{}, error)

GetPluginProperties returns the properties of the given plugin.

func GetPluginsInstallDir

func GetPluginsInstallDir(pluginName string) (string, error)

GetPluginsInstallDir returns the plugin installation directory

func GetPrimaryPluginsInstallDir

func GetPrimaryPluginsInstallDir() (string, error)

GetPrimaryPluginsInstallDir returns the primary plugin installation dir

func GetProjectRoot

func GetProjectRoot() (string, error)

GetProjectRoot returns the Gauge project root A project root is where a manifest.json files exists this routine keeps going upwards searching for manifest.json

func GetProjectRootFromSpecPath

func GetProjectRootFromSpecPath(specPath string) (string, error)

GetProjectRootFromSpecPath returns the path of the project root from a given spec path

func GetSkeletonFilePath

func GetSkeletonFilePath(filename string) (string, error)

GetSkeletonFilePath returns the path skeleton file

func GetTempDir

func GetTempDir() string

GetTempDir returns the system temp directory

func GetUniqueID

func GetUniqueID() int64

GetUniqueID returns a unique id for the proto messages

func IsPluginInstalled

func IsPluginInstalled(name, version string) bool

IsPluginInstalled checks if the given Gauge plugin version is installed

func MirrorDir

func MirrorDir(src, dst string) ([]string, error)

MirrorDir creates an exact copy of source dir to destination dir Modified version of bradfitz's camlistore (https://github.com/bradfitz/camlistore/blob/master/make.go)

func MirrorFile

func MirrorFile(src, dst string) error

MirrorFile creates an exact copy of source file to destination file Modified version of bradfitz's camlistore (https://github.com/bradfitz/camlistore/blob/master/make.go)

func ReadFileContents

func ReadFileContents(file string) (string, error)

ReadFileContents returns the contents of the file

func Remove

func Remove(path string) error

Remove removes all the files and directories recursively for the given path

func SaveFile

func SaveFile(filePath, contents string, takeBackup bool) error

SaveFile saves contents at the given filepath

func SetEnvVariable

func SetEnvVariable(key, value string) error

SetEnvVariable is a wrapper around os.SetEnv to set env variable

func SubDirectoryExists

func SubDirectoryExists(pluginDir string, pluginName string) bool

SubDirectoryExists checks if a dir for given plugin exists in the plugin directory

func TrimTrailingSpace

func TrimTrailingSpace(str string) string

TrimTrailingSpace trims the trailing spaces in the given string

func UnzipArchive

func UnzipArchive(zipFile string, dest string) (string, error)

UnzipArchive extract the zip file to destination directory

func UrlExists

func UrlExists(url string) (bool, error)

UrlExists checks if the given url exists

Types

type Property

type Property struct {
	Name         string
	Comment      string
	DefaultValue string
}

Property represents a single property in the properties file

func (*Property) String

func (property *Property) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL