コード例 #1
0
ファイル: init.go プロジェクト: andrewmkrug/gauge
// ListTemplates lists all the Gauge templates available in GaugeTemplatesURL
func ListTemplates() {
	templatesURL := config.GaugeTemplatesUrl()
	_, err := common.UrlExists(templatesURL)
	if err != nil {
		fmt.Printf("Gauge templates URL is not reachable: %s\n", err.Error())
		os.Exit(1)
	}
	tempDir := common.GetTempDir()
	defer util.Remove(tempDir)
	templatesPage, err := common.Download(templatesURL, tempDir)
	if err != nil {
		fmt.Printf("Error occurred while downloading templates list: %s\n", err.Error())
		os.Exit(1)
	}

	templatePageContents, err := common.ReadFileContents(templatesPage)
	if err != nil {
		fmt.Printf("Failed to read contents of file %s: %s\n", templatesPage, err.Error())
		os.Exit(1)
	}
	templates := getTemplateNames(templatePageContents)
	for _, template := range templates {
		fmt.Println(template)
	}
	fmt.Println("\nRun `gauge --init <template_name>` to create a new Gauge project.")
}
コード例 #2
0
ファイル: install.go プロジェクト: mattdotmatt/gauge
// 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 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("")
}
コード例 #4
0
ファイル: builder.go プロジェクト: manuviswam/gauge-go
// LoadGaugeImpls builds the go project and runs the generated go file,
// so that the gauge specific implementations get scanned
func LoadGaugeImpls() error {
	var b bytes.Buffer
	buff := bufio.NewWriter(&b)

	if err := util.RunCommand(os.Stdout, os.Stdout, constants.CommandGo, "build", "./..."); err != nil {
		buff.Flush()
		return fmt.Errorf("Build failed: %s\n", err.Error())
	}

	// get list of all packages in the projectRoot
	if err := util.RunCommand(buff, buff, constants.CommandGo, "list", "./..."); err != nil {
		buff.Flush()
		fmt.Printf("Failed to get the list of all packages: %s\n%s", err.Error(), b.String())
	}

	tempDir := common.GetTempDir()
	defer os.RemoveAll(tempDir)

	gaugeGoMainFile := filepath.Join(tempDir, constants.GaugeTestMainFileName)
	f, err := os.Create(gaugeGoMainFile)
	if err != nil {
		return fmt.Errorf("Failed to create main file in %s: %s", tempDir, err.Error())
	}

	genGaugeTestFileContents(f, b.String())
	f.Close()
	// Scan gauge methods
	if err := util.RunCommand(os.Stdout, os.Stdout, constants.CommandGo, "run", gaugeGoMainFile); err != nil {
		return fmt.Errorf("Failed to compile project: %s\nPlease ensure the project is in GOPATH.\n", err.Error())
	}
	return nil
}
コード例 #5
0
ファイル: init.go プロジェクト: mattdotmatt/gauge
// ListTemplates lists all the Gauge templates available in GaugeTemplatesURL
func ListTemplates() {
	templatesURL := config.GaugeTemplatesUrl()
	_, err := common.UrlExists(templatesURL)
	if err != nil {
		logger.Fatalf("Gauge templates URL is not reachable: %s", err.Error())
	}
	tempDir := common.GetTempDir()
	defer util.Remove(tempDir)
	templatesPage, err := util.Download(templatesURL, tempDir, "", true)
	if err != nil {
		util.Remove(tempDir)
		logger.Fatalf("Error occurred while downloading templates list: %s", err.Error())
	}

	templatePageContents, err := common.ReadFileContents(templatesPage)
	if err != nil {
		util.Remove(tempDir)
		logger.Fatalf("Failed to read contents of file %s: %s", templatesPage, err.Error())
	}
	templates := getTemplateNames(templatePageContents)
	for _, template := range templates {
		logger.Info(template)
	}
	logger.Info("\nRun `gauge --init <template_name>` to create a new Gauge project.")
}
コード例 #6
0
ファイル: install.go プロジェクト: magictests/gauge
func InstallPlugin(pluginName, version string) installResult {
	installDescription, result := getInstallDescription(pluginName)
	if !result.Success {
		return result
	}
	defer removeTempDir(common.GetTempDir())
	return installPluginWithDescription(installDescription, version)
}
コード例 #7
0
func build(destination string, classpath string) {
	os.RemoveAll(destination)
	os.Mkdir(destination, 0755)
	args := []string{"-encoding", "UTF-8", "-d", destination, "-cp", classpath}
	javaFiles := make([]string, 0)
	resourceFiles := make(map[string][]string, 0)

	srcDirs := make([]string, 0)

	value := os.Getenv(custom_compile_dir)
	if len(value) > 0 {
		paths := splitByComma(value)
		for _, src := range paths {
			srcDirs = append(srcDirs, src)
		}
	}
	srcDirs = append(srcDirs, defaultSrcDir)

	for _, srcDirItem := range srcDirs {
		filepath.Walk(srcDirItem, func(currentPath string, info os.FileInfo, err error) error {
			if err != nil {
				return err
			}
			if filepath.Ext(currentPath) == javaExt {
				javaFiles = append(javaFiles, currentPath)
			} else if !info.IsDir() {
				if _, ok := resourceFiles[srcDirItem]; !ok {
					resourceFiles[srcDirItem] = make([]string, 0)
				}
				listOfFiles := resourceFiles[srcDirItem]
				listOfFiles = append(listOfFiles, currentPath)
				resourceFiles[srcDirItem] = listOfFiles
			}
			return nil
		})
	}
	if len(javaFiles) == 0 {
		return
	}

	// Writing all java src file names to a file and using it as a @filename parameter to javac. Eg: javac -cp jar1:jar2 @sources.txt
	// This needs to be done because if the number of java files is too high the command length will be more than that permitted by the os.
	tempDir := common.GetTempDir()
	defer os.RemoveAll(tempDir)

	sourcesFile := filepath.Join(tempDir, uniqueFileName())
	if err := writeLines(javaFiles, sourcesFile); err != nil {
		panic("Unable to write file: " + err.Error())
	}
	args = append(args, "@"+sourcesFile)
	javac := getExecPathFrom(java_home, alternate_java_home, execName("javac"))

	//TODO: should move to logs
	//fmt.Println(fmt.Sprintf("Building files in %s directory to %s", "src", destination))
	runCommand(javac, args)
	copyResources(resourceFiles, destination)
}
コード例 #8
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)
}
コード例 #9
0
ファイル: install.go プロジェクト: mattdotmatt/gauge
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)
}
コード例 #10
0
ファイル: init.go プロジェクト: 0-T-0/gauge
func initializeTemplate(templateName string) error {
	tempDir := common.GetTempDir()
	defer util.Remove(tempDir)
	unzippedTemplate, err := util.DownloadAndUnzip(getTemplateURL(templateName), tempDir)
	if err != nil {
		return err
	}

	wd := config.ProjectRoot

	logger.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 != "" {
		command := strings.Split(metadata.PostInstallCmd, " ")
		cmd, err := common.ExecuteSystemCommand(command, 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
}
コード例 #11
0
ファイル: install.go プロジェクト: mattdotmatt/gauge
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)
}
コード例 #12
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.")
}
コード例 #13
0
ファイル: funcExecutor.go プロジェクト: manuviswam/gauge-go
func getScreenshot() []byte {
	if os.Getenv(constants.ScreenshotOnFailure) == "true" {
		if *CustomScreenShot != nil {
			fn := reflect.ValueOf(*CustomScreenShot)
			screenShotBytes := fn.Call(make([]reflect.Value, 0))
			return screenShotBytes[0].Interface().([]byte)
		}
		tmpDir := common.GetTempDir()
		defer os.RemoveAll(tmpDir)
		var b bytes.Buffer
		buff := bufio.NewWriter(&b)
		screenshotFile := filepath.Join(tmpDir, screenshotFileName)
		util.RunCommand(buff, buff, constants.GaugeScreenshot, screenshotFile)
		bytes, err := ioutil.ReadFile(screenshotFile)
		if err != nil {
			fmt.Println(err.Error())
			return nil
		}
		return bytes
	}
	return nil
}
コード例 #14
0
ファイル: fileUtils.go プロジェクト: mattdotmatt/gauge
// RemoveTempDir removes the temp dir
func RemoveTempDir() {
	Remove(common.GetTempDir())
}