Exemple #1
0
        protected override bool ExecuteInner()
        {
            var specificationFiles = SpecificationFiles.Select(x => x.GetMetadata("Fullpath")).ToList();
            var repository         = ControlFlow.SuppressErrors(() => GitRepository.FromLocalDirectory(BaseDirectory));

            string GetFilePath(Tool tool)
            => (AbsolutePath)BaseDirectory
            / (UseNestedNamespaces ? tool.Name : ".")
            / tool.DefaultOutputFileName;

            string GetNamespace(Tool tool)
            => !UseNestedNamespaces
                    ? BaseNamespace
                    : string.IsNullOrEmpty(BaseNamespace)
                        ? tool.Name
                        : $"{BaseNamespace}.{tool.Name}";

            string GetSourceFile(Tool tool)
            => repository.IsGitHubRepository() ? repository?.GetGitHubDownloadUrl(tool.SpecificationFile) : null;

            specificationFiles
            .ForEachLazy(x => LogMessage(message: $"Handling {x} ..."))
            .ForEach(x => CodeGenerator.GenerateCode(x, GetFilePath, GetNamespace, GetSourceFile));

            if (UpdateReferences)
            {
                ReferenceUpdater.UpdateReferences(specificationFiles);
            }

            return(true);
        }
Exemple #2
0
        public bool Execute()
        {
            var specificationFiles = SpecificationFiles.Select(x => x.GetMetadata("Fullpath")).ToList();
            var repository         = ControlFlow.SuppressErrors(() => GitRepository.FromLocalDirectory(BaseDirectory));

            CodeGenerator.GenerateCode(
                specificationFiles,
                outputFileProvider: x =>
                (AbsolutePath)BaseDirectory
                / (UseNestedNamespaces ? x.Name : ".")
                / x.DefaultOutputFileName,
                namespaceProvider: x =>
                !UseNestedNamespaces
                        ? BaseNamespace
                        : string.IsNullOrEmpty(BaseNamespace)
                            ? x.Name
                            : $"{BaseNamespace}.{x.Name}",
                sourceFileProvider: x =>
                repository.IsGitHubRepository() ? repository?.GetGitHubDownloadUrl(x.SpecificationFile) : null);

            if (UpdateReferences)
            {
                ReferenceUpdater.UpdateReferences(specificationFiles);
            }

            return(true);
        }
Exemple #3
0
        public bool Execute()
        {
            var metadataFiles = MetadataFiles.Select(x => x.GetMetadata("Fullpath")).ToList();

            if (!MetadataFiles.Any())
            {
                ControlFlow.SuppressErrors(() =>
                {
                    var exampleFile = Path.Combine(BaseDirectory, "RandomTool.json");
                    HttpTasks.HttpDownloadFile(c_exampleUrl, exampleFile);
                    metadataFiles.Add(exampleFile);
                });
            }

            CodeGenerator.GenerateCode(
                metadataFiles,
                BaseDirectory,
                UseNestedNamespaces,
                BaseNamespace,
                GitRepository.FromLocalDirectory(BaseDirectory));

            if (UpdateReferences)
            {
                ReferenceUpdater.UpdateReferences(metadataFiles);
            }

            return(true);
        }
Exemple #4
0
 public override object GetValue(MemberInfo member, object instance)
 {
     return(ControlFlow.SuppressErrors(() =>
                                       GitRepository.FromLocalDirectory(
                                           NukeBuild.RootDirectory,
                                           Branch ?? GetBranch(),
                                           Remote ?? "origin")));
 }
