From 8c304cdc72bf5090ed1c7e5dcdb7cad54db01253 Mon Sep 17 00:00:00 2001 From: Nicolai Mikkel Brogaard Date: Mon, 15 Feb 2021 18:43:53 +0100 Subject: [PATCH] (GH-3143) Recreate the issue with a test (GH-3143) Don't try to parse empty solution file lines --- .../Properties/Resources.Designer.cs | 49 +++++++++++++------ .../Properties/Resources.resx | 44 +++++++++++++++++ .../Unit/Solution/SolutionParserTests.cs | 19 +++++++ src/Cake.Common/Solution/SolutionParser.cs | 6 +++ 4 files changed, 102 insertions(+), 16 deletions(-) diff --git a/src/Cake.Common.Tests/Properties/Resources.Designer.cs b/src/Cake.Common.Tests/Properties/Resources.Designer.cs index 58b4866ff6..965de5b72b 100644 --- a/src/Cake.Common.Tests/Properties/Resources.Designer.cs +++ b/src/Cake.Common.Tests/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace Cake.Common.Tests.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] public class Resources { @@ -328,7 +328,7 @@ public static string Nuspec_ContentFiles { /// <owners>Owner #1,Owner #2</owners> /// <licenseUrl>https://license.com</licenseUrl> /// <projectUrl>https://project.com</projectUrl> - /// <iconUr [rest of string was truncated]";. + /// <icon>i [rest of string was truncated]";. /// public static string Nuspec_FrameworkAssemblies { get { @@ -347,7 +347,7 @@ public static string Nuspec_FrameworkAssemblies { /// <owners>Owner #1,Owner #2</owners> /// <licenseUrl>https://license.com</licenseUrl> /// <projectUrl>https://project.com</projectUrl> - /// <iconUr [rest of string was truncated]";. + /// <icon>i [rest of string was truncated]";. /// public static string Nuspec_License { get { @@ -366,7 +366,7 @@ public static string Nuspec_License { /// <owners>Owner #1,Owner #2</owners> /// <licenseUrl>https://license.com</licenseUrl> /// <projectUrl>https://project.com</projectUrl> - /// <iconUr [rest of string was truncated]";. + /// <icon>i [rest of string was truncated]";. /// public static string Nuspec_Metadata { get { @@ -405,7 +405,7 @@ public static string Nuspec_Metadata_PackWithTargetFrameworkDependencies { /// <owners>Owner #1,Owner #2</owners> /// <licenseUrl>https://license.com</licenseUrl> /// <projectUrl>https://project.com</projectUrl> - /// <iconUr [rest of string was truncated]";. + /// <icon>i [rest of string was truncated]";. /// public static string Nuspec_Metadata_WithDependencies { get { @@ -424,10 +424,10 @@ public static string Nuspec_Metadata_WithDependencies { /// <owners>Owner #1,Owner #2</owners> /// <licenseUrl>https://license.com</licenseUrl> /// <projectUrl>https://project.com</projectUrl> + /// <icon>images\icon.png</icon> /// <iconUrl>https://icon.com</iconUrl> /// <requireLicenseAcceptance>true</requireLicenseAcceptance> - /// <developmentDependency>true</developmentDependency> - /// <descriptio [rest of string was truncated]";. + /// <developmentDependency>true</devel [rest of string was truncated]";. /// public static string Nuspec_Metadata_WithoutNamespaces { get { @@ -446,10 +446,10 @@ public static string Nuspec_Metadata_WithoutNamespaces { /// <owners>Owner #1,Owner #2</owners> /// <licenseUrl>https://license.com</licenseUrl> /// <projectUrl>https://project.com</projectUrl> + /// <icon>images\icon.png</icon> /// <iconUrl>https://icon.com</iconUrl> /// <requireLicenseAcceptance>true</requireLicenseAcceptance> - /// <developmentDependency>true</developmentDependency> - /// <descriptio [rest of string was truncated]";. + /// <developmentDependency>true</devel [rest of string was truncated]";. /// public static string Nuspec_Metadata_WithoutNamespaces_WithDependencies { get { @@ -468,10 +468,10 @@ public static string Nuspec_Metadata_WithoutNamespaces_WithDependencies { /// <owners>Owner #1,Owner #2</owners> /// <licenseUrl>https://license.com</licenseUrl> /// <projectUrl>https://project.com</projectUrl> + /// <icon>images\icon.png</icon> /// <iconUrl>https://icon.com</iconUrl> /// <requireLicenseAcceptance>true</requireLicenseAcceptance> - /// <developmentDependency>true</developmentDependency> - /// <descriptio [rest of string was truncated]";. + /// <developmentDependency>true</devel [rest of string was truncated]";. /// public static string Nuspec_Metadata_WithoutNamespaces_WithTargetFramworkDependencies { get { @@ -490,7 +490,7 @@ public static string Nuspec_Metadata_WithoutNamespaces_WithTargetFramworkDepende /// <owners>Owner #1,Owner #2</owners> /// <licenseUrl>https://license.com</licenseUrl> /// <projectUrl>https://project.com</projectUrl> - /// <iconUr [rest of string was truncated]";. + /// <icon>i [rest of string was truncated]";. /// public static string Nuspec_Metadata_WithTargetFrameworkDependencies { get { @@ -562,7 +562,7 @@ public static string Nuspec_NoMetadataValues_WithoutNamespaces { /// <owners>Owner #1,Owner #2</owners> /// <licenseUrl>https://license.com</licenseUrl> /// <projectUrl>https://project.com</projectUrl> - /// <iconUr [rest of string was truncated]";. + /// <icon>i [rest of string was truncated]";. /// public static string Nuspec_PackageTypes { get { @@ -598,7 +598,7 @@ public static string Nuspec_ProjectFile { /// <owners>Owner #1,Owner #2</owners> /// <licenseUrl>https://license.com</licenseUrl> /// <projectUrl>https://project.com</projectUrl> - /// <iconUr [rest of string was truncated]";. + /// <icon>i [rest of string was truncated]";. /// public static string Nuspec_References { get { @@ -617,7 +617,7 @@ public static string Nuspec_References { /// <owners>Owner #1,Owner #2</owners> /// <licenseUrl>https://license.com</licenseUrl> /// <projectUrl>https://project.com</projectUrl> - /// <iconUr [rest of string was truncated]";. + /// <icon>i [rest of string was truncated]";. /// public static string Nuspec_References_WithTargetFramework { get { @@ -636,7 +636,7 @@ public static string Nuspec_References_WithTargetFramework { /// <owners>Owner #1,Owner #2</owners> /// <licenseUrl>https://license.com</licenseUrl> /// <projectUrl>https://project.com</projectUrl> - /// <iconUr [rest of string was truncated]";. + /// <icon>i [rest of string was truncated]";. /// public static string Nuspec_Repository { get { @@ -661,6 +661,23 @@ public static string Solution_WithProjectsAndFolders { } } + /// + /// Looks up a localized string similar to Microsoft Visual Studio Solution File, Format Version 12.00 + ///# Visual Studio 14 + ///VisualStudioVersion = 14.0.25123.0 + ///MinimumVisualStudioVersion = 10.0.40219.1 + ///Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2400A22B-695E-4BDF-93CB-8757F5FB3FB7}" + ///EndProject + ///Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{69930DD1-1688-4407-B4AB-B9E2C0BFB284}" + ///EndProject + ///Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dummy", "src\dummy\dummy.csproj", "{ADCB37DA-2469-462F-99 [rest of string was truncated]";. + /// + public static string Solution_WithProjectsAndFoldersAndMissingLine { + get { + return ResourceManager.GetString("Solution_WithProjectsAndFoldersAndMissingLine", resourceCulture); + } + } + /// /// Looks up a localized string similar to using System.Reflection; ///using System.Runtime.CompilerServices; diff --git a/src/Cake.Common.Tests/Properties/Resources.resx b/src/Cake.Common.Tests/Properties/Resources.resx index 4803f4cfec..8fb0c0c0b0 100644 --- a/src/Cake.Common.Tests/Properties/Resources.resx +++ b/src/Cake.Common.Tests/Properties/Resources.resx @@ -900,6 +900,50 @@ Global {5D553DC6-36AB-4823-85BD-A33F57C81381} = {69930DD1-1688-4407-B4AB-B9E2C0BFB284} EndGlobalSection EndGlobal + + + Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2400A22B-695E-4BDF-93CB-8757F5FB3FB7}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{69930DD1-1688-4407-B4AB-B9E2C0BFB284}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dummy", "src\dummy\dummy.csproj", "{ADCB37DA-2469-462F-99F6-9D4FB7691A3B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dummy.Tests", "test\dummy.Tests\dummy.Tests.csproj", "{5D553DC6-36AB-4823-85BD-A33F57C81381}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "executable", "executable\executable.csproj", "{CF305C72-F3E0-44AA-9474-6F12C5276F9F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {ADCB37DA-2469-462F-99F6-9D4FB7691A3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ADCB37DA-2469-462F-99F6-9D4FB7691A3B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ADCB37DA-2469-462F-99F6-9D4FB7691A3B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ADCB37DA-2469-462F-99F6-9D4FB7691A3B}.Release|Any CPU.Build.0 = Release|Any CPU + {5D553DC6-36AB-4823-85BD-A33F57C81381}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5D553DC6-36AB-4823-85BD-A33F57C81381}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5D553DC6-36AB-4823-85BD-A33F57C81381}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5D553DC6-36AB-4823-85BD-A33F57C81381}.Release|Any CPU.Build.0 = Release|Any CPU + {CF305C72-F3E0-44AA-9474-6F12C5276F9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CF305C72-F3E0-44AA-9474-6F12C5276F9F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CF305C72-F3E0-44AA-9474-6F12C5276F9F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CF305C72-F3E0-44AA-9474-6F12C5276F9F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + + {ADCB37DA-2469-462F-99F6-9D4FB7691A3B} = {2400A22B-695E-4BDF-93CB-8757F5FB3FB7} + {5D553DC6-36AB-4823-85BD-A33F57C81381} = {69930DD1-1688-4407-B4AB-B9E2C0BFB284} + EndGlobalSection +EndGlobal <?xml version="1.0" encoding="utf-8"?> diff --git a/src/Cake.Common.Tests/Unit/Solution/SolutionParserTests.cs b/src/Cake.Common.Tests/Unit/Solution/SolutionParserTests.cs index f35b221be3..0d960cc6e3 100644 --- a/src/Cake.Common.Tests/Unit/Solution/SolutionParserTests.cs +++ b/src/Cake.Common.Tests/Unit/Solution/SolutionParserTests.cs @@ -111,6 +111,25 @@ public void Should_Properly_Parse_Relation_Between_Project_And_Folder() Assert.Contains(dummyProject, srcFolder.Items); Assert.Equal(srcFolder, dummyProject.Parent); } + + [Fact] + public void Should_Properly_Parse_Projects_With_Empty_Lines() + { + // Given + var fixture = new SolutionParserFixture(); + var slnFilePath = fixture.WithSolutionFile(Resources.Solution_WithProjectsAndFoldersAndMissingLine); + var solutionParser = new SolutionParser(fixture.FileSystem, fixture.Environment); + + // When + var result = solutionParser.Parse(slnFilePath); + + // Then + Assert.NotNull(result); + Assert.NotNull(result.Projects); + Assert.Equal(5, result.Projects.Count); + var onlyProjects = result.Projects.Where(x => !(x is SolutionFolder)).ToList(); + Assert.Equal(3, onlyProjects.Count); + } } } } \ No newline at end of file diff --git a/src/Cake.Common/Solution/SolutionParser.cs b/src/Cake.Common/Solution/SolutionParser.cs index 2ee2253e8d..eec359270d 100644 --- a/src/Cake.Common/Solution/SolutionParser.cs +++ b/src/Cake.Common/Solution/SolutionParser.cs @@ -73,6 +73,12 @@ public SolutionParserResult Parse(FilePath solutionPath) foreach (var line in file.ReadLines(Encoding.UTF8)) { var trimmed = line.Trim(); + + if (trimmed == string.Empty) + { + continue; + } + if (line.StartsWith("Project(\"{")) { var project = ParseSolutionProjectLine(file, line);