Exemple #1
0
        public void Execute(VersionVariables variables, OutputContext context)
        {
            var gitVersionOptions = options.Value;

            if (gitVersionOptions.Output.Contains(OutputType.BuildServer))
            {
                buildAgent?.WriteIntegration(console.WriteLine, variables, context.UpdateBuildNumber ?? true);
            }
            if (gitVersionOptions.Output.Contains(OutputType.File))
            {
                fileSystem.WriteAllText(context.OutputFile, variables.ToString());
            }
            if (gitVersionOptions.Output.Contains(OutputType.Json))
            {
                switch (gitVersionOptions.ShowVariable)
                {
                case null:
                    console.WriteLine(variables.ToString());
                    break;

                default:
                    if (!variables.TryGetValue(gitVersionOptions.ShowVariable, out var part))
                    {
                        throw new WarningException($"'{gitVersionOptions.ShowVariable}' variable does not exist");
                    }

                    console.WriteLine(part);
                    break;
                }
            }
        }
Exemple #2
0
    public void Execute(VersionVariables variables, OutputContext context)
    {
        var gitVersionOptions = this.options.Value;

        if (gitVersionOptions.Output.Contains(OutputType.BuildServer))
        {
            this.buildAgent.WriteIntegration(this.console.WriteLine, variables, context.UpdateBuildNumber ?? true);
        }
        if (gitVersionOptions.Output.Contains(OutputType.File))
        {
            var retryOperation = new RetryAction <IOException>();
            retryOperation.Execute(() => this.fileSystem.WriteAllText(context.OutputFile, variables.ToString()));
        }

        if (!gitVersionOptions.Output.Contains(OutputType.Json))
        {
            return;
        }

        switch (gitVersionOptions.ShowVariable)
        {
        case null:
            this.console.WriteLine(variables.ToString());
            break;

        default:
            if (!variables.TryGetValue(gitVersionOptions.ShowVariable, out var part))
            {
                throw new WarningException($"'{gitVersionOptions.ShowVariable}' variable does not exist");
            }

            this.console.WriteLine(part);
            break;
        }
    }
Exemple #3
0
        public void Execute(VersionVariables variables, OutputContext context)
        {
            var gitVersionOptions = options.Value;

            if (gitVersionOptions.Output.Contains(OutputType.BuildServer))
            {
                buildAgent?.WriteIntegration(console.WriteLine, variables, context.UpdateBuildNumber ?? true);
            }
            if (gitVersionOptions.Output.Contains(OutputType.File))
            {
                var retryOperation = new OperationWithExponentialBackoff <IOException>(new ThreadSleep(), log, () => fileSystem.WriteAllText(context.OutputFile, variables.ToString()));
                retryOperation.ExecuteAsync().Wait();
            }
            if (gitVersionOptions.Output.Contains(OutputType.Json))
            {
                switch (gitVersionOptions.ShowVariable)
                {
                case null:
                    console.WriteLine(variables.ToString());
                    break;

                default:
                    if (!variables.TryGetValue(gitVersionOptions.ShowVariable, out var part))
                    {
                        throw new WarningException($"'{gitVersionOptions.ShowVariable}' variable does not exist");
                    }

                    console.WriteLine(part);
                    break;
                }
            }
        }
        public void Generate()
        {
            var filePath = Path.Combine(_directory, _fileName);

            string originalFileContents = null;

            if (File.Exists(filePath))
            {
                originalFileContents = _fileSystem.ReadAllText(filePath);
            }

            var fileExtension = Path.GetExtension(filePath);
            var template      = _templateManager.GetTemplateFor(fileExtension);
            var addFormat     = _templateManager.GetAddFormatFor(fileExtension);
            var members       = _variables.ToString(addFormat);

            var fileContents = string.Format(template, members);

            if (fileContents != originalFileContents)
            {
                _fileSystem.WriteAllText(filePath, fileContents);
            }
        }