public NuGetPacker(OpenApiDocument document, YardarmGenerationSettings settings, PackageSpec packageSpec, IEnumerable <INuGetPackageEnricher> packageEnrichers) { _document = document ?? throw new ArgumentNullException(nameof(document)); _settings = settings ?? throw new ArgumentNullException(nameof(settings)); _packageSpec = packageSpec ?? throw new ArgumentNullException(nameof(packageSpec)); _packageEnrichers = packageEnrichers.ToArray(); }
public RootNamespace(YardarmGenerationSettings settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } Name = SyntaxFactory.ParseName(settings.RootNamespace); }
private void ApplyStrongNaming(YardarmGenerationSettings settings) { if (string.IsNullOrEmpty(_options.KeyFile)) { return; } settings.CompilationOptions = settings.CompilationOptions .WithStrongNameProvider(new DesktopStrongNameProvider(ImmutableArray.Create(Directory.GetCurrentDirectory()))) .WithCryptoKeyFile(_options.KeyFile); }
private List <Stream> ApplyFileStreams(YardarmGenerationSettings settings) { var streams = new List <Stream>(); try { if (!string.IsNullOrEmpty(_options.OutputFile)) { var dllStream = File.Create(_options.OutputFile); streams.Add(dllStream); settings.DllOutput = dllStream; if (!string.IsNullOrEmpty(_options.OutputXmlFile)) { var xmlStream = File.Create(_options.OutputXmlFile); streams.Add(xmlStream); settings.XmlDocumentationOutput = xmlStream; } if (!string.IsNullOrEmpty(_options.OutputDebugSymbols)) { var pdbStream = File.Create(_options.OutputDebugSymbols); streams.Add(pdbStream); settings.PdbOutput = pdbStream; } } else if (!string.IsNullOrEmpty(_options.OutputPackageFile)) { var nupkgStream = File.Create(_options.OutputPackageFile); streams.Add(nupkgStream); settings.NuGetOutput = nupkgStream; if (!string.IsNullOrEmpty(_options.OutputSymbolsPackageFile)) { var snupkgStream = File.Create(_options.OutputSymbolsPackageFile); streams.Add(snupkgStream); settings.NuGetSymbolsOutput = snupkgStream; } } return(streams); } catch { // Don't leave dangling streams on exception foreach (var stream in streams) { stream.Dispose(); } throw; } }
public async Task <int> ExecuteAsync() { var stopwatch = new Stopwatch(); stopwatch.Start(); var document = await ReadDocumentAsync(); var generator = new YardarmGenerator(); var settings = new YardarmGenerationSettings(_options.AssemblyName); ApplyVersion(settings); ApplyExtensions(settings); ApplyStrongNaming(settings); ApplyNuGetSettings(settings); List <Stream> streams = ApplyFileStreams(settings); try { settings .AddLogging(builder => { builder .SetMinimumLevel(LogLevel.Information) .AddSerilog(); }); YardarmGenerationResult generationResult = await generator.EmitAsync(document, settings); foreach (Diagnostic diagnostic in generationResult.GetAllDiagnostics() .Where(p => p.Severity >= DiagnosticSeverity.Info)) { Log.Logger.Write( diagnostic.Severity switch { DiagnosticSeverity.Error => LogEventLevel.Error, DiagnosticSeverity.Warning => LogEventLevel.Warning, _ => LogEventLevel.Information }, diagnostic.GetMessageWithSource( generationResult.Context.GenerationServices.GetRequiredService <IOpenApiElementRegistry>()) ); }
public async Task <int> ExecuteAsync() { var document = await ReadDocumentAsync(); var generator = new YardarmGenerator(); var settings = new YardarmGenerationSettings(_options.AssemblyName); ApplyVersion(settings); ApplyExtensions(settings); ApplyStrongNaming(settings); List <Stream> streams = ApplyFileStreams(settings); try { settings .AddLogging(builder => { builder .SetMinimumLevel(LogLevel.Information) .AddConsole(); }); EmitResult compilationResult = await generator.EmitAsync(document, settings); await using var stdError = new StreamWriter(Console.OpenStandardError(), new UTF8Encoding(false)); foreach (Diagnostic diagnostic in compilationResult.Diagnostics.Where(p => p.Severity == DiagnosticSeverity.Error)) { stdError.WriteLine(diagnostic); } return(compilationResult.Success ? 0 : 1); } finally { foreach (var stream in streams) { await stream.DisposeAsync(); } } }
private void ApplyVersion(YardarmGenerationSettings settings) { int dashIndex = _options.Version.IndexOf('-'); string versionStr = dashIndex >= 0 ? _options.Version.Substring(0, dashIndex) : _options.Version; settings.VersionSuffix = dashIndex >= 0 ? _options.Version.Substring(dashIndex) : ""; if (!Version.TryParse(versionStr, out Version version)) { Environment.ExitCode = 1; throw new InvalidOperationException($"Invalid version {_options.Version}"); } settings.Version = version; }
private void ApplyExtensions(YardarmGenerationSettings settings) { foreach (string extensionFile in _options.ExtensionFiles) { try { string fullPath = !Path.IsPathFullyQualified(extensionFile) ? Path.Combine(Directory.GetCurrentDirectory(), extensionFile) : extensionFile; Assembly assembly = Assembly.LoadFile(fullPath); settings.AddExtension(assembly); } catch (Exception ex) { throw new Exception($"Error loading extension '{extensionFile}'.", ex); } } }
public VersionAssemblyInfoEnricher(YardarmGenerationSettings settings) { _settings = settings ?? throw new ArgumentNullException(nameof(settings)); }
public DefaultPackageSpecGenerator(YardarmGenerationSettings settings, IEnumerable <IPackageSpecEnricher> enrichers) { _settings = settings ?? throw new ArgumentNullException(nameof(settings)); Enrichers = enrichers.ToArray(); }