Пример #1
0
        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();
        }
Пример #2
0
        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();
        }
Пример #3
0
        private static void RunMain(string[] args)
        {
            if (args.Length < 3 || args.Length > 4)
            {
                WriteErrorAndSetErrorCode("Wrong number of arguments." + Environment.NewLine + Environment.NewLine + "Sample:" + Environment.NewLine + "justassembly.commandlinetool Path\\To\\Assembly1 Path\\To\\Assembly2 Path\\To\\XMLOutput [Path\\To\\IgnoreXML]");
                return;
            }

            var oldAssemblyPath = args[0];

            if (!FilePathValidater.ValidateInputFile(oldAssemblyPath))
            {
                WriteErrorAndSetErrorCode("First assembly path is in incorrect format or file not found.");
                return;
            }

            var newAssemblyPath = args[1];

            if (!FilePathValidater.ValidateInputFile(newAssemblyPath))
            {
                WriteErrorAndSetErrorCode("Second assembly path is in incorrect format or file not found.");
                return;
            }

            var outputPath = args[2];

            if (!FilePathValidater.ValidateOutputFile(outputPath))
            {
                WriteErrorAndSetErrorCode("Output file path is in incorrect format.");
                return;
            }

            var ignoreFile = args.Length > 3 ? args[3] : null;
            IgnoredChangesSet ignoreChangeSet = new IgnoredChangesSet(new ChangeSet(new Change[0]));

            if (ignoreFile != null)
            {
                if (!FilePathValidater.ValidateOutputFile(ignoreFile))
                {
                    WriteErrorAndSetErrorCode("Ignore file path is in incorrect format.");
                    return;
                }

                try
                {
                    using (var textReader = File.OpenText(ignoreFile))
                    {
                        var xmlReader    = new XmlSerializer(typeof(ChangeSet));
                        var rawChangeSet = (ChangeSet)xmlReader.Deserialize(textReader);
                        ignoreChangeSet = new IgnoredChangesSet(rawChangeSet);
                    }
                }
                catch (Exception ex)
                {
                    WriteExceptionAndSetErrorCode("A problem occurred while parsing the ignore file.", ex);
                    return;
                }
            }

            var differ = new Differ(ignoreChangeSet, new EmptyFileGenerationNotifier());

            ChangeSet changeSet;

            try
            {
                var typesMap     = new OldToNewTupleMap <string> (oldAssemblyPath, newAssemblyPath);
                var assemblyNode = differ.CreateAssemblyNode(typesMap);
                changeSet = differ.CreateChangeSet(assemblyNode);
            }
            catch (Exception ex)
            {
                WriteExceptionAndSetErrorCode("A problem occurred while creating the change set.", ex);
                return;
            }

            try
            {
                differ.CreatePatchFileAndSources(
                    changeSet,
                    Path.ChangeExtension(outputPath, ".patch"),
                    Path.ChangeExtension(outputPath, ".zip"));
            }
            catch (Exception ex)
            {
                WriteExceptionAndSetErrorCode("There was a problem while writing the patch file.", ex);
                return;
            }

            string xml = string.Empty;

            try
            {
                foreach (var change in changeSet.MemberChanges)
                {
                    if (change is ResourceChange)
                    {
                        if (change.OldSource != null)
                        {
                            change.OldSource.Text = null;
                        }
                        if (change.NewSource != null)
                        {
                            change.NewSource.Text = null;
                        }
                    }
                }
                xml = differ.CreateXMLDiff(changeSet);
            }
            catch (Exception ex)
            {
                WriteExceptionAndSetErrorCode("A problem occurred while creating the API diff.", ex);
                return;
            }

            try
            {
                using (StreamWriter writer = new StreamWriter(outputPath))
                {
                    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();
        }