From 9007bf0c197679f1a0845c4bc706fcbd4f1cb812 Mon Sep 17 00:00:00 2001 From: Enrico Sada Date: Mon, 29 Jan 2018 18:42:04 +0100 Subject: [PATCH 1/3] refactor extract parameters --- src/Paket.Core/PackageAnalysis/Environment.fs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Paket.Core/PackageAnalysis/Environment.fs b/src/Paket.Core/PackageAnalysis/Environment.fs index e619904e76..e36bf4bec2 100644 --- a/src/Paket.Core/PackageAnalysis/Environment.fs +++ b/src/Paket.Core/PackageAnalysis/Environment.fs @@ -81,18 +81,19 @@ module PaketEnv = environment.LockFile |> failIfNone (LockFileNotFound environment.RootDirectory) - let init (directory : DirectoryInfo) = + let initWithContent sources additional (directory : DirectoryInfo) = match locatePaketRootDirectory directory with | Some rootDirectory when rootDirectory.FullName = directory.FullName -> Logging.tracefn "Paket is already initialized in %s" rootDirectory.FullName ok () | _ -> - let sources = [PackageSources.DefaultNuGetSource] - let serialized = + let sourcesSerialized = (sources |> List.map (string >> DependenciesFileSerializer.sourceString)) @ [""] |> Array.ofList + + let serialized = Array.append sourcesSerialized (additional |> Array.ofList) let mainGroup = { Name = Constants.MainDependencyGroup @@ -102,11 +103,15 @@ module PaketEnv = Packages = [] RemoteFiles = [] } let groups = [Constants.MainDependencyGroup, mainGroup] |> Map.ofSeq - + let dependenciesFile = DependenciesFile( Path.Combine(directory.FullName, Constants.DependenciesFileName), groups, serialized) - dependenciesFile.ToString() |> saveFile dependenciesFile.FileName \ No newline at end of file + dependenciesFile.ToString() |> saveFile dependenciesFile.FileName + + let init (directory : DirectoryInfo) = + let sources = [PackageSources.DefaultNuGetSource] + initWithContent sources [] directory From a5bf56cb2d54c0cf60da1f09bc7ef8dd845ddaff Mon Sep 17 00:00:00 2001 From: Enrico Sada Date: Mon, 29 Jan 2018 18:42:04 +0100 Subject: [PATCH 2/3] add Init overload --- src/Paket.Core/PublicAPI.fs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Paket.Core/PublicAPI.fs b/src/Paket.Core/PublicAPI.fs index 050648d4ae..a98d5b7045 100644 --- a/src/Paket.Core/PublicAPI.fs +++ b/src/Paket.Core/PublicAPI.fs @@ -87,6 +87,25 @@ type Dependencies(dependenciesFileName: string) = deps.DownloadLatestBootstrapper() #endif + /// Initialize paket.dependencies file in the given directory + static member Init(directory, sources, additional, downloadBootstrapper) = + let directory = DirectoryInfo(directory) + + RunInLockedAccessMode( + directory.FullName, + fun () -> + PaketEnv.initWithContent sources additional directory + |> returnOrFail + ) + +#if !NO_BOOTSTRAPPER + if downloadBootstrapper then + let deps = Dependencies.Locate(directory.FullName) + deps.DownloadLatestBootstrapper() +#else + ignore downloadBootstrapper +#endif + /// Converts the solution from NuGet to Paket. static member ConvertFromNuget(force: bool,installAfter: bool, initAutoRestore: bool,credsMigrationMode: string option, ?directory: DirectoryInfo) : unit = let dir = defaultArg directory (DirectoryInfo(Directory.GetCurrentDirectory())) From 3f3881f08bd83f3a5a0ad93a70f5016cecf9e654 Mon Sep 17 00:00:00 2001 From: Enrico Sada Date: Tue, 30 Jan 2018 14:00:53 +0100 Subject: [PATCH 3/3] add test --- .../Paket.IntegrationTests/InitSpecs.fs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/integrationtests/Paket.IntegrationTests/InitSpecs.fs b/integrationtests/Paket.IntegrationTests/InitSpecs.fs index 4602f9d5c1..500caa03ca 100644 --- a/integrationtests/Paket.IntegrationTests/InitSpecs.fs +++ b/integrationtests/Paket.IntegrationTests/InitSpecs.fs @@ -54,4 +54,21 @@ let ``#1240 current bootstrapper should work``() = |> shouldEqual true File.Exists(scenarioTempPath "i001240-bootstrapper" "paket.exe") - |> shouldEqual true \ No newline at end of file + |> shouldEqual true + +[] +let ``#1041 init api``() = + let tempScenarioDir = scenarioTempPath "i001041-init-api" + + let url = "http://my.test/api" + let source = Paket.PackageSources.PackageSource.NuGetV2Source(url) + + Paket.Dependencies.Init(tempScenarioDir, [source], [ "download_license: true" ], false) + + let depsPath = tempScenarioDir "paket.dependencies" + File.Exists(depsPath) |> shouldEqual true + + let lines = File.ReadAllText(depsPath) + + StringAssert.Contains(url, lines); + StringAssert.Contains("download_license: true", lines);