Exemple #5
0
        public void Execute()
        {
            if (_downloadSchema)
            {
                ControlFlow.SuppressErrors(() =>
                                           HttpTasks.HttpDownloadFile(c_schemaDownloadUrl, (RelativePath)_metadataDirectory / c_schemaFileName));
            }

            var files = Directory.GetFiles(_metadataDirectory, "*.json", SearchOption.TopDirectoryOnly).Where(x => !x.EndsWith(c_schemaFileName));

            files.AsParallel().ForAll(HandleFile);
        }
        public override object GetValue(MemberInfo member, object instance)
        {
            // TODO: https://github.com/GitTools/GitVersion/issues/1097
            if (EnvironmentInfo.IsUnix && DisableOnUnix)
            {
                Logger.Warn($"{nameof(GitVersion)} is disabled on UNIX environment.");
                return(null);
            }

            return(ControlFlow.SuppressErrors(() =>
                                              GitVersionTasks.GitVersion(s => s
                                                                         .DisableLogOutput())
                                              .Result,
                                              includeStackTrace: true));
        }
Exemple #7
0
        private static IDictionary <string, string> GetCommonProperties(NukeBuild build = null)
        {
            var process = ControlFlow.SuppressErrors(
                () => ProcessTasks.StartProcess(DotNetTasks.DotNetPath, "--version", logInvocation: false, logOutput: false).AssertWaitForExit(),
                logWarning: false);

            return(new Dictionary <string, string>
            {
                ["os_platform"] = EnvironmentInfo.Platform.ToString(),
                ["os_architecture"] = RuntimeInformation.OSArchitecture.ToString(),
                ["version_dotnet_sdk"] = process?.ExitCode == 0 ? process.Output.First().Text : null,
                ["version_nuke_common"] = build != null ? typeof(NukeBuild).Assembly.GetVersionText() : null,
                ["version_nuke_global_tool"] = build != null
                           ? EnvironmentInfo.Variables.GetValueOrDefault(Constants.GlobalToolVersionEnvironmentKey)
                           : Assembly.GetEntryAssembly().GetVersionText()
            });
        }
Exemple #8
0
        private static IDictionary <string, string> GetRepositoryProperties(string directory)
        {
            var repository = ControlFlow.SuppressErrors(() => GitRepository.FromLocalDirectory(directory), logWarning: false);

            if (repository == null)
            {
                return(new Dictionary <string, string>());
            }

            var providers =
                new List <(Func <bool>, string)>
            {
                (() => repository.Endpoint.ContainsOrdinalIgnoreCase("github.com"), "GitHub"),
                (() => repository.Endpoint.ContainsOrdinalIgnoreCase("gitlab.com"), "GitLab"),
                (() => repository.Endpoint.ContainsOrdinalIgnoreCase("bitbucket.org"), "Bitbucket"),
                (() => repository.Endpoint.ContainsOrdinalIgnoreCase("jetbrains.space"), "JetBrains"),
                (() => repository.Endpoint.ContainsOrdinalIgnoreCase("visualstudio.com"), "Azure")
            };

            var branches =
                new List <(Func <bool>, string)>
            {
                (() => repository.IsOnMainOrMasterBranch(), "main"),
                (() => repository.IsOnDevelopBranch(), "develop"),
                (() => repository.IsOnReleaseBranch(), "release"),
                (() => repository.IsOnHotfixBranch(), "hotfix")
            };

            return(new Dictionary <string, string>
            {
                ["repo_provider"] = providers.FirstOrDefault(x => x.Item1.Invoke()).Item2,
                ["repo_branch"] = branches.FirstOrDefault(x => x.Item1.Invoke()).Item2,
                ["repo_url"] = repository.SshUrl.GetSHA256Hash().Substring(startIndex: 0, length: 6),
                ["repo_commit"] = repository.Commit.GetSHA256Hash().Substring(startIndex: 0, length: 6)
            });
        }
 public override object GetStaticValue()
 {
     return(Value = Value
                    ?? ControlFlow.SuppressErrors(() =>
                                                  GitRepository.FromLocalDirectory(NukeBuild.Instance.RootDirectory, Branch, Remote.NotNull())));
 }
 public object TryGetValue(MemberInfo member, object instance)
 {
     return(ControlFlow.SuppressErrors(() => GetValue(member, instance), includeStackTrace: true));
 }
 public override object GetStaticValue()
 {
     return(Value = Value
                    ?? ControlFlow.SuppressErrors(() =>
                                                  GitRepository.TryParse(NukeBuild.Instance.RootDirectory)));
 }