public static void GenerateSpecifications(SpecificationGeneratorSettings settings) { Console.WriteLine("Generating Helm specifications..."); var definitions = DefinitionLoader.LoadDefinitions(settings.DefinitionFolder); definitions.SelectMany(x => x.Options).Concat(definitions.SelectMany(x => x.InheritedOptions)).Select(x => x.Type).ToHashSet() .OrderBy(x => x).ForEach(x => Console.WriteLine(x)); var tool = DefinitionParser.Parse(definitions, settings.Reference); var overwrites = settings.OverwriteFile != null?DefinitionLoader.LoadOverwrites(settings.OverwriteFile) : null; if (overwrites != null) { SpecificationModifier.Overwrite(tool, overwrites); } tool.SpecificationFile = PathConstruction.Combine(settings.OutputFolder, "Helm.json"); Directory.CreateDirectory(settings.OutputFolder); ToolSerializer.Save(tool, tool.SpecificationFile); Console.WriteLine(); Console.WriteLine("Generation finished."); Console.WriteLine($"Created Tasks: {tool.Tasks.Count}"); Console.WriteLine($"Created Data Classes: {tool.DataClasses.Count}"); Console.WriteLine($"Created Enumerations: {tool.Enumerations.Count}"); Console.WriteLine($"Created Common Task Properties: {tool.CommonTaskProperties.Count}"); Console.WriteLine($"Created Common Task Property Sets: {tool.CommonTaskPropertySets.Count}"); }
private static string[] GetAssemblyDirectories(string packageDirectory) { string GetBestFrameworkDirectory(string libDirectory) { var frameworkDirectory = PathConstruction.Combine(libDirectory, "lib"); if (!Directory.Exists(frameworkDirectory)) { return(null); } var bestFramework = Directory.GetDirectories(frameworkDirectory) .Select(Path.GetFileName) .Where(x => x.StartsWith("dotnet") || x.StartsWith("net")) .OrderBy(x => x.StartsWith("dotnet") || x.StartsWith("netstandard") ? $"!{x}" : x) .First(); return(PathConstruction.Combine(frameworkDirectory, bestFramework)); } return(Directory.GetDirectories(packageDirectory) .Select(GetBestFrameworkDirectory) .WhereNotNull() .ToArray()); }
/// <summary> /// Finalizes the changelog by moving all entries from `[vNext]` to the version specified by release. /// <p>If <paramref name="repository"/> is specified a summary with all versions and links to list the changes directly on GitHub is appended to the end of the changelog.</p> /// </summary> /// <param name="changelogFile">The path to the changelog file.</param> /// <param name="tag">The version to finalize the changelog.</param> /// <param name="repository">The repository to create the version overview for.</param> /// <seealso cref="FinalizeChangelog(ChangeLog,NuGetVersion,GitRepository)"/> public static void FinalizeChangelog(string changelogFile, string tag, [CanBeNull] GitRepository repository = null) { Logger.Info($"Finalizing {PathConstruction.GetRelativePath(NukeBuild.RootDirectory, changelogFile)} for '{tag}'..."); var content = TextTasks.ReadAllLines(changelogFile).ToList(); var sections = GetReleaseSections(content).ToList(); var firstSection = sections.First(); var secondSection = sections.Skip(1).FirstOrDefault(); ControlFlow.Assert(firstSection.Caption.All(char.IsLetter), "Cannot find a draft section."); ControlFlow.Assert(sections.All(x => !x.Caption.EqualsOrdinalIgnoreCase(tag)), $"Tag '{tag}' already exists."); ControlFlow.Assert(firstSection.EndIndex > firstSection.StartIndex, $"Draft section '{firstSection.Caption}' does not contain any information."); ControlFlow.Assert(secondSection == null || NuGetVersion.Parse(tag).CompareTo(NuGetVersion.Parse(secondSection.Caption)) > 0, $"Tag '{tag}' is not greater compared to last tag '{secondSection?.Caption}'."); content.Insert(firstSection.StartIndex + 1, string.Empty); content.Insert(firstSection.StartIndex + 2, $"## [{tag}] / {DateTime.Now:yyyy-MM-dd}"); UpdateVersionSummary(tag, content, repository); content.Add(string.Empty); TextTasks.WriteAllLines(changelogFile, content); }
public virtual FileInfo[] GetAllReleaseNugetPackages() { return(PathConstruction.GlobFiles(RootDirectory, $"**/Anabasis.*.{BuildVersion}.nupkg") .OrderBy(path => $"{path}") .Select(path => new FileInfo($"{path}")) .ToArray()); }
public void GenerateSpecifications() { Console.WriteLine($"Generating {ToolName} specifications..."); var tool = GenerateTool(PathConstruction.Combine(_outputFolder, $"{ToolName}.json")); using (var parser = CreateSpecificationParser()) { parser.Populate(tool); } PopulateReferences(tool); if (_overwriteFilePath != null) { SpecificationModifier.OverwriteFromFile(tool, _overwriteFilePath); } Directory.CreateDirectory(_outputFolder); ToolSerializer.Save(tool, tool.SpecificationFile); Console.WriteLine(); Console.WriteLine("Generation finished."); Console.WriteLine($"Created Tasks: {tool.Tasks.Count}"); Console.WriteLine($"Created Data Classes: {tool.DataClasses.Count}"); Console.WriteLine($"Created Enumerations: {tool.Enumerations.Count}"); Console.WriteLine($"Created Common Task Properties: {tool.CommonTaskProperties.Count}"); Console.WriteLine($"Created Common Task Property Sets: {tool.CommonTaskPropertySets.Count}"); }
/// <summary> /// Finalizes the changelog by moving all entries from `[vNext]` to the version specified by release. /// <p>If <paramref name="repository"/> is specified a summary with all versions and links to list the changes directly on GitHub is appended to the end of the changelog.</p> /// </summary> /// <param name="changelogFile">The path to the changelog file.</param> /// <param name="tag">The <see cref="NuGetVersion"/> to finalize the changelog.</param> /// <param name="repository">The repository to create the version overview for.</param> /// <seealso cref="FinalizeChangelog(ChangeLog,NuGetVersion,GitRepository)"/> public static void FinalizeChangelog(ChangeLog changelogFile, NuGetVersion tag, [CanBeNull] GitRepository repository = null) { Logger.Info($"Finalizing {PathConstruction.GetRelativePath(NukeBuild.RootDirectory, changelogFile.Path)} for '{tag}'..."); var unreleasedNotes = changelogFile.Unreleased; var releaseNotes = changelogFile.ReleaseNotes; var lastReleased = changelogFile.LatestVersion; ControlFlow.Assert(unreleasedNotes != null, "Changelog should have draft section."); ControlFlow.Assert(releaseNotes.Any(x => x.Version != null && x.Version.Equals(tag)), $"Tag '{tag}' already exists."); ControlFlow.Assert(lastReleased != null && tag.CompareTo(lastReleased.Version) > 0, $"Tag '{tag}' is not greater compared to last tag '{lastReleased.NotNull().Version}'."); var path = changelogFile.Path; var content = TextTasks.ReadAllLines(path).ToList(); content.Insert(unreleasedNotes.StartIndex + 1, string.Empty); content.Insert(unreleasedNotes.EndIndex + 2, $"## [{tag}] / {DateTime.Now:yyyy-MM-dd}"); UpdateVersionSummary(tag.ToString(), content, repository); content.Add(string.Empty); TextTasks.WriteAllLines(path, content); }
public static Tool GetLocalTool(string absoluteOrRelativePath) { var toolPath = PathConstruction.HasPathRoot(absoluteOrRelativePath) ? absoluteOrRelativePath : Path.Combine(NukeBuild.RootDirectory, absoluteOrRelativePath); Assert.FileExists(toolPath); return(new ToolExecutor(toolPath).Execute); }
private static string GetRepositoryRelativePath([CanBeNull] string path, GitRepository repository) { if (path == null) return null; if (!Path.IsPathRooted(path)) return path; ControlFlow.Assert(PathConstruction.IsDescendantPath(repository.LocalDirectory.NotNull("repository.LocalDirectory != null"), path), $"PathConstruction.IsDescendantPath({repository.LocalDirectory}, {path})"); return PathConstruction.GetRelativePath(repository.LocalDirectory, path).Replace(oldChar: '\\', newChar: '/'); }
private static AssemblyDefinition[] LoadAssemblies(string packageDirectory) { var assemblyDirectory = PathConstruction.Combine(packageDirectory, "tools"); var assemblyResolver = new DefaultAssemblyResolver(); assemblyResolver.AddSearchDirectory(assemblyDirectory); return(PathConstruction.GlobFiles(assemblyDirectory, "docfx.exe") .Select(x => AssemblyDefinition.ReadAssembly(x, new ReaderParameters { AssemblyResolver = assemblyResolver })) .ToArray()); }
public virtual FileInfo[] GetAllTestsProjects() { var testProjects = PathConstruction.GlobFiles(RootDirectory, "**/Anabasis.*.Tests*.csproj").OrderBy(path => $"{path}") .Select(path => new FileInfo($"{path}")) .ToArray(); if (SkipIntegrationTests) { testProjects = testProjects.Where(testProject => !testProject.Name.ToLower().Contains("integration")).ToArray(); } return(testProjects); }
public void AddSolution(Solution solution, SolutionFolder folder = null) { SolutionFolder GetParentFolder(PrimitiveProject solutionFolder) => AllSolutionFolders.FirstOrDefault(x => x.ProjectId == solutionFolder.SolutionFolder?.ProjectId); IDictionary <string, string> GetItems(SolutionFolder solutionFolder) => solutionFolder.Items.Keys .Select(x => (string)PathConstruction.GetWinRelativePath(Directory, solution.Directory / x)) .ToDictionary(x => x, x => x); solution.AllSolutionFolders.ForEach(x => AddSolutionFolder(x.Name, x.ProjectId, GetParentFolder(x) ?? folder)); solution.AllSolutionFolders.ForEach(x => GetSolutionFolder(x.ProjectId).Items = GetItems(x)); solution.AllProjects.ForEach(x => AddProject(x.Name, x.TypeId, x.Path, x.ProjectId, x.Configurations, GetParentFolder(x) ?? folder)); }
private static string GetMethod([CanBeNull] string relativePath, GitHubItemType itemType, GitRepository repository) { var absolutePath = repository.LocalDirectory != null && relativePath != null ? PathConstruction.NormalizePath(Path.Combine(repository.LocalDirectory, relativePath)) : null; if (itemType == GitHubItemType.Directory || Directory.Exists(absolutePath) || relativePath == null) return "tree"; if (itemType == GitHubItemType.File || File.Exists(absolutePath)) return "blob"; return null; }
private static AssemblyDefinition[] LoadAssemblies(string packageDirectory) { var assemblyDirectories = GetAssemblyDirectories(packageDirectory); var assemblyResolver = new DefaultAssemblyResolver(); assemblyDirectories.ForEach(x => assemblyResolver.AddSearchDirectory(x)); return(assemblyDirectories .SelectMany(x => PathConstruction.GlobFiles(x, "*.dll")) .Select(x => AssemblyDefinition.ReadAssembly(x, new ReaderParameters { AssemblyResolver = assemblyResolver })) .ToArray()); }
// TODO: allow wildcard matching? [Solution("nuke-*.sln")] -- no globbing? // TODO: for just [Solution] without parameter being passed, do wildcard search? private string GetSolutionFile(MemberInfo member) { if (_relativePath != null) { return(PathConstruction.Combine(NukeBuild.RootDirectory, _relativePath)); } var parameterValue = ParameterService.Instance.GetParameter <PathConstruction.AbsolutePath>(member); if (parameterValue != null) { return(parameterValue); } return(GetSolutionFileFromConfigurationFile()); }
private static string GetRepositoryRelativePath([CanBeNull] string path, GitRepository repository) { if (path == null) { return(null); } if (!Path.IsPathRooted(path)) { return(path); } ControlFlow.Assert(PathConstruction.IsDescendantPath(repository.LocalDirectory.NotNull("repository.LocalDirectory != null"), path), $"PathConstruction.IsDescendantPath({repository.LocalDirectory}, {path})"); return(PathConstruction.GetRelativePath(repository.LocalDirectory, path)); }
// TODO: allow wildcard matching? [Solution("nuke-*.sln")] -- no globbing? // TODO: for just [Solution] without parameter being passed, do wildcard search? private string GetSolutionFile(string memberName) { var parameter = ParameterService.Instance.GetParameter <string>(memberName); if (parameter != null) { return(PathConstruction.HasPathRoot(parameter) ? parameter : PathConstruction.Combine(EnvironmentInfo.WorkingDirectory, parameter)); } if (_solutionFileRootRelativePath != null) { return(PathConstruction.Combine(NukeBuild.Instance.RootDirectory, _solutionFileRootRelativePath)); } return(NukeBuild.Instance.SolutionFile); }
public static void GenerateSpecifications(SpecificationGeneratorSettings settings) { Console.WriteLine("Generating docker specifications..."); var definitions = DefinitionFetcher.GetCommandDefinitionsFromFolder(settings.DefinitionFolder, settings.Reference, settings.CommandsToSkip); var tool = DefinitionParser.GenerateTool(definitions); Directory.CreateDirectory(settings.OutputFolder); ToolSerializer.Save(tool, PathConstruction.Combine(settings.OutputFolder, "Docker.json")); Console.WriteLine(); Console.WriteLine("Generation finished."); Console.WriteLine($"Created Tasks: {tool.Tasks.Count}"); Console.WriteLine($"Created Data Classes: {tool.DataClasses.Count}"); Console.WriteLine($"Created Enumerations: {tool.Enumerations.Count}"); Console.WriteLine($"Created Common Task Properties: {tool.CommonTaskProperties.Count}"); Console.WriteLine($"Created Common Task Property Sets: {tool.CommonTaskPropertySets.Count}"); }
private static void CompressTar(string directory, string archiveFile, Predicate <FileInfo> filter, Func <Stream, Stream> outputStreamFactory) { FileSystemTasks.EnsureExistingParentDirectory(archiveFile); var files = GetFiles(directory, filter); using (var fileStream = File.Open(archiveFile, FileMode.CreateNew, FileAccess.ReadWrite)) using (var outputStream = outputStreamFactory(fileStream)) using (var tarArchive = TarArchive.CreateOutputTarArchive(outputStream)) { foreach (var file in files) { var entry = TarEntry.CreateEntryFromFile(file); var relativePath = PathConstruction.GetRelativePath(directory, file); entry.Name = PathConstruction.NormalizePath(relativePath, separator: '/'); tarArchive.WriteEntry(entry, recurse: false); } } Logger.Log($"Compressed content of '{directory}' to '{Path.GetFileName(archiveFile)}'."); }
public static void UncompressZip(string archiveFile, string directory) { using (var fileStream = File.OpenRead(archiveFile)) using (var zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(fileStream)) { var entries = zipFile.Cast <ZipEntry>().Where(x => !x.IsDirectory); foreach (var entry in entries) { var file = PathConstruction.Combine(directory, entry.Name); FileSystemTasks.EnsureExistingParentDirectory(file); using (var entryStream = zipFile.GetInputStream(entry)) using (var outputStream = File.Open(file, FileMode.Create)) { entryStream.CopyTo(outputStream); } } } Logger.Log($"Uncompressed '{archiveFile}' to '{directory}'."); }
public static void CompressZip(string directory, string archiveFile, Predicate <FileInfo> filter, CompressionLevel compressionLevel) { FileSystemTasks.EnsureExistingParentDirectory(archiveFile); var files = GetFiles(directory, filter); using (var fileStream = File.Open(archiveFile, FileMode.CreateNew, FileAccess.ReadWrite)) using (var zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Create)) { // zipStream.SetLevel(1); foreach (var file in files) { var relativePath = PathConstruction.GetRelativePath(directory, file); var entryName = ZipEntry.CleanName(relativePath); zipArchive.CreateEntryFromFile(file, entryName, compressionLevel); } } Logger.Log($"Compressed content of '{directory}' to '{Path.GetFileName(archiveFile)}'."); }
public static void FinalizeChangelog(string changelogFile, string tag, [CanBeNull] GitRepository repository = null) { Logger.Info($"Finalizing {PathConstruction.GetRootRelativePath(changelogFile)} for '{tag}'..."); var content = TextTasks.ReadAllLines(changelogFile).ToList(); var sections = GetReleaseSections(content).ToList(); var firstSection = sections.First(); var secondSection = sections.Skip(1).FirstOrDefault(); ControlFlow.Assert(firstSection.Caption.All(char.IsLetter), "Cannot find a draft section."); ControlFlow.Assert(sections.All(x => !x.Caption.EqualsOrdinalIgnoreCase(tag)), $"Tag '{tag}' already exists."); ControlFlow.Assert(firstSection.EndIndex > firstSection.StartIndex, $"Draft section '{firstSection.Caption}' does not contain any information."); ControlFlow.Assert(secondSection == null || NuGetVersion.Parse(tag).CompareTo(NuGetVersion.Parse(secondSection.Caption)) > 0, $"Tag '{tag}' is not greater compared to last tag '{secondSection?.Caption}'."); content.Insert(firstSection.StartIndex + 1, string.Empty); content.Insert(firstSection.StartIndex + 2, $"## [{tag}] / {DateTime.Now:yyyy-MM-dd}"); if (repository != null && repository.IsGitHubRepository()) { sections = GetReleaseSections(content).ToList(); firstSection = sections.First(); var lastSection = sections.Last(); content.RemoveRange(lastSection.EndIndex + 1, content.Count - lastSection.EndIndex - 1); content.Add(string.Empty); content.Add($"[{firstSection.Caption}]: {repository}/compare/{tag}...HEAD"); for (var i = 1; i + 1 < sections.Count; i++) { content.Add($"[{sections[i].Caption}]: {repository}/compare/{sections[i + 1].Caption}...{sections[i].Caption}"); } content.Add($"[{lastSection.Caption}]: {repository}/tree/{lastSection.Caption}"); } content.Add(string.Empty); TextTasks.WriteAllLines(changelogFile, content); }
private IEnumerable <ITaskItem> GetFiles(string packageId, string packageVersion) { var packageToolsPath = Path.Combine(NuGetPackageRoot, packageId, packageVersion, "tools"); if (!Directory.Exists(packageToolsPath)) { yield break; } foreach (var file in Directory.GetFiles(packageToolsPath, "*", SearchOption.AllDirectories)) { var taskItem = new TaskItem(file); taskItem.SetMetadata("BuildAction", "None"); taskItem.SetMetadata("PackagePath", Path.Combine("tools", TargetFramework, "any", packageId, PathConstruction.GetRelativePath(packageToolsPath, file))); yield return(taskItem); } }
// TODO: allow wildcard matching? [Solution("nuke-*.sln")] -- no globbing? // TODO: for just [Solution] without parameter being passed, do wildcard search? private string GetSolutionFileFromParametersFile(MemberInfo member) { return(_relativePath != null ? PathConstruction.Combine(NukeBuild.RootDirectory, _relativePath) : EnvironmentInfo.GetParameter <AbsolutePath>(member).NotNull($"No solution file defined for '{member.Name}'.")); }
internal MountedPath(string path, AbsolutePath hostPath) { this._path = PathConstruction.NormalizePath(path); HostPath = hostPath; }
public virtual FileInfo[] GetAllProjects() { return(PathConstruction.GlobFiles(RootDirectory, "**/Anabasis.*.csproj").OrderBy(path => $"{path}") .Select(path => new FileInfo($"{path}")) .ToArray()); }