public AssemblyBrowseTabItem(IOldToNewTupleMap <string> comparableModel) { APIDiffInfo diffInfo = new APIDiffInfo(APIDiffHelper.GetAPIDifferences(comparableModel.OldType, comparableModel.NewType)); var generationProjectInfoMap = new OldToNewTupleMap <GeneratedProjectOutputInfo> ( new GeneratedProjectOutputInfo(comparableModel.OldType), new GeneratedProjectOutputInfo(comparableModel.NewType) ); FilterSettings filterSettings = new FilterSettings(this.ShowAllUnmodified); this.nodes = new AssemblyNode[] { new AssemblyNode(comparableModel, null, null, this, filterSettings) { GenerationProjectInfoMap = generationProjectInfoMap } }; this.header = GetTabTitle(comparableModel); this.toolTip = GetTabToolTip(comparableModel); this.nodes[0].ChildrenLoaded += OnAssemblyNodeChildrenLoaded; this.contentLoaded = new bool[2]; }
static void Main(string[] args) { if (args.Length != 3) { WriteErrorAndSetErrorCode("Exactly 3 arguments are needed - 2 file paths for input files and 1 file path for output xml file."); return; } if (!FilePathValidater.ValidateInputFile(args[0])) { WriteErrorAndSetErrorCode("First file path is in incorrect format or file not found."); return; } if (!FilePathValidater.ValidateInputFile(args[1])) { WriteErrorAndSetErrorCode("Second file path is in incorrect format or file not found."); return; } if (!FilePathValidater.ValidateOutputFile(args[2])) { WriteErrorAndSetErrorCode("Output file path is in incorrect format."); return; } string xml = string.Empty; try { IDiffItem diffItem = APIDiffHelper.GetAPIDifferences(args[0], args[1]); if (diffItem != null) { xml = diffItem.ToXml(); } } catch (Exception ex) { WriteExceptionAndSetErrorCode("There was a problem during calculation of API differences.", ex); return; } try { using (StreamWriter writer = new StreamWriter(args[2])) { writer.Write(xml); } } catch (Exception ex) { WriteExceptionAndSetErrorCode("There was a problem while writing output file.", ex); return; } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("API differences calculated successfully."); Console.ResetColor(); }
private static void RunMain(string[] args) { if (args.Length != 3) { WriteErrorAndSetErrorCode("Wrong number of arguments." + Environment.NewLine + Environment.NewLine + "Sample:" + Environment.NewLine + "justassembly.commandlinetool Path\\To\\Assembly1 Path\\To\\Assembly2 Path\\To\\XMLOutput"); return; } if (!FilePathValidater.ValidateInputFile(args[0])) { WriteErrorAndSetErrorCode("First assembly path is in incorrect format or file not found."); return; } if (!FilePathValidater.ValidateInputFile(args[1])) { WriteErrorAndSetErrorCode("Second assembly path is in incorrect format or file not found."); return; } if (!FilePathValidater.ValidateOutputFile(args[2])) { WriteErrorAndSetErrorCode("Output file path is in incorrect format."); return; } string xml = string.Empty; try { IDiffItem diffItem = APIDiffHelper.GetAPIDifferences(args[0], args[1]); if (diffItem != null) { xml = diffItem.ToXml(); } } catch (Exception ex) { WriteExceptionAndSetErrorCode("A problem occurred while creating the API diff.", ex); return; } try { using (StreamWriter writer = new StreamWriter(args[2])) { writer.Write(xml); } } catch (Exception ex) { WriteExceptionAndSetErrorCode("There was a problem while writing output file.", ex); return; } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("API differences calculated successfully."); Console.ResetColor(); }
private AssemblyNode ProcessAssemblyNodeCreation(IOldToNewTupleMap <string> typesMap) { APIDiffInfo diffInfo = this.apiDiffInfo != null ? new APIDiffInfo(APIDiffHelper.GetAPIDifferences(typesMap.OldType, typesMap.NewType)) : null; var generationProjectInfoMap = new OldToNewTupleMap <GeneratedProjectOutputInfo> ( new GeneratedProjectOutputInfo(typesMap.OldType), new GeneratedProjectOutputInfo(typesMap.NewType) ); var assemblyNode = new AssemblyNode(typesMap, this, diffInfo, progressNotifier, this.FilterSettings) { GenerationProjectInfoMap = generationProjectInfoMap }; assemblyNode.SetDifferenceDecoration(); return(assemblyNode); }
static void Main(string[] args) { var providers = new AssemblyProviderFactoryCollection( new AssemblyProviderFactory(), new DirectoryAssemblyProviderFactory(), new NuGetAssemblyProviderFactory(new Providers.NuGet.NuGet( Environment.GetEnvironmentVariable("NUGET"), Environment.GetEnvironmentVariable("NUGET_SOURCES"))), new GitHubAssemblyProviderFactory(new Git(Environment.GetEnvironmentVariable("GIT"))) ); var exporters = new ExporterCollection( new XmlExporter(), new MarkdownExporter(), new AsciiDocExporter() ); var options = new OptionSet { { "t|target=", "the assembly targets. Defaults to *all* assemblies located by the provider", AddTarget }, { "f|format=", $"the format of the diff output. Supported formats are {exporters.SupportedFormats}. Defaults to {_format}", f => _format = f }, { "o|output=", "the output directory. Defaults to current directory", o => _output = o }, { "h|?|help", "show this message and exit", h => _help = h != null }, }; if (args.Length < 2) { ShowHelp(options, providers); Environment.ExitCode = 1; return; } List <string> unflaggedArgs; try { unflaggedArgs = options.Parse(args); } catch (OptionException e) { Console.WriteLine(e.Message); Console.WriteLine("Try 'Differ.exe --help' for more information."); Environment.ExitCode = 1; return; } if (_help) { ShowHelp(options, providers); return; } try { var firstProvider = providers.GetProvider(unflaggedArgs[0]); var secondProvider = providers.GetProvider(unflaggedArgs[1]); if (!exporters.Contains(_format)) { throw new Exception($"No exporter for format '{_format}'"); } var exporter = exporters[_format]; foreach (var assemblyPair in CreateAssemblyPairs(firstProvider, secondProvider)) { assemblyPair.Diff = APIDiffHelper.GetAPIDifferences(assemblyPair.First.FullName, assemblyPair.Second.FullName); if (assemblyPair.Diff == null) { Console.WriteLine($"No diff between {assemblyPair.First.FullName} and {assemblyPair.Second.FullName}"); continue; } exporter.Export(assemblyPair, _output); } } catch (Exception e) { Console.WriteLine(e); Environment.ExitCode = 1; } }
private string GetAPIDiffResult(string oldFile, string newFile) { IDiffItem diffItem = APIDiffHelper.GetAPIDifferences(oldFile, newFile); return(diffItem == null ? string.Empty : diffItem.ToXml()); }
private static int Main(string[] args) { var providers = new AssemblyProviderFactoryCollection( new AssemblyProviderFactory(), new DirectoryAssemblyProviderFactory(), new NuGetAssemblyProviderFactory(new Providers.NuGet.NuGet()), new PreviousNuGetAssemblyProviderFactory(new PreviousNugetLocator()), new GitHubAssemblyProviderFactory(new Git(Environment.GetEnvironmentVariable("GIT"))) ); var exporters = new ExporterCollection( new XmlExporter(), new MarkdownExporter(), new AsciiDocExporter(), new GitHubActionCommentExporter() ); var options = new OptionSet { { "t|target=", "the assembly targets. Defaults to *all* assemblies located by the provider", AddTarget }, { "f|format=", $"the format of the diff output. Supported formats are {exporters.SupportedFormats}. Defaults to {_format}", f => _format = f }, { "o|output=", "the output directory or file name. If not specified only prints to console", o => _output = new OutputWriterFactory(o) }, { "p|prevent-change=", "Fail if the change detected is higher then specified: none|patch|minor|major. Defaults to `none` which will never fail.", c => _preventChange = Enum.Parse <SuggestedVersionChange>(c, true) }, { "a|allow-empty-previous-nuget=", "", n => _allowEmptyPreviousNuget = n != null }, { "h|?|help", "show this message and exit", h => _help = h != null }, }; if (_help) { ShowHelp(options, providers); return(2); } if (args.Length < 2) { ShowHelp(options, providers); return(2); } List <string> unflaggedArgs; try { unflaggedArgs = options.Parse(args); } catch (OptionException e) { Console.WriteLine(e.Message); Console.WriteLine("Try 'Differ.exe --help' for more information."); Environment.ExitCode = 1; return(2); } try { var firstProvider = providers.GetProvider(unflaggedArgs[0]); var secondProvider = providers.GetProvider(unflaggedArgs[1]); var firstProviderName = providers.GetProviderName(unflaggedArgs[0]); var secondProviderName = providers.GetProviderName(unflaggedArgs[1]); if (!exporters.Contains(_format)) { throw new Exception($"No exporter for format '{_format}'"); } var exporter = exporters[_format]; var first = firstProvider.GetAssemblies(Targets).ToList(); var second = secondProvider.GetAssemblies(Targets).ToList(); var pairs = CreateAssemblyPairs(first, second).ToList(); if (!pairs.Any()) { if (_allowEmptyPreviousNuget && (firstProviderName == "previous-nuget" || secondProviderName == "previous-nuget")) { Console.WriteLine($"[diff] No previous nuget found for: {firstProviderName}"); Console.WriteLine($"[diff] {firstProvider.GetType().Name}: {first.Count()} assemblies"); Console.WriteLine($"[diff] {secondProvider.GetType().Name}: {second.Count()} assemblies"); Console.WriteLine($"[diff]"); Console.WriteLine($"[diff] NOT treated as an error because --allow-empty-previous-nuget was set"); return(0); } Console.Error.WriteLine($"[diff] Unable to create diff!"); Console.Error.WriteLine($"[diff] {firstProvider.GetType().Name}: {first.Count()} assemblies"); Console.Error.WriteLine($"[diff] {secondProvider.GetType().Name}: {second.Count()} assemblies"); return(1); } var result = new AllComparisonResults(pairs, _preventChange); foreach (var assemblyPair in pairs) { assemblyPair.Diff = APIDiffHelper.GetAPIDifferences(assemblyPair.First.FullName, assemblyPair.Second.FullName); if (assemblyPair.Diff == null) { Console.WriteLine($"[diff] No diff between {assemblyPair.First.FullName} and {assemblyPair.Second.FullName}"); continue; } Console.WriteLine($"[diff] Difference found: {firstProvider.GetType().Name}:{assemblyPair.First.Name} and {secondProvider.GetType().Name}:{assemblyPair.Second.Name}"); if (exporter is IAssemblyComparisonExporter c) { c.Export(assemblyPair, _output); } } if (exporter is IAllComparisonResultsExporter allExporter) { allExporter.Export(result, _output); } if (_preventChange > SuggestedVersionChange.None && result.SuggestedVersionChange >= _preventChange) { Console.Error.WriteLine($"[diff] Needed version change '{result.SuggestedVersionChange}' exceeds or equals configured lock: '{_preventChange}"); return(4); } Console.WriteLine($"[diff] Suggested version change: {result.SuggestedVersionChange}"); } catch (Exception e) { Console.Error.WriteLine(e); return(1); } return(0); }