Example #1
0
func (parser *ConceptParser) ParseFile(file string) ([]*Step, *ParseDetailResult) {
	fileText, fileReadErr := common.ReadFileContents(file)
	if fileReadErr != nil {
		return nil, &ParseDetailResult{Error: &ParseError{Message: fmt.Sprintf("failed to read concept file %s", file)}}
	}
	return parser.Parse(fileText)
}
Example #2
0
// 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.")
}
Example #3
0
// 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.")
}
Example #4
0
func writeConceptToFile(concept string, conceptUsageText string, conceptFileName string, fileName string, info *gauge_messages.TextInfo) {
	if _, err := os.Stat(conceptFileName); os.IsNotExist(err) {
		os.Create(conceptFileName)
	}
	content, _ := common.ReadFileContents(conceptFileName)
	util.SaveFile(conceptFileName, content+"\n"+concept, true)
	text := ReplaceExtractedStepsWithConcept(info, conceptUsageText)
	util.SaveFile(fileName, text, true)
}
Example #5
0
func getInstallDescriptionFromJSON(installJSON string) (*installDescription, installResult) {
	InstallJSONContents, readErr := common.ReadFileContents(installJSON)
	if readErr != nil {
		return nil, installError(readErr.Error())
	}
	installDescription := &installDescription{}
	if err := json.Unmarshal([]byte(InstallJSONContents), installDescription); err != nil {
		return nil, installError(err.Error())
	}
	return installDescription, installSuccess("")
}
Example #6
0
func installRunnerFromDir(unzippedPluginDir string, language string) error {
	var r runner.Runner
	contents, err := common.ReadFileContents(filepath.Join(unzippedPluginDir, language+jsonExt))
	if err != nil {
		return err
	}
	err = json.Unmarshal([]byte(contents), &r)
	if err != nil {
		return err
	}
	return copyPluginFilesToGaugeInstallDir(unzippedPluginDir, r.Id, r.Version)
}
Example #7
0
func ExtractConcept(conceptName *gauge_messages.Step, steps []*gauge_messages.Step, conceptFileName string, changeAcrossProject bool, selectedTextInfo *gauge_messages.TextInfo) (bool, error, []string) {
	content := SPEC_HEADING_TEMPLATE
	if util.IsSpec(selectedTextInfo.GetFileName()) {
		content, _ = common.ReadFileContents(selectedTextInfo.GetFileName())
	}
	concept, conceptUsageText, err := getExtractedConcept(conceptName, steps, content)
	if err != nil {
		return false, err, []string{}
	}
	writeConceptToFile(concept, conceptUsageText, conceptFileName, selectedTextInfo.GetFileName(), selectedTextInfo)
	return true, errors.New(""), []string{conceptFileName, selectedTextInfo.GetFileName()}
}
Example #8
0
func getRunnerJSONContents(file string) (*runner.Runner, error) {
	var r runner.Runner
	contents, err := common.ReadFileContents(file)
	if err != nil {
		return nil, err
	}
	err = json.Unmarshal([]byte(contents), &r)
	if err != nil {
		return nil, err
	}
	return &r, nil
}
Example #9
0
func GetPluginDescriptorFromJSON(pluginJSON string) (*pluginDescriptor, error) {
	pluginJSONContents, err := common.ReadFileContents(pluginJSON)
	if err != nil {
		return nil, err
	}
	var pd pluginDescriptor
	if err = json.Unmarshal([]byte(pluginJSONContents), &pd); err != nil {
		return nil, fmt.Errorf("%s: %s", pluginJSON, err.Error())
	}
	pd.pluginPath = filepath.Dir(pluginJSON)

	return &pd, nil
}
Example #10
0
func initializePredefinedResolvers() map[string]resolverFn {
	return map[string]resolverFn{
		"file": func(filePath string) (*gauge.StepArg, error) {
			fileContent, err := common.ReadFileContents(util.GetPathToFile(filePath))
			if err != nil {
				return nil, err
			}
			return &gauge.StepArg{Value: fileContent, ArgType: gauge.SpecialString}, nil
		},
		"table": func(filePath string) (*gauge.StepArg, error) {
			csv, err := common.ReadFileContents(util.GetPathToFile(filePath))
			if err != nil {
				return nil, err
			}
			csvTable, err := convertCsvToTable(csv)
			if err != nil {
				return nil, err
			}
			return &gauge.StepArg{Table: *csvTable, ArgType: gauge.SpecialTable}, nil
		},
	}
}
Example #11
0
func getPluginDescriptorFromJson(pluginJson string) (*pluginDescriptor, error) {
	pluginJsonContents, err := common.ReadFileContents(pluginJson)
	if err != nil {
		return nil, err
	}
	var pd pluginDescriptor
	if err = json.Unmarshal([]byte(pluginJsonContents), &pd); err != nil {
		return nil, errors.New(fmt.Sprintf("%s: %s", pluginJson, err.Error()))
	}
	pd.pluginPath = filepath.Dir(pluginJson)

	return &pd, nil
}
Example #12
0
func initializePredefinedResolvers() map[string]resolverFn {
	return map[string]resolverFn{
		"file": func(filePath string) (*stepArg, error) {
			fileContent, err := common.ReadFileContents(filePath)
			if err != nil {
				return nil, err
			}
			return &stepArg{value: fileContent, argType: specialString}, nil
		},
		"table": func(filePath string) (*stepArg, error) {
			csv, err := common.ReadFileContents(filePath)
			if err != nil {
				return nil, err
			}
			csvTable, err := convertCsvToTable(csv)
			if err != nil {
				return nil, err
			}
			return &stepArg{table: *csvTable, argType: specialTable}, nil
		},
	}
}
Example #13
0
func getLanguageJSONFilePath(manifest *manifest.Manifest, r *Runner) (string, error) {
	languageJsonFilePath, err := common.GetLanguageJSONFilePath(manifest.Language)
	if err != nil {
		return "", err
	}
	contents, err := common.ReadFileContents(languageJsonFilePath)
	if err != nil {
		return "", err
	}
	err = json.Unmarshal([]byte(contents), r)
	if err != nil {
		return "", err
	}
	return filepath.Dir(languageJsonFilePath), nil
}
Example #14
0
func AddConcepts(conceptFile string, conceptDictionary *ConceptDictionary) *ParseError {
	fileText, fileReadErr := common.ReadFileContents(conceptFile)
	if fileReadErr != nil {
		return &ParseError{Message: fmt.Sprintf("failed to read concept file %s", conceptFile)}
	}
	concepts, parseResults := new(ConceptParser).Parse(fileText)
	if parseResults != nil && parseResults.Warnings != nil {
		for _, warning := range parseResults.Warnings {
			logger.Log.Warning(warning.String())
		}
	}
	if parseResults != nil && parseResults.Error != nil {
		return parseResults.Error
	}
	return conceptDictionary.Add(concepts, conceptFile)
}
Example #15
0
func IsCompatibleLanguagePluginInstalled(name string) bool {
	jsonFilePath, err := common.GetLanguageJSONFilePath(name)
	if err != nil {
		return false
	}
	var r runner.Runner
	contents, err := common.ReadFileContents(jsonFilePath)
	if err != nil {
		return false
	}
	err = json.Unmarshal([]byte(contents), &r)
	if err != nil {
		return false
	}
	return (version.CheckCompatibility(version.CurrentGaugeVersion, &r.GaugeVersionSupport) == nil)
}
Example #16
0
func GetRunnerInfo(language string) (*Runner, error) {
	runnerInfo := new(Runner)
	languageJsonFilePath, err := common.GetLanguageJSONFilePath(language)
	if err != nil {
		return nil, err
	}

	contents, err := common.ReadFileContents(languageJsonFilePath)
	if err != nil {
		return nil, err
	}

	err = json.Unmarshal([]byte(contents), &runnerInfo)
	if err != nil {
		return nil, err
	}
	return runnerInfo, nil
}
Example #17
0
func ProjectManifest() (*Manifest, error) {
	contents, err := common.ReadFileContents(path.Join(config.ProjectRoot, common.ManifestFile))
	if err != nil {
		return nil, err
	}
	dec := json.NewDecoder(strings.NewReader(contents))

	var m Manifest
	for {
		if err := dec.Decode(&m); err == io.EOF {
			break
		} else if err != nil {
			return nil, fmt.Errorf("Failed to read Manifest. %s\n", err.Error())
		}
	}

	return &m, nil
}
Example #18
0
func parseSpec(specFile string, conceptDictionary *conceptDictionary, specChannel chan *specification, parseResultChan chan *parseResult) {
	specFileContent, err := common.ReadFileContents(specFile)
	if err != nil {
		specChannel <- nil
		parseResultChan <- &parseResult{error: &parseError{message: err.Error()}, ok: false, fileName: specFile}
		return
	}
	spec, parseResult := new(specParser).parse(specFileContent, conceptDictionary)
	parseResult.fileName = specFile
	if !parseResult.ok {
		specChannel <- nil
		parseResultChan <- parseResult
		return
	}
	spec.fileName = specFile
	specChannel <- spec
	parseResultChan <- parseResult
}
Example #19
0
func parseSpec(specFile string, conceptDictionary *ConceptDictionary, specChannel chan *Specification, parseResultChan chan *ParseResult) {
	specFileContent, err := common.ReadFileContents(specFile)
	if err != nil {
		specChannel <- nil
		parseResultChan <- &ParseResult{ParseError: &ParseError{Message: err.Error()}, Ok: false, FileName: specFile}
		return
	}
	spec, parseResult := new(SpecParser).Parse(specFileContent, conceptDictionary)
	parseResult.FileName = specFile
	if !parseResult.Ok {
		specChannel <- nil
		parseResultChan <- parseResult
		return
	}
	spec.FileName = specFile
	specChannel <- spec
	parseResultChan <- parseResult
}
Example #20
0
func parsePluginJSON(pluginDir, pluginName string) (*GaugePlugin, error) {
	var file string
	if common.FileExists(filepath.Join(pluginDir, pluginName+jsonExt)) {
		file = filepath.Join(pluginDir, pluginName+jsonExt)
	} else {
		file = filepath.Join(pluginDir, pluginJSON)
	}

	var gp GaugePlugin
	contents, err := common.ReadFileContents(file)
	if err != nil {
		return nil, err
	}
	if err = json.Unmarshal([]byte(contents), &gp); err != nil {
		return nil, err
	}
	return &gp, nil
}
Example #21
0
File: init.go Project: 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
}
Example #22
0
func (s *MySuite) TestDownloadSuccess(c *C) {
	os.Mkdir("temp", 0755)
	defer os.RemoveAll("temp")

	handler := func(w http.ResponseWriter, r *http.Request) {
		http.Error(w, "All OK", http.StatusOK)
	}

	server := httptest.NewServer(http.HandlerFunc(handler))
	defer server.Close()

	actualDownloadedFilePath, err := Download(server.URL, "temp", "", false)
	expectedDownloadFilePath := filepath.Join("temp", strings.TrimPrefix(server.URL, "http://"))
	absoluteDownloadFilePath, _ := filepath.Abs(expectedDownloadFilePath)
	expectedFileContents := "All OK\n"

	c.Assert(err, Equals, nil)
	c.Assert(actualDownloadedFilePath, Equals, expectedDownloadFilePath)
	c.Assert(common.FileExists(absoluteDownloadFilePath), Equals, true)

	actualFileContents, err := common.ReadFileContents(absoluteDownloadFilePath)
	c.Assert(err, Equals, nil)
	c.Assert(actualFileContents, Equals, expectedFileContents)
}
Example #23
0
func ReplaceExtractedStepsWithConcept(selectedTextInfo *gauge_messages.TextInfo, conceptText string) string {
	content, _ := common.ReadFileContents(selectedTextInfo.GetFileName())
	return replaceText(content, selectedTextInfo, conceptText)
}