From 0ec925dbf8359629e6d4f71fb142118a05f07298 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sun, 7 Jun 2020 08:14:46 -0700 Subject: Move WixCop to "wix.exe convert" command --- .../ConsoleMessageListener.cs | 96 -------- .../TestData/PermissionEx/v3.wxs | 27 --- .../TestData/PermissionEx/v4_expected.wxs | 27 --- .../Preprocessor/ConvertedPreprocessor.wxs | 62 ------ .../TestData/Preprocessor/Preprocessor.wxs | 63 ------ .../TestData/Preprocessor/wixcop.settings.xml | 9 - .../TestData/QtExec.bad/v3.wxs | 65 ------ .../TestData/QtExec.bad/v4_expected.wxs | 64 ------ .../WixToolsetTest.WixCop/TestData/QtExec/v3.wxs | 64 ------ .../TestData/QtExec/v4_expected.wxs | 63 ------ .../TestData/SingleFile/ConvertedSingleFile.wxs | 60 ----- .../TestData/SingleFile/SingleFile.wxs | 61 ------ src/test/WixToolsetTest.WixCop/WixCopFixture.cs | 242 --------------------- src/test/WixToolsetTest.WixCop/WixCopRunner.cs | 68 ------ .../WixToolsetTest.WixCop/WixCopRunnerResult.cs | 22 -- .../WixToolsetTest.WixCop.csproj | 51 ----- .../WixToolsetTest.WixCop.v3.ncrunchproject | 6 - src/wix/ConsoleMessageListener.cs | 96 ++++++++ src/wix/Program.cs | 4 +- src/wix/app.config | 10 +- src/wix/wix.csproj | 5 +- src/wix/wix.exe.manifest | 4 +- src/wixcop/CommandLine/ConvertCommand.cs | 224 ------------------- src/wixcop/CommandLine/HelpCommand.cs | 37 ---- src/wixcop/CommandLine/WixCopCommandLineParser.cs | 135 ------------ src/wixcop/Interfaces/IWixCopCommandLineParser.cs | 13 -- src/wixcop/Program.cs | 79 ------- src/wixcop/WixCop.csproj | 35 --- src/wixcop/WixCop.net461.v3.ncrunchproject | 5 - src/wixcop/WixCop.netcoreapp2.1.v3.ncrunchproject | 5 - src/wixcop/app.config | 10 - src/wixcop/wixcop.exe.manifest | 20 -- 32 files changed, 105 insertions(+), 1627 deletions(-) delete mode 100644 src/WixToolset.Tools.Core/ConsoleMessageListener.cs delete mode 100644 src/test/WixToolsetTest.WixCop/TestData/PermissionEx/v3.wxs delete mode 100644 src/test/WixToolsetTest.WixCop/TestData/PermissionEx/v4_expected.wxs delete mode 100644 src/test/WixToolsetTest.WixCop/TestData/Preprocessor/ConvertedPreprocessor.wxs delete mode 100644 src/test/WixToolsetTest.WixCop/TestData/Preprocessor/Preprocessor.wxs delete mode 100644 src/test/WixToolsetTest.WixCop/TestData/Preprocessor/wixcop.settings.xml delete mode 100644 src/test/WixToolsetTest.WixCop/TestData/QtExec.bad/v3.wxs delete mode 100644 src/test/WixToolsetTest.WixCop/TestData/QtExec.bad/v4_expected.wxs delete mode 100644 src/test/WixToolsetTest.WixCop/TestData/QtExec/v3.wxs delete mode 100644 src/test/WixToolsetTest.WixCop/TestData/QtExec/v4_expected.wxs delete mode 100644 src/test/WixToolsetTest.WixCop/TestData/SingleFile/ConvertedSingleFile.wxs delete mode 100644 src/test/WixToolsetTest.WixCop/TestData/SingleFile/SingleFile.wxs delete mode 100644 src/test/WixToolsetTest.WixCop/WixCopFixture.cs delete mode 100644 src/test/WixToolsetTest.WixCop/WixCopRunner.cs delete mode 100644 src/test/WixToolsetTest.WixCop/WixCopRunnerResult.cs delete mode 100644 src/test/WixToolsetTest.WixCop/WixToolsetTest.WixCop.csproj delete mode 100644 src/test/WixToolsetTest.WixCop/WixToolsetTest.WixCop.v3.ncrunchproject create mode 100644 src/wix/ConsoleMessageListener.cs delete mode 100644 src/wixcop/CommandLine/ConvertCommand.cs delete mode 100644 src/wixcop/CommandLine/HelpCommand.cs delete mode 100644 src/wixcop/CommandLine/WixCopCommandLineParser.cs delete mode 100644 src/wixcop/Interfaces/IWixCopCommandLineParser.cs delete mode 100644 src/wixcop/Program.cs delete mode 100644 src/wixcop/WixCop.csproj delete mode 100644 src/wixcop/WixCop.net461.v3.ncrunchproject delete mode 100644 src/wixcop/WixCop.netcoreapp2.1.v3.ncrunchproject delete mode 100644 src/wixcop/app.config delete mode 100644 src/wixcop/wixcop.exe.manifest (limited to 'src') diff --git a/src/WixToolset.Tools.Core/ConsoleMessageListener.cs b/src/WixToolset.Tools.Core/ConsoleMessageListener.cs deleted file mode 100644 index 709fb576..00000000 --- a/src/WixToolset.Tools.Core/ConsoleMessageListener.cs +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. - -namespace WixToolset.Tools.Core -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Globalization; - using System.Text; - using System.Threading; - using WixToolset.Data; - using WixToolset.Extensibility; - using WixToolset.Extensibility.Services; - - public sealed class ConsoleMessageListener : IMessageListener - { - public ConsoleMessageListener(string prefix, string appName) - { - this.Prefix = prefix; - this.AppName = appName; - - PrepareConsoleForLocalization(); - } - - public string AppName { get; } - - public string Prefix { get; } - - public void Write(Message message) - { - var filename = message.SourceLineNumbers?.FileName ?? this.AppName; - var type = message.Level.ToString().ToLowerInvariant(); - var output = message.Level >= MessageLevel.Warning ? Console.Out : Console.Error; - - if (message.SourceLineNumbers?.LineNumber.HasValue == true) - { - filename = String.Concat(filename, "(", message.SourceLineNumbers?.LineNumber.Value, ")"); - } - - output.WriteLine("{0} : {1} {2}{3:0000}: {4}", filename, type, this.Prefix, message.Id, message.ToString()); - - var fileNames = GetFileNames(message.SourceLineNumbers); - if (fileNames.Any()) - { - output.WriteLine("Source trace:"); - - foreach (var fileName in fileNames) - { - output.WriteLine("Source trace: {0}", fileName); - } - } - } - - public void Write(string message) - { - Console.Out.WriteLine(message); - } - - public MessageLevel CalculateMessageLevel(IMessaging messaging, Message message, MessageLevel defaultMessageLevel) => defaultMessageLevel; - - private static IList GetFileNames(SourceLineNumber sourceLineNumbers) - { - var fileNames = new List(); - - for (var sln = sourceLineNumbers; null != sln; sln = sln.Parent) - { - if (String.IsNullOrEmpty(sln.FileName)) - { - continue; - } - else if (sln.LineNumber.HasValue) - { - fileNames.Add(String.Format(CultureInfo.CurrentUICulture, "{0}: line {1}", sln.FileName, sln.LineNumber)); - } - else - { - fileNames.Add(sln.FileName); - } - } - - return fileNames; - } - - private static void PrepareConsoleForLocalization() - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentUICulture.GetConsoleFallbackUICulture(); - - if (Console.OutputEncoding.CodePage != Encoding.UTF8.CodePage && - Console.OutputEncoding.CodePage != Thread.CurrentThread.CurrentUICulture.TextInfo.OEMCodePage && - Console.OutputEncoding.CodePage != Thread.CurrentThread.CurrentUICulture.TextInfo.ANSICodePage) - { - Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); - } - } - } -} diff --git a/src/test/WixToolsetTest.WixCop/TestData/PermissionEx/v3.wxs b/src/test/WixToolsetTest.WixCop/TestData/PermissionEx/v3.wxs deleted file mode 100644 index 0e241544..00000000 --- a/src/test/WixToolsetTest.WixCop/TestData/PermissionEx/v3.wxs +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/WixToolsetTest.WixCop/TestData/PermissionEx/v4_expected.wxs b/src/test/WixToolsetTest.WixCop/TestData/PermissionEx/v4_expected.wxs deleted file mode 100644 index 375b70d3..00000000 --- a/src/test/WixToolsetTest.WixCop/TestData/PermissionEx/v4_expected.wxs +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/ConvertedPreprocessor.wxs b/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/ConvertedPreprocessor.wxs deleted file mode 100644 index dcd43e35..00000000 --- a/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/ConvertedPreprocessor.wxs +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/Preprocessor.wxs b/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/Preprocessor.wxs deleted file mode 100644 index 2eb908c2..00000000 --- a/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/Preprocessor.wxs +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/wixcop.settings.xml b/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/wixcop.settings.xml deleted file mode 100644 index 9d3ad496..00000000 --- a/src/test/WixToolsetTest.WixCop/TestData/Preprocessor/wixcop.settings.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/src/test/WixToolsetTest.WixCop/TestData/QtExec.bad/v3.wxs b/src/test/WixToolsetTest.WixCop/TestData/QtExec.bad/v3.wxs deleted file mode 100644 index b0630f65..00000000 --- a/src/test/WixToolsetTest.WixCop/TestData/QtExec.bad/v3.wxs +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/WixToolsetTest.WixCop/TestData/QtExec.bad/v4_expected.wxs b/src/test/WixToolsetTest.WixCop/TestData/QtExec.bad/v4_expected.wxs deleted file mode 100644 index b28c94e4..00000000 --- a/src/test/WixToolsetTest.WixCop/TestData/QtExec.bad/v4_expected.wxs +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/WixToolsetTest.WixCop/TestData/QtExec/v3.wxs b/src/test/WixToolsetTest.WixCop/TestData/QtExec/v3.wxs deleted file mode 100644 index 8d81a758..00000000 --- a/src/test/WixToolsetTest.WixCop/TestData/QtExec/v3.wxs +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/WixToolsetTest.WixCop/TestData/QtExec/v4_expected.wxs b/src/test/WixToolsetTest.WixCop/TestData/QtExec/v4_expected.wxs deleted file mode 100644 index 99cc2151..00000000 --- a/src/test/WixToolsetTest.WixCop/TestData/QtExec/v4_expected.wxs +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/WixToolsetTest.WixCop/TestData/SingleFile/ConvertedSingleFile.wxs b/src/test/WixToolsetTest.WixCop/TestData/SingleFile/ConvertedSingleFile.wxs deleted file mode 100644 index aacb68fa..00000000 --- a/src/test/WixToolsetTest.WixCop/TestData/SingleFile/ConvertedSingleFile.wxs +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/WixToolsetTest.WixCop/TestData/SingleFile/SingleFile.wxs b/src/test/WixToolsetTest.WixCop/TestData/SingleFile/SingleFile.wxs deleted file mode 100644 index 310ae811..00000000 --- a/src/test/WixToolsetTest.WixCop/TestData/SingleFile/SingleFile.wxs +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/WixToolsetTest.WixCop/WixCopFixture.cs b/src/test/WixToolsetTest.WixCop/WixCopFixture.cs deleted file mode 100644 index 72a36dd6..00000000 --- a/src/test/WixToolsetTest.WixCop/WixCopFixture.cs +++ /dev/null @@ -1,242 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. - -namespace WixToolsetTest.WixCop -{ - using System.IO; - using System.Linq; - using WixBuildTools.TestSupport; - using Xunit; - - public class WixCopFixture - { - [Fact] - public void CanConvertPermissionExFile() - { - const string beforeFileName = "v3.wxs"; - const string afterFileName = "v4_expected.wxs"; - var folder = TestData.Get(@"TestData\PermissionEx"); - - using (var fs = new DisposableFileSystem()) - { - var baseFolder = fs.GetFolder(true); - var targetFile = Path.Combine(baseFolder, beforeFileName); - File.Copy(Path.Combine(folder, beforeFileName), Path.Combine(baseFolder, beforeFileName)); - - var runner = new WixCopRunner - { - FixErrors = true, - SearchPatterns = - { - targetFile, - }, - }; - - var result = runner.Execute(); - - Assert.Equal(2, result.ExitCode); - - var expected = File.ReadAllText(Path.Combine(folder, afterFileName)).Replace("\r\n", "\n"); - var actual = File.ReadAllText(targetFile).Replace("\r\n", "\n"); - Assert.Equal(expected, actual); - - var runner2 = new WixCopRunner - { - FixErrors = true, - SearchPatterns = - { - targetFile, - }, - }; - - var result2 = runner2.Execute(); - - Assert.Equal(0, result2.ExitCode); - } - } - - [Fact] - public void CanConvertSingleFile() - { - const string beforeFileName = "SingleFile.wxs"; - const string afterFileName = "ConvertedSingleFile.wxs"; - var folder = TestData.Get(@"TestData\SingleFile"); - - using (var fs = new DisposableFileSystem()) - { - var baseFolder = fs.GetFolder(true); - var targetFile = Path.Combine(baseFolder, beforeFileName); - File.Copy(Path.Combine(folder, beforeFileName), Path.Combine(baseFolder, beforeFileName)); - - var runner = new WixCopRunner - { - FixErrors = true, - SearchPatterns = - { - targetFile, - }, - }; - - var result = runner.Execute(); - - Assert.Equal(2, result.ExitCode); - - var expected = File.ReadAllText(Path.Combine(folder, afterFileName)).Replace("\r\n", "\n"); - var actual = File.ReadAllText(targetFile).Replace("\r\n", "\n"); - Assert.Equal(expected, actual); - - var runner2 = new WixCopRunner - { - FixErrors = true, - SearchPatterns = - { - targetFile, - }, - }; - - var result2 = runner2.Execute(); - - Assert.Equal(0, result2.ExitCode); - } - } - - [Fact] - public void RetainsPreprocessorInstructions() - { - const string beforeFileName = "Preprocessor.wxs"; - const string afterFileName = "ConvertedPreprocessor.wxs"; - var folder = TestData.Get(@"TestData\Preprocessor"); - - using (var fs = new DisposableFileSystem()) - { - var baseFolder = fs.GetFolder(true); - var targetFile = Path.Combine(baseFolder, beforeFileName); - File.Copy(Path.Combine(folder, beforeFileName), Path.Combine(baseFolder, beforeFileName)); - - var runner = new WixCopRunner - { - FixErrors = true, - SettingFile1 = Path.Combine(folder, "wixcop.settings.xml"), - SearchPatterns = - { - targetFile, - }, - }; - - var result = runner.Execute(); - - Assert.Equal(2, result.ExitCode); - - var expected = File.ReadAllText(Path.Combine(folder, afterFileName)).Replace("\r\n", "\n"); - var actual = File.ReadAllText(targetFile).Replace("\r\n", "\n"); - Assert.Equal(expected, actual); - - var runner2 = new WixCopRunner - { - FixErrors = true, - SettingFile1 = Path.Combine(folder, "wixcop.settings.xml"), - SearchPatterns = - { - targetFile, - }, - }; - - var result2 = runner2.Execute(); - - Assert.Equal(0, result2.ExitCode); - } - } - - [Fact] - public void CanConvertQtExec() - { - const string beforeFileName = "v3.wxs"; - const string afterFileName = "v4_expected.wxs"; - var folder = TestData.Get(@"TestData\QtExec"); - - using (var fs = new DisposableFileSystem()) - { - var baseFolder = fs.GetFolder(true); - var targetFile = Path.Combine(baseFolder, beforeFileName); - File.Copy(Path.Combine(folder, beforeFileName), Path.Combine(baseFolder, beforeFileName)); - - var runner = new WixCopRunner - { - FixErrors = true, - SearchPatterns = - { - targetFile, - }, - }; - - var result = runner.Execute(); - - Assert.Equal(2, result.ExitCode); - - var expected = File.ReadAllText(Path.Combine(folder, afterFileName)).Replace("\r\n", "\n"); - var actual = File.ReadAllText(targetFile).Replace("\r\n", "\n"); - Assert.Equal(expected, actual); - - var runner2 = new WixCopRunner - { - FixErrors = true, - SearchPatterns = - { - targetFile, - }, - }; - - var result2 = runner2.Execute(); - - Assert.Equal(0, result2.ExitCode); - } - } - - [Fact] - public void DetectUnconvertableQtExecCmdTimeout() - { - const string beforeFileName = "v3.wxs"; - const string afterFileName = "v4_expected.wxs"; - var folder = TestData.Get(@"TestData\QtExec.bad"); - - using (var fs = new DisposableFileSystem()) - { - var baseFolder = fs.GetFolder(true); - var targetFile = Path.Combine(baseFolder, beforeFileName); - File.Copy(Path.Combine(folder, beforeFileName), Path.Combine(baseFolder, beforeFileName)); - - var runner = new WixCopRunner - { - FixErrors = true, - SearchPatterns = - { - targetFile, - }, - }; - - var result = runner.Execute(); - - Assert.Equal(2, result.ExitCode); - - Assert.Single(result.Messages.Where(message => message.ToString().EndsWith("(QtExecCmdTimeoutAmbiguous)"))); - - var expected = File.ReadAllText(Path.Combine(folder, afterFileName)).Replace("\r\n", "\n"); - var actual = File.ReadAllText(targetFile).Replace("\r\n", "\n"); - Assert.Equal(expected, actual); - - // still fails because QtExecCmdTimeoutAmbiguous is unfixable - var runner2 = new WixCopRunner - { - FixErrors = true, - SearchPatterns = - { - targetFile, - }, - }; - - var result2 = runner2.Execute(); - - Assert.Equal(2, result2.ExitCode); - } - } - } -} diff --git a/src/test/WixToolsetTest.WixCop/WixCopRunner.cs b/src/test/WixToolsetTest.WixCop/WixCopRunner.cs deleted file mode 100644 index d2a0abbe..00000000 --- a/src/test/WixToolsetTest.WixCop/WixCopRunner.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. - -namespace WixToolsetTest.WixCop -{ - using System; - using System.Collections.Generic; - using WixToolset.Core; - using WixToolset.Core.TestPackage; - using WixToolset.Extensibility; - using WixToolset.Extensibility.Services; - using WixToolset.Tools.WixCop; - using WixToolset.Tools.WixCop.CommandLine; - using WixToolset.Tools.WixCop.Interfaces; - - public class WixCopRunner - { - public bool FixErrors { get; set; } - - public List SearchPatterns { get; } = new List(); - - public string SettingFile1 { get; set; } - - public WixCopRunnerResult Execute() - { - var argList = new List(); - - if (this.FixErrors) - { - argList.Add("-f"); - } - - if (!String.IsNullOrEmpty(this.SettingFile1)) - { - argList.Add($"-set1{this.SettingFile1}"); - } - - foreach (var searchPattern in this.SearchPatterns) - { - argList.Add(searchPattern); - } - - return WixCopRunner.Execute(argList.ToArray()); - } - - public static WixCopRunnerResult Execute(string[] args) - { - var listener = new TestMessageListener(); - - var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider(); - serviceProvider.AddService((x, y) => listener); - serviceProvider.AddService((x, y) => new WixCopCommandLineParser(x)); - - var exitCode = Execute(serviceProvider, args); - - return new WixCopRunnerResult - { - ExitCode = exitCode, - Messages = listener.Messages.ToArray() - }; - } - - public static int Execute(IWixToolsetServiceProvider serviceProvider, string[] args) - { - var wixcop = new Program(); - return wixcop.Run(serviceProvider, args); - } - } -} diff --git a/src/test/WixToolsetTest.WixCop/WixCopRunnerResult.cs b/src/test/WixToolsetTest.WixCop/WixCopRunnerResult.cs deleted file mode 100644 index 1b35e491..00000000 --- a/src/test/WixToolsetTest.WixCop/WixCopRunnerResult.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. - -namespace WixToolsetTest.WixCop -{ - using System; - using System.Linq; - using WixToolset.Data; - using Xunit; - - public class WixCopRunnerResult - { - public int ExitCode { get; set; } - - public Message[] Messages { get; set; } - - public WixCopRunnerResult AssertSuccess() - { - Assert.True(0 == this.ExitCode, $"WixCop failed unexpectedly. Output:\r\n{String.Join("\r\n", this.Messages.Select(m => m.ToString()).ToArray())}"); - return this; - } - } -} diff --git a/src/test/WixToolsetTest.WixCop/WixToolsetTest.WixCop.csproj b/src/test/WixToolsetTest.WixCop/WixToolsetTest.WixCop.csproj deleted file mode 100644 index 3ea4dae5..00000000 --- a/src/test/WixToolsetTest.WixCop/WixToolsetTest.WixCop.csproj +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - net461 - false - embedded - win-x86 - - - - NU1603 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/WixToolsetTest.WixCop/WixToolsetTest.WixCop.v3.ncrunchproject b/src/test/WixToolsetTest.WixCop/WixToolsetTest.WixCop.v3.ncrunchproject deleted file mode 100644 index 8f3624cb..00000000 --- a/src/test/WixToolsetTest.WixCop/WixToolsetTest.WixCop.v3.ncrunchproject +++ /dev/null @@ -1,6 +0,0 @@ - - - True - - - \ No newline at end of file diff --git a/src/wix/ConsoleMessageListener.cs b/src/wix/ConsoleMessageListener.cs new file mode 100644 index 00000000..709fb576 --- /dev/null +++ b/src/wix/ConsoleMessageListener.cs @@ -0,0 +1,96 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Tools.Core +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Globalization; + using System.Text; + using System.Threading; + using WixToolset.Data; + using WixToolset.Extensibility; + using WixToolset.Extensibility.Services; + + public sealed class ConsoleMessageListener : IMessageListener + { + public ConsoleMessageListener(string prefix, string appName) + { + this.Prefix = prefix; + this.AppName = appName; + + PrepareConsoleForLocalization(); + } + + public string AppName { get; } + + public string Prefix { get; } + + public void Write(Message message) + { + var filename = message.SourceLineNumbers?.FileName ?? this.AppName; + var type = message.Level.ToString().ToLowerInvariant(); + var output = message.Level >= MessageLevel.Warning ? Console.Out : Console.Error; + + if (message.SourceLineNumbers?.LineNumber.HasValue == true) + { + filename = String.Concat(filename, "(", message.SourceLineNumbers?.LineNumber.Value, ")"); + } + + output.WriteLine("{0} : {1} {2}{3:0000}: {4}", filename, type, this.Prefix, message.Id, message.ToString()); + + var fileNames = GetFileNames(message.SourceLineNumbers); + if (fileNames.Any()) + { + output.WriteLine("Source trace:"); + + foreach (var fileName in fileNames) + { + output.WriteLine("Source trace: {0}", fileName); + } + } + } + + public void Write(string message) + { + Console.Out.WriteLine(message); + } + + public MessageLevel CalculateMessageLevel(IMessaging messaging, Message message, MessageLevel defaultMessageLevel) => defaultMessageLevel; + + private static IList GetFileNames(SourceLineNumber sourceLineNumbers) + { + var fileNames = new List(); + + for (var sln = sourceLineNumbers; null != sln; sln = sln.Parent) + { + if (String.IsNullOrEmpty(sln.FileName)) + { + continue; + } + else if (sln.LineNumber.HasValue) + { + fileNames.Add(String.Format(CultureInfo.CurrentUICulture, "{0}: line {1}", sln.FileName, sln.LineNumber)); + } + else + { + fileNames.Add(sln.FileName); + } + } + + return fileNames; + } + + private static void PrepareConsoleForLocalization() + { + Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentUICulture.GetConsoleFallbackUICulture(); + + if (Console.OutputEncoding.CodePage != Encoding.UTF8.CodePage && + Console.OutputEncoding.CodePage != Thread.CurrentThread.CurrentUICulture.TextInfo.OEMCodePage && + Console.OutputEncoding.CodePage != Thread.CurrentThread.CurrentUICulture.TextInfo.ANSICodePage) + { + Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); + } + } + } +} diff --git a/src/wix/Program.cs b/src/wix/Program.cs index 7e302078..3293ef05 100644 --- a/src/wix/Program.cs +++ b/src/wix/Program.cs @@ -4,6 +4,7 @@ namespace WixToolset.Tools { using System; using System.Runtime.InteropServices; + using WixToolset.Converters; using WixToolset.Core; using WixToolset.Data; using WixToolset.Extensibility; @@ -24,7 +25,8 @@ namespace WixToolset.Tools [MTAThread] public static int Main(string[] args) { - var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider(); + var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider() + .AddConverter(); var listener = new ConsoleMessageListener("WIX", "wix.exe"); diff --git a/src/wix/app.config b/src/wix/app.config index 65d3d6c3..081fea2c 100644 --- a/src/wix/app.config +++ b/src/wix/app.config @@ -1,10 +1,8 @@ - - - - - - + + + + diff --git a/src/wix/wix.csproj b/src/wix/wix.csproj index 117bbcd9..2507de33 100644 --- a/src/wix/wix.csproj +++ b/src/wix/wix.csproj @@ -21,10 +21,7 @@ - - - - + diff --git a/src/wix/wix.exe.manifest b/src/wix/wix.exe.manifest index 49d90508..f35b5534 100644 --- a/src/wix/wix.exe.manifest +++ b/src/wix/wix.exe.manifest @@ -1,10 +1,8 @@ - - - WiX Toolset Compiler + WiX Toolset Compiler diff --git a/src/wixcop/CommandLine/ConvertCommand.cs b/src/wixcop/CommandLine/ConvertCommand.cs deleted file mode 100644 index 0a765771..00000000 --- a/src/wixcop/CommandLine/ConvertCommand.cs +++ /dev/null @@ -1,224 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. - -namespace WixToolset.Tools.WixCop.CommandLine -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Xml; - using WixToolset.Converters; - using WixToolset.Extensibility.Data; - using WixToolset.Extensibility.Services; - - internal class ConvertCommand : ICommandLineCommand - { - private const string SettingsFileDefault = "wixcop.settings.xml"; - - public ConvertCommand(IWixToolsetServiceProvider serviceProvider, bool showLogo, bool fixErrors, int indentationAmount, List searchPatterns, bool subDirectories, string settingsFile1, string settingsFile2) - { - this.ErrorsAsWarnings = new HashSet(); - this.ExemptFiles = new HashSet(); - this.FixErrors = fixErrors; - this.IndentationAmount = indentationAmount; - this.IgnoreErrors = new HashSet(); - this.SearchPatternResults = new HashSet(); - this.SearchPatterns = searchPatterns; - this.ServiceProvider = serviceProvider; - this.SettingsFile1 = settingsFile1; - this.SettingsFile2 = settingsFile2; - this.ShowLogo = showLogo; - this.SubDirectories = subDirectories; - } - - private HashSet ErrorsAsWarnings { get; } - - private HashSet ExemptFiles { get; } - - private bool FixErrors { get; } - - private int IndentationAmount { get; } - - private HashSet IgnoreErrors { get; } - - private HashSet SearchPatternResults { get; } - - private List SearchPatterns { get; } - - private IWixToolsetServiceProvider ServiceProvider { get; } - - private string SettingsFile1 { get; } - - private string SettingsFile2 { get; } - - private bool SubDirectories { get; } - - public bool ShowLogo { get; } - - public bool StopParsing => throw new NotImplementedException(); - - public bool TryParseArgument(ICommandLineParser parser, string argument) - { - throw new NotImplementedException(); - } - - public int Execute() - { - // parse the settings if any were specified - if (null != this.SettingsFile1 || null != this.SettingsFile2) - { - this.ParseSettingsFiles(this.SettingsFile1, this.SettingsFile2); - } - else - { - if (File.Exists(ConvertCommand.SettingsFileDefault)) - { - this.ParseSettingsFiles(ConvertCommand.SettingsFileDefault, null); - } - } - - var messaging = this.ServiceProvider.GetService(); - var converter = new Wix3Converter(messaging, this.IndentationAmount, this.ErrorsAsWarnings, this.IgnoreErrors); - - var errors = this.InspectSubDirectories(converter, Path.GetFullPath(".")); - - foreach (var searchPattern in this.SearchPatterns) - { - if (!this.SearchPatternResults.Contains(searchPattern)) - { - Console.Error.WriteLine("Could not find file \"{0}\"", searchPattern); - errors++; - } - } - - return errors != 0 ? 2 : 0; - } - - /// - /// Get the files that match a search path pattern. - /// - /// The base directory at which to begin the search. - /// The search path pattern. - /// The files matching the pattern. - private static string[] GetFiles(string baseDir, string searchPath) - { - // convert alternate directory separators to the standard one - var filePath = searchPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); - var lastSeparator = filePath.LastIndexOf(Path.DirectorySeparatorChar); - string[] files = null; - - try - { - if (0 > lastSeparator) - { - files = Directory.GetFiles(baseDir, filePath); - } - else // found directory separator - { - var searchPattern = filePath.Substring(lastSeparator + 1); - - files = Directory.GetFiles(filePath.Substring(0, lastSeparator + 1), searchPattern); - } - } - catch (DirectoryNotFoundException) - { - // don't let this function throw the DirectoryNotFoundException. (this exception - // occurs for non-existant directories and invalid characters in the searchPattern) - } - - return files; - } - - /// - /// Inspect sub-directories. - /// - /// The directory whose sub-directories will be inspected. - /// The number of errors that were found. - private int InspectSubDirectories(Wix3Converter converter, string directory) - { - var errors = 0; - - foreach (var searchPattern in this.SearchPatterns) - { - foreach (var sourceFilePath in GetFiles(directory, searchPattern)) - { - var file = new FileInfo(sourceFilePath); - - if (!this.ExemptFiles.Contains(file.Name.ToUpperInvariant())) - { - this.SearchPatternResults.Add(searchPattern); - errors += converter.ConvertFile(file.FullName, this.FixErrors); - } - } - } - - if (this.SubDirectories) - { - foreach (var childDirectoryPath in Directory.GetDirectories(directory)) - { - errors += this.InspectSubDirectories(converter, childDirectoryPath); - } - } - - return errors; - } - - /// - /// Parse the primary and secondary settings files. - /// - /// The primary settings file. - /// The secondary settings file. - private void ParseSettingsFiles(string localSettingsFile1, string localSettingsFile2) - { - if (null == localSettingsFile1 && null != localSettingsFile2) - { - throw new ArgumentException("Cannot specify a secondary settings file (set2) without a primary settings file (set1).", "localSettingsFile2"); - } - - var settingsFile = localSettingsFile1; - while (null != settingsFile) - { - XmlTextReader reader = null; - try - { - reader = new XmlTextReader(settingsFile); - var doc = new XmlDocument(); - doc.Load(reader); - - // get the types of tests that will have their errors displayed as warnings - var testsIgnoredElements = doc.SelectNodes("/Settings/IgnoreErrors/Test"); - foreach (XmlElement test in testsIgnoredElements) - { - var key = test.GetAttribute("Id"); - this.IgnoreErrors.Add(key); - } - - // get the types of tests that will have their errors displayed as warnings - var testsAsWarningsElements = doc.SelectNodes("/Settings/ErrorsAsWarnings/Test"); - foreach (XmlElement test in testsAsWarningsElements) - { - var key = test.GetAttribute("Id"); - this.ErrorsAsWarnings.Add(key); - } - - // get the exempt files - var localExemptFiles = doc.SelectNodes("/Settings/ExemptFiles/File"); - foreach (XmlElement file in localExemptFiles) - { - var key = file.GetAttribute("Name").ToUpperInvariant(); - this.ExemptFiles.Add(key); - } - } - finally - { - if (null != reader) - { - reader.Close(); - } - } - - settingsFile = localSettingsFile2; - localSettingsFile2 = null; - } - } - } -} diff --git a/src/wixcop/CommandLine/HelpCommand.cs b/src/wixcop/CommandLine/HelpCommand.cs deleted file mode 100644 index 4a173cd9..00000000 --- a/src/wixcop/CommandLine/HelpCommand.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. - -namespace WixToolset.Tools.WixCop.CommandLine -{ - using System; - using WixToolset.Extensibility.Data; - using WixToolset.Extensibility.Services; - - internal class HelpCommand : ICommandLineCommand - { - public bool ShowLogo => true; - - public bool StopParsing => true; - - public int Execute() - { - Console.WriteLine(" usage: wixcop.exe sourceFile [sourceFile ...]"); - Console.WriteLine(); - Console.WriteLine(" -f fix errors automatically for writable files"); - Console.WriteLine(" -nologo suppress displaying the logo information"); - Console.WriteLine(" -s search for matching files in current dir and subdirs"); - Console.WriteLine(" -set1 primary settings file"); - Console.WriteLine(" -set2 secondary settings file (overrides primary)"); - Console.WriteLine(" -indent: indentation multiple (overrides default of 4)"); - Console.WriteLine(" -? this help information"); - Console.WriteLine(); - Console.WriteLine(" sourceFile may use wildcards like *.wxs"); - - return 0; - } - - public bool TryParseArgument(ICommandLineParser parser, string argument) - { - return true; - } - } -} diff --git a/src/wixcop/CommandLine/WixCopCommandLineParser.cs b/src/wixcop/CommandLine/WixCopCommandLineParser.cs deleted file mode 100644 index f06decee..00000000 --- a/src/wixcop/CommandLine/WixCopCommandLineParser.cs +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. - -namespace WixToolset.Tools.WixCop.CommandLine -{ - using System; - using System.Collections.Generic; - using WixToolset.Core; - using WixToolset.Extensibility.Data; - using WixToolset.Extensibility.Services; - using WixToolset.Tools.WixCop.Interfaces; - - public sealed class WixCopCommandLineParser : IWixCopCommandLineParser - { - private bool fixErrors; - private int indentationAmount; - private readonly List searchPatterns; - private readonly IWixToolsetServiceProvider serviceProvider; - private string settingsFile1; - private string settingsFile2; - private bool showHelp; - private bool showLogo; - private bool subDirectories; - - public WixCopCommandLineParser(IWixToolsetServiceProvider serviceProvider) - { - this.serviceProvider = serviceProvider; - - this.indentationAmount = 4; - this.searchPatterns = new List(); - this.showLogo = true; - } - - public ICommandLineArguments Arguments { get; set; } - - public ICommandLineCommand ParseWixCopCommandLine() - { - this.Parse(); - - if (this.showLogo) - { - AppCommon.DisplayToolHeader(); - Console.WriteLine(); - } - - if (this.showHelp) - { - return new HelpCommand(); - } - - return new ConvertCommand( - this.serviceProvider, - this.showLogo, - this.fixErrors, - this.indentationAmount, - this.searchPatterns, - this.subDirectories, - this.settingsFile1, - this.settingsFile2); - } - - private void Parse() - { - this.showHelp = 0 == this.Arguments.Arguments.Length; - var parser = this.Arguments.Parse(); - - while (!this.showHelp && - String.IsNullOrEmpty(parser.ErrorArgument) && - parser.TryGetNextSwitchOrArgument(out var arg)) - { - if (String.IsNullOrWhiteSpace(arg)) // skip blank arguments. - { - continue; - } - - if (parser.IsSwitch(arg)) - { - if (!this.ParseArgument(parser, arg)) - { - parser.ErrorArgument = arg; - } - } - else - { - this.searchPatterns.Add(arg); - } - } - } - - private bool ParseArgument(ICommandLineParser parser, string arg) - { - var parameter = arg.Substring(1); - - switch (parameter.ToLowerInvariant()) - { - case "?": - this.showHelp = true; - return true; - case "f": - this.fixErrors = true; - return true; - case "nologo": - this.showLogo = false; - return true; - case "s": - this.subDirectories = true; - return true; - default: // other parameters - if (parameter.StartsWith("set1", StringComparison.Ordinal)) - { - this.settingsFile1 = parameter.Substring(4); - } - else if (parameter.StartsWith("set2", StringComparison.Ordinal)) - { - this.settingsFile2 = parameter.Substring(4); - } - else if (parameter.StartsWith("indent:", StringComparison.Ordinal)) - { - try - { - this.indentationAmount = Convert.ToInt32(parameter.Substring(7)); - } - catch - { - throw new ArgumentException("Invalid numeric argument.", parameter); - } - } - else - { - throw new ArgumentException("Invalid argument.", parameter); - } - return true; - } - } - } -} diff --git a/src/wixcop/Interfaces/IWixCopCommandLineParser.cs b/src/wixcop/Interfaces/IWixCopCommandLineParser.cs deleted file mode 100644 index 44c75289..00000000 --- a/src/wixcop/Interfaces/IWixCopCommandLineParser.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. - -namespace WixToolset.Tools.WixCop.Interfaces -{ - using WixToolset.Extensibility.Data; - - public interface IWixCopCommandLineParser - { - ICommandLineArguments Arguments { get; set; } - - ICommandLineCommand ParseWixCopCommandLine(); - } -} diff --git a/src/wixcop/Program.cs b/src/wixcop/Program.cs deleted file mode 100644 index 5e72f8ea..00000000 --- a/src/wixcop/Program.cs +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. - -namespace WixToolset.Tools.WixCop -{ - using System; - using System.Diagnostics; - using WixToolset.Core; - using WixToolset.Extensibility; - using WixToolset.Extensibility.Data; - using WixToolset.Extensibility.Services; - using WixToolset.Tools.Core; - using WixToolset.Tools.WixCop.CommandLine; - using WixToolset.Tools.WixCop.Interfaces; - - /// - /// Wix source code style inspector and converter. - /// - public sealed class Program - { - /// - /// The main entry point for the application. - /// - /// The commandline arguments. - /// The number of errors that were found. - [STAThread] - public static int Main(string[] args) - { - var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider(); - var listener = new ConsoleMessageListener("WXCP", "wixcop.exe"); - - serviceProvider.AddService((x, y) => listener); - serviceProvider.AddService((x, y) => new WixCopCommandLineParser(x)); - - var program = new Program(); - return program.Run(serviceProvider, args); - } - - /// - /// Run the application with the given arguments. - /// - /// Service provider to use throughout this execution. - /// The commandline arguments. - /// The number of errors that were found. - public int Run(IWixToolsetServiceProvider serviceProvider, string[] args) - { - try - { - var listener = serviceProvider.GetService(); - var messaging = serviceProvider.GetService(); - messaging.SetListener(listener); - - var arguments = serviceProvider.GetService(); - arguments.Populate(args); - - var commandLine = serviceProvider.GetService(); - commandLine.Arguments = arguments; - var command = commandLine.ParseWixCopCommandLine(); - - if (command.ShowLogo) - { - var wixcopAssembly = this.GetType().Assembly; - var fv = FileVersionInfo.GetVersionInfo(wixcopAssembly.Location); - - Console.WriteLine("WiX Cop version {0}", fv.FileVersion); - Console.WriteLine("Copyright (C) .NET Foundation and contributors. All rights reserved."); - Console.WriteLine(); - } - - return command?.Execute() ?? 1; - } - catch (Exception e) - { - Console.Error.WriteLine("wixcop.exe : fatal error WXCP0001 : {0}\r\n\n\nStack Trace:\r\n{1}", e.Message, e.StackTrace); - - return 1; - } - } - } -} diff --git a/src/wixcop/WixCop.csproj b/src/wixcop/WixCop.csproj deleted file mode 100644 index 13a188ab..00000000 --- a/src/wixcop/WixCop.csproj +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - netcoreapp2.1;net461;net472 - Exe - Converter - WiX Error Correction Tool - embedded - true - - win-x86 - app.config - wixcop.exe.manifest - Major - - - - NU1701 - - - - - - - - - - - - - - - diff --git a/src/wixcop/WixCop.net461.v3.ncrunchproject b/src/wixcop/WixCop.net461.v3.ncrunchproject deleted file mode 100644 index cf22dfa9..00000000 --- a/src/wixcop/WixCop.net461.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/wixcop/WixCop.netcoreapp2.1.v3.ncrunchproject b/src/wixcop/WixCop.netcoreapp2.1.v3.ncrunchproject deleted file mode 100644 index cf22dfa9..00000000 --- a/src/wixcop/WixCop.netcoreapp2.1.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/wixcop/app.config b/src/wixcop/app.config deleted file mode 100644 index 65d3d6c3..00000000 --- a/src/wixcop/app.config +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/src/wixcop/wixcop.exe.manifest b/src/wixcop/wixcop.exe.manifest deleted file mode 100644 index bf4a93b0..00000000 --- a/src/wixcop/wixcop.exe.manifest +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - WiX Toolset Correction Tool - - - - - - - - - - true - - - -- cgit v1.2.3-55-g6feb