From 18b41a3d7e4ab3ba6b8f4e0cab9351ac90207f0e Mon Sep 17 00:00:00 2001 From: Matthias Dittrich Date: Thu, 1 Jun 2017 23:01:51 +0200 Subject: [PATCH 1/4] make the bootstrapper search harder for the paket.dependencies file (like paket is doing it). --- src/Paket.Bootstrapper/ArgumentParser.cs | 11 +++++++- src/Paket.Bootstrapper/PaketDependencies.cs | 28 ++++++++++++++++++--- src/Paket.Bootstrapper/Program.cs | 4 +++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/Paket.Bootstrapper/ArgumentParser.cs b/src/Paket.Bootstrapper/ArgumentParser.cs index dcd3196429..81ed0d9496 100644 --- a/src/Paket.Bootstrapper/ArgumentParser.cs +++ b/src/Paket.Bootstrapper/ArgumentParser.cs @@ -70,7 +70,7 @@ public static BootstrapperOptions ParseArgumentsAndConfigurations(IEnumerable Date: Thu, 1 Jun 2017 23:09:49 +0200 Subject: [PATCH 2/4] fix nullref --- src/Paket.Bootstrapper/ArgumentParser.cs | 4 ---- src/Paket.Bootstrapper/Program.cs | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Paket.Bootstrapper/ArgumentParser.cs b/src/Paket.Bootstrapper/ArgumentParser.cs index 81ed0d9496..07c8f5afc5 100644 --- a/src/Paket.Bootstrapper/ArgumentParser.cs +++ b/src/Paket.Bootstrapper/ArgumentParser.cs @@ -243,13 +243,9 @@ private static void FillDownloadOptionsFromArguments(DownloadArguments downloadA private static bool GetIsMagicMode(IFileSystemProxy fileSystemProxy) { -#if DEBUG - return true; -#else // Magic mode is defined by the bootstrapper being renamed 'paket.exe' var fileName = Path.GetFileName(fileSystemProxy.GetExecutingAssemblyPath()); return string.Equals(fileName, "paket.exe", StringComparison.OrdinalIgnoreCase); -#endif } private static string GetHash(string input) diff --git a/src/Paket.Bootstrapper/Program.cs b/src/Paket.Bootstrapper/Program.cs index 0579ec9dd6..4254988b1b 100644 --- a/src/Paket.Bootstrapper/Program.cs +++ b/src/Paket.Bootstrapper/Program.cs @@ -24,7 +24,7 @@ static void Main(string[] args) var fileProxy = new FileSystemProxy(); var optionsBeforeDependenciesFile = ArgumentParser.ParseArgumentsAndConfigurations(args, ConfigurationManager.AppSettings, - Environment.GetEnvironmentVariables(), fileProxy, null); + Environment.GetEnvironmentVariables(), fileProxy, Enumerable.Empty()); ConsoleImpl.Verbosity = optionsBeforeDependenciesFile.Verbosity; var argumentsFromDependenciesFile = From c287bda68af2e93ae8f1b7d99b8448597ac08025 Mon Sep 17 00:00:00 2001 From: Matthias Dittrich Date: Thu, 1 Jun 2017 23:20:32 +0200 Subject: [PATCH 3/4] trigger build again by cleanup: No need for multiple builds anymore. --- appveyor.yml | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 4ccb218cb2..5a9671b0d7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,21 +14,13 @@ nuget: account_feed: false project_feed: true -environment: - # these variables are common to all jobs - #common_var1: value1 +#environment: +# # these variables are common to all jobs +# #common_var1: value1 +# +# matrix: +# # first group +# - SkipIntegrationTests: true +# # second group +# - SkipNuGet: true - matrix: - # first group - - SkipIntegrationTests: true - # second group - - SkipNuGet: true - -#deploy: -# provider: NuGet -# server: https://ci.appveyor.com/nuget/paket # remove to push to NuGet.org -# #api_key: -# # secure: m49OJ7+Jdt9an3jPcTukHA== -# #skip_symbols: false -# #symbol_server: # remove to push symbols to SymbolSource.org -# artifact: /temp/.*\.nupkg/ From f1084200bb8d7085da0afe4c1fc17b50bda6b66b Mon Sep 17 00:00:00 2001 From: Matthias Dittrich Date: Thu, 1 Jun 2017 23:54:08 +0200 Subject: [PATCH 4/4] refactor to use proxy file system and add test. --- src/Paket.Bootstrapper/ArgumentParser.cs | 2 +- .../HelperProxies/FileSystemProxy.cs | 1 + .../HelperProxies/IFileSystemProxy.cs | 1 + .../Paket.Bootstrapper.csproj | 1 + src/Paket.Bootstrapper/PaketDependencies.cs | 20 ++++++----- src/Paket.Bootstrapper/Program.cs | 2 +- .../Properties/InternalsVisibleTo.cs | 4 +++ .../ArgumentParserTests.cs | 34 +++++++++++++++++++ 8 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 src/Paket.Bootstrapper/Properties/InternalsVisibleTo.cs diff --git a/src/Paket.Bootstrapper/ArgumentParser.cs b/src/Paket.Bootstrapper/ArgumentParser.cs index 07c8f5afc5..44a8807317 100644 --- a/src/Paket.Bootstrapper/ArgumentParser.cs +++ b/src/Paket.Bootstrapper/ArgumentParser.cs @@ -159,7 +159,7 @@ private static void FillRunOptionsFromArguments(BootstrapperOptions options, Lis } } - private static void FillNonRunOptionsFromArguments(BootstrapperOptions options, List commandArgs) + internal static void FillNonRunOptionsFromArguments(BootstrapperOptions options, List commandArgs) { if (commandArgs.Contains(CommandArgs.PreferNuget)) { diff --git a/src/Paket.Bootstrapper/HelperProxies/FileSystemProxy.cs b/src/Paket.Bootstrapper/HelperProxies/FileSystemProxy.cs index 11f6fa8a28..653864ea23 100644 --- a/src/Paket.Bootstrapper/HelperProxies/FileSystemProxy.cs +++ b/src/Paket.Bootstrapper/HelperProxies/FileSystemProxy.cs @@ -8,6 +8,7 @@ namespace Paket.Bootstrapper.HelperProxies { class FileSystemProxy : IFileSystemProxy { + public string GetCurrentDirectory() { return Directory.GetCurrentDirectory(); } public bool FileExists(string filename) { return File.Exists(filename); } public void CopyFile(string fileFrom, string fileTo, bool overwrite) { File.Copy(fileFrom, fileTo, overwrite); } public void DeleteFile(string filename) { File.Delete(filename); } diff --git a/src/Paket.Bootstrapper/HelperProxies/IFileSystemProxy.cs b/src/Paket.Bootstrapper/HelperProxies/IFileSystemProxy.cs index 305c67c1d2..10f1b41f06 100644 --- a/src/Paket.Bootstrapper/HelperProxies/IFileSystemProxy.cs +++ b/src/Paket.Bootstrapper/HelperProxies/IFileSystemProxy.cs @@ -6,6 +6,7 @@ namespace Paket.Bootstrapper.HelperProxies { public interface IFileSystemProxy { + string GetCurrentDirectory(); bool FileExists(string filename); void CopyFile(string fileFrom, string fileTo, bool overwrite = false); void DeleteFile(string filename); diff --git a/src/Paket.Bootstrapper/Paket.Bootstrapper.csproj b/src/Paket.Bootstrapper/Paket.Bootstrapper.csproj index 2fe1eec602..32e6707716 100644 --- a/src/Paket.Bootstrapper/Paket.Bootstrapper.csproj +++ b/src/Paket.Bootstrapper/Paket.Bootstrapper.csproj @@ -56,6 +56,7 @@ + diff --git a/src/Paket.Bootstrapper/PaketDependencies.cs b/src/Paket.Bootstrapper/PaketDependencies.cs index c54b3a41d2..7921a2b458 100644 --- a/src/Paket.Bootstrapper/PaketDependencies.cs +++ b/src/Paket.Bootstrapper/PaketDependencies.cs @@ -1,15 +1,16 @@ -using System; +using Paket.Bootstrapper.HelperProxies; +using System; using System.IO; using System.Text.RegularExpressions; namespace Paket.Bootstrapper { - static class PaketDependencies + internal static class PaketDependencies { private static readonly Regex bootstrapperArgsLine = new Regex("^\\s*version\\s+(?.*)$", RegexOptions.IgnoreCase | RegexOptions.Compiled); - const string DEPENDENCY_FILE = "paket.dependencies"; + internal const string DEPENDENCY_FILE = "paket.dependencies"; public static string GetBootstrapperArgs(TextReader reader) { @@ -26,10 +27,10 @@ public static string GetBootstrapperArgs(TextReader reader) return null; } - public static string LocateDependenciesFile(DirectoryInfo folder) + public static string LocateDependenciesFile(IFileSystemProxy proxy, DirectoryInfo folder) { var path = Path.Combine(folder.FullName, DEPENDENCY_FILE); - if (File.Exists(path)) + if (proxy.FileExists(path)) { return path; } @@ -37,7 +38,7 @@ public static string LocateDependenciesFile(DirectoryInfo folder) { if (folder.Parent != null) { - return LocateDependenciesFile(folder.Parent); + return LocateDependenciesFile(proxy, folder.Parent); } else { @@ -46,18 +47,19 @@ public static string LocateDependenciesFile(DirectoryInfo folder) } } - public static string GetBootstrapperArgsForFolder(string folder) + public static string GetBootstrapperArgsForFolder(IFileSystemProxy proxy) { try { - var path = LocateDependenciesFile(new DirectoryInfo(folder)); + var folder = proxy.GetCurrentDirectory(); + var path = LocateDependenciesFile(proxy, new DirectoryInfo(folder)); if (path == null) { ConsoleImpl.WriteTrace("Dependencies file was not found."); return null; } - using (var fileStream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)) + using (var fileStream = proxy.OpenRead(path)) { using (var reader = new StreamReader(fileStream)) { diff --git a/src/Paket.Bootstrapper/Program.cs b/src/Paket.Bootstrapper/Program.cs index 4254988b1b..ea4468598e 100644 --- a/src/Paket.Bootstrapper/Program.cs +++ b/src/Paket.Bootstrapper/Program.cs @@ -29,7 +29,7 @@ static void Main(string[] args) var argumentsFromDependenciesFile = WindowsProcessArguments.Parse( - PaketDependencies.GetBootstrapperArgsForFolder(Environment.CurrentDirectory)); + PaketDependencies.GetBootstrapperArgsForFolder(fileProxy)); var options = ArgumentParser.ParseArgumentsAndConfigurations(args, ConfigurationManager.AppSettings, Environment.GetEnvironmentVariables(), fileProxy, argumentsFromDependenciesFile); if (options.ShowHelp) diff --git a/src/Paket.Bootstrapper/Properties/InternalsVisibleTo.cs b/src/Paket.Bootstrapper/Properties/InternalsVisibleTo.cs new file mode 100644 index 0000000000..58a298b64d --- /dev/null +++ b/src/Paket.Bootstrapper/Properties/InternalsVisibleTo.cs @@ -0,0 +1,4 @@ + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Paket.Bootstrapper.Tests")] \ No newline at end of file diff --git a/tests/Paket.Bootstrapper.Tests/ArgumentParserTests.cs b/tests/Paket.Bootstrapper.Tests/ArgumentParserTests.cs index c5ba7c1e8b..01debcb963 100644 --- a/tests/Paket.Bootstrapper.Tests/ArgumentParserTests.cs +++ b/tests/Paket.Bootstrapper.Tests/ArgumentParserTests.cs @@ -6,6 +6,8 @@ using System.Linq; using NUnit.Framework; using Paket.Bootstrapper.HelperProxies; +using Moq; +using System.Text; namespace Paket.Bootstrapper.Tests { @@ -113,6 +115,11 @@ public Stream OpenRead(string filename) { return Stream.Null; } + + public string GetCurrentDirectory() + { + return Directory.GetCurrentDirectory(); + } } private static readonly IFileSystemProxy NormalModeFileSystemSystem = new DummyFileSystemProxy(Path.Combine(rootDir, "repo", ".paket", "paket.bootstrapper.exe")); @@ -641,5 +648,32 @@ public void Magic_MaxFileAgeInMinutes() Assert.That(result.DownloadArguments.MaxFileAgeInMinutes, Is.EqualTo(4242)); Assert.That(result.UnprocessedCommandArgs, Is.Empty); } + + + [Test] + public void Dependencies_FindDependenciesFile() + { + //arrange + var fs = new Mock(); + var cwd = Directory.GetCurrentDirectory(); + + var subDir = Path.Combine(cwd, "testing", "subdir"); + var depsFile = Path.Combine(cwd, PaketDependencies.DEPENDENCY_FILE); + var depsFileContent = "version 5.0.0-beta008"; + var depsFileStream = new MemoryStream(Encoding.UTF8.GetBytes(depsFileContent)); + fs.Setup(f => f.GetCurrentDirectory()).Returns(subDir); + fs.Setup(f => f.FileExists(It.IsAny())).Returns(false); + fs.Setup(f => f.FileExists(depsFile)).Returns(true); + fs.Setup(f => f.OpenRead(depsFile)).Returns(depsFileStream); + + //act + var opts = new BootstrapperOptions(); + var argstring = PaketDependencies.GetBootstrapperArgsForFolder(fs.Object); + var args = WindowsProcessArguments.Parse(argstring); + ArgumentParser.FillNonRunOptionsFromArguments(opts, args); + + //assert + Assert.That(opts.DownloadArguments.LatestVersion, Is.EqualTo("5.0.0-beta008")); + } } }