From 000734d1ef05583277aee63ee2381045d71e77a5 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Fri, 20 Jan 2017 15:59:21 -0800 Subject: [PATCH 1/4] Ignore explicit glob **/*.cs --- .../TestAppWithExplicitIncludeGlob/Program.cs | 9 +++++++ .../project.json | 24 +++++++++++++++++++ .../Rules/MigrateBuildOptionsRule.cs | 5 ++++ .../transforms/IncludeContextTransform.cs | 22 +++++++++++++++-- .../GivenThatIWantToMigrateTestApps.cs | 15 ++++++++++++ 5 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/Program.cs create mode 100644 TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/project.json diff --git a/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/Program.cs b/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/Program.cs new file mode 100644 index 000000000..5f9be2467 --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/Program.cs @@ -0,0 +1,9 @@ +using System; + +class Program +{ + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } +} \ No newline at end of file diff --git a/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/project.json b/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/project.json new file mode 100644 index 000000000..67a885251 --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/project.json @@ -0,0 +1,24 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "debugType": "portable", + "emitEntryPoint": true, + "compile": { + "include": [ + "**/*.cs" + ] + } + }, + "dependencies": {}, + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.1" + } + }, + "imports": "dnxcore50" + } + } +} diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs index c0e3b0201..7b15bdf9e 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs @@ -110,10 +110,15 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules compilerOptions => projectFolderName, compilerOptions => compilerOptions.OutputName != null); + private string[] _compilePatternsBlackList = new string[] { + "**/*.cs" + }; + private IncludeContextTransform CompileFilesTransform => new IncludeContextTransform( "Compile", transformMappings: false, + patternsBlackList: _compilePatternsBlackList, condition: ic => ic != null, emitBuiltInIncludes: false); diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs b/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs index 65630c2da..06a82260d 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs @@ -25,6 +25,16 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms && includeContext.IncludeFiles != null && includeContext.IncludeFiles.Count > 0); + private bool IsPatternBlackListed(string pattern) + { + if (_patternsBlackList == null) + { + return false; + } + + return _patternsBlackList.Contains(pattern.Replace('\\', '/')); + } + protected virtual Func> IncludeExcludeTransformGetter => (itemName) => new AddItemTransform( itemName, @@ -36,6 +46,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms fullIncludeSet = fullIncludeSet.Union(includeContext.BuiltInsInclude.OrEmptyIfNull()); } + if (_patternsBlackList != null) + { + fullIncludeSet = fullIncludeSet.Where((pattern) => !IsPatternBlackListed(pattern)); + } + return FormatGlobPatternsForMsbuild(fullIncludeSet, includeContext.SourceBasePath); }, includeContext => @@ -50,7 +65,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms { return includeContext != null && ( - (includeContext.IncludePatterns != null && includeContext.IncludePatterns.Count > 0) + (includeContext.IncludePatterns != null && includeContext.IncludePatterns.Where((pattern) => !IsPatternBlackListed(pattern)).Count() > 0) || (_emitBuiltInIncludes && includeContext.BuiltInsInclude != null && @@ -68,6 +83,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms private readonly string _itemName; private bool _transformMappings; + private string[] _patternsBlackList; private bool _emitBuiltInIncludes; private readonly List> _metadata = new List>(); @@ -75,11 +91,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms string itemName, bool transformMappings = true, Func condition = null, - bool emitBuiltInIncludes = true) : base(condition) + bool emitBuiltInIncludes = true, + string[] patternsBlackList = null) : base(condition) { _itemName = itemName; _transformMappings = transformMappings; _emitBuiltInIncludes = emitBuiltInIncludes; + _patternsBlackList = patternsBlackList; _mappingsToTransfrom = (addItemTransform, targetPath) => { diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs index c569c6cc6..98e1f2169 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs @@ -640,6 +640,21 @@ namespace Microsoft.DotNet.Migration.Tests Restore(projectDirectory, projectName); BuildMSBuild(projectDirectory, projectName); } + + [Fact] + public void ItMigratesAndBuildsAppWithExplicitIncludeGlob() + { + const string projectName = "TestAppWithExplicitIncludeGlob"; + var projectDirectory = TestAssets.Get(projectName) + .CreateInstance() + .WithSourceFiles() + .Root + .FullName; + + MigrateProject(projectDirectory); + Restore(projectDirectory, projectName); + BuildMSBuild(projectDirectory, projectName); + } private void VerifyAutoInjectedDesktopReferences(DirectoryInfo projectDirectory, string projectName, bool shouldBePresent) { From ecd034b95cd8bcf2b8d3bd20dc9c23b1aed07f7a Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Mon, 23 Jan 2017 10:37:47 -0800 Subject: [PATCH 2/4] fix build errors after rebase --- test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs index 98e1f2169..f9ced890b 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs @@ -648,10 +648,9 @@ namespace Microsoft.DotNet.Migration.Tests var projectDirectory = TestAssets.Get(projectName) .CreateInstance() .WithSourceFiles() - .Root - .FullName; + .Root; - MigrateProject(projectDirectory); + MigrateProject(projectDirectory.FullName); Restore(projectDirectory, projectName); BuildMSBuild(projectDirectory, projectName); } From 3fa73a90d4b68330993fd65a0bcf0c789c531797 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Mon, 23 Jan 2017 11:35:32 -0800 Subject: [PATCH 3/4] fix EOL in test asset --- .../TestProjects/TestAppWithExplicitIncludeGlob/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/Program.cs b/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/Program.cs index 5f9be2467..c81448f54 100644 --- a/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/Program.cs +++ b/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/Program.cs @@ -6,4 +6,4 @@ class Program { Console.WriteLine("Hello World!"); } -} \ No newline at end of file +} From 7a65922895a7183f2dd69027ee6c6f88db1f7529 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Thu, 26 Jan 2017 09:02:21 -0800 Subject: [PATCH 4/4] apply review feedback --- .../Rules/MigrateBuildOptionsRule.cs | 4 ++-- .../transforms/IncludeContextTransform.cs | 22 ++++++------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs index 7b15bdf9e..b243be518 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs @@ -110,7 +110,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules compilerOptions => projectFolderName, compilerOptions => compilerOptions.OutputName != null); - private string[] _compilePatternsBlackList = new string[] { + private string[] _compilePatternsToExclude = new string[] { "**/*.cs" }; @@ -118,7 +118,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules new IncludeContextTransform( "Compile", transformMappings: false, - patternsBlackList: _compilePatternsBlackList, + patternsToExclude: _compilePatternsToExclude, condition: ic => ic != null, emitBuiltInIncludes: false); diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs b/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs index 06a82260d..80a671cd1 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs @@ -25,14 +25,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms && includeContext.IncludeFiles != null && includeContext.IncludeFiles.Count > 0); - private bool IsPatternBlackListed(string pattern) + private bool IsPatternExcluded(string pattern) { - if (_patternsBlackList == null) - { - return false; - } - - return _patternsBlackList.Contains(pattern.Replace('\\', '/')); + return _patternsToExclude.Contains(pattern.Replace('\\', '/')); } protected virtual Func> IncludeExcludeTransformGetter => @@ -46,10 +41,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms fullIncludeSet = fullIncludeSet.Union(includeContext.BuiltInsInclude.OrEmptyIfNull()); } - if (_patternsBlackList != null) - { - fullIncludeSet = fullIncludeSet.Where((pattern) => !IsPatternBlackListed(pattern)); - } + fullIncludeSet = fullIncludeSet.Where((pattern) => !IsPatternExcluded(pattern)); return FormatGlobPatternsForMsbuild(fullIncludeSet, includeContext.SourceBasePath); }, @@ -65,7 +57,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms { return includeContext != null && ( - (includeContext.IncludePatterns != null && includeContext.IncludePatterns.Where((pattern) => !IsPatternBlackListed(pattern)).Count() > 0) + (includeContext.IncludePatterns != null && includeContext.IncludePatterns.Where((pattern) => !IsPatternExcluded(pattern)).Count() > 0) || (_emitBuiltInIncludes && includeContext.BuiltInsInclude != null && @@ -83,7 +75,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms private readonly string _itemName; private bool _transformMappings; - private string[] _patternsBlackList; + private string[] _patternsToExclude; private bool _emitBuiltInIncludes; private readonly List> _metadata = new List>(); @@ -92,12 +84,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms bool transformMappings = true, Func condition = null, bool emitBuiltInIncludes = true, - string[] patternsBlackList = null) : base(condition) + string[] patternsToExclude = null) : base(condition) { _itemName = itemName; _transformMappings = transformMappings; _emitBuiltInIncludes = emitBuiltInIncludes; - _patternsBlackList = patternsBlackList; + _patternsToExclude = patternsToExclude ?? Array.Empty(); _mappingsToTransfrom = (addItemTransform, targetPath) => {