Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] add overload for Dependencies.Init #3019

Merged
merged 3 commits into from Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion integrationtests/Paket.IntegrationTests/InitSpecs.fs
Expand Up @@ -54,4 +54,21 @@ let ``#1240 current bootstrapper should work``() =
|> shouldEqual true

File.Exists(scenarioTempPath "i001240-bootstrapper" </> "paket.exe")
|> shouldEqual true
|> shouldEqual true

[<Test>]
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);
15 changes: 10 additions & 5 deletions src/Paket.Core/PackageAnalysis/Environment.fs
Expand Up @@ -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
Expand All @@ -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
dependenciesFile.ToString() |> saveFile dependenciesFile.FileName

let init (directory : DirectoryInfo) =
let sources = [PackageSources.DefaultNuGetSource]
initWithContent sources [] directory
19 changes: 19 additions & 0 deletions src/Paket.Core/PublicAPI.fs
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't even know that flag?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added that to disable boostrapper on .net core. was not working anyway, no need to download it

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()))
Expand Down