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

Copy paket exe to cwd on init #853

Merged
merged 7 commits into from
Jun 2, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Paket.Core/Constants.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,33 @@
open System
open System.IO

[<Literal>]
let GithubUrl = "https://github.com"

[<Literal>]
let DefaultNugetStream = "https://nuget.org/api/v2"

[<Literal>]
let GithubReleasesUrl = "https://api.github.com/repos/fsprojects/Paket/releases"

[<Literal>]
let GithubReleaseDownloadUrl = "https://github.com/fsprojects/Paket/releases/download"

[<Literal>]
let LockFileName = "paket.lock"

[<Literal>]
let DependenciesFileName = "paket.dependencies"

[<Literal>]
let PaketFolderName = ".paket"

[<Literal>]
let BootstrapperFileName = "paket.bootstrapper.exe"

[<Literal>]
let TargetsFileName = "paket.targets"

[<Literal>]
let ReferencesFile = "paket.references"

Expand Down
10 changes: 4 additions & 6 deletions src/Paket.Core/Paket.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{7bab0ae2-089f-4761-b138-a717aa2f86c5}</ProjectGuid>
<ProjectGuid>{7BAB0AE2-089F-4761-B138-A717AA2F86C5}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Paket</RootNamespace>
<AssemblyName>Paket.Core</AssemblyName>
Expand All @@ -18,14 +17,11 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>..\..\bin</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>
</DocumentationFile>
<StartArguments>update</StartArguments>
<StartAction>Project</StartAction>
<StartProgram>paket.exe</StartProgram>
Expand All @@ -41,6 +37,7 @@
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>..\..\bin\Paket.Core.XML</DocumentationFile>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
Expand Down Expand Up @@ -117,6 +114,7 @@
<Compile Include="PackageMetaData.fs" />
<Compile Include="PackageProcess.fs" />
<Compile Include="Environment.fs" />
<Compile Include="Releases.fs" />
<Compile Include="Simplifier.fs" />
<Compile Include="VSIntegration.fs" />
<Compile Include="NugetConvert.fs" />
Expand Down Expand Up @@ -269,4 +267,4 @@
</ItemGroup>
</When>
</Choose>
</Project>
</Project>
6 changes: 6 additions & 0 deletions src/Paket.Core/PublicAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ type Dependencies(dependenciesFileName: string) =
|> this.Process
|> List.map (fun (PackageName p,_,newVersion) -> p,newVersion)

/// Downloads the latest paket.bootstrapper into the .paket folder.
member this.DownloadLatestBootstrapper() : unit =
Utils.RunInLockedAccessMode(
this.RootPath,
fun () -> Releases.downloadLatestBootstrapper |> this.Process)

/// Pulls new paket.targets and bootstrapper and puts them into .paket folder.
member this.TurnOnAutoRestore(): unit =
Utils.RunInLockedAccessMode(
Expand Down
63 changes: 63 additions & 0 deletions src/Paket.Core/Releases.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module Paket.Releases

open System.IO
open System.Diagnostics
open Logging
open System
open Chessie.ErrorHandling
open Paket.Domain

let private getLatestVersionFromJson (data : string) =
try
let start = data.IndexOf("tag_name") + 11
let end' = data.IndexOf("\"", start)
(data.Substring(start, end' - start)) |> SemVer.Parse |> ok
with _ ->
fail ReleasesJsonParseError

let private download version (file:FileInfo) client =
trial {
tracen (sprintf "%A" file)

do! createDir(file.DirectoryName)
let url = sprintf "%s/%s/%s" Constants.GithubReleaseDownloadUrl (string version) file.Name

do! downloadFileSync url file.FullName client
}

let private doesNotExistsOrIsNewer (file:FileInfo) latest =
if (not <| file.Exists) then true
else
let verInfo = FileVersionInfo.GetVersionInfo file.FullName
let currentVersion = SemVer.Parse verInfo.FileVersion
currentVersion < latest

/// Downloads the latest version of the given files to the destination dir
let downloadLatestVersionOf files destDir =
use client = createWebClient(Constants.GithubUrl, None)

trial {
let! data = client |> downloadStringSync Constants.GithubReleasesUrl
let! latestVersion = getLatestVersionFromJson data

let! downloads =
files
|> List.map (fun file -> FileInfo(Path.Combine(destDir, file)))
|> List.filter (fun file -> doesNotExistsOrIsNewer file latestVersion)
|> List.map (fun file -> download latestVersion file client)
|> collect

ignore downloads
}

/// Downloads the latest version of the paket.bootstrapper to the .paket dir
let downloadLatestBootstrapper environment =
let exeDir = Path.Combine(environment.RootDirectory.FullName, Constants.PaketFolderName)

downloadLatestVersionOf [Constants.BootstrapperFileName] exeDir

/// Downloads the latest version of the paket.bootstrapper and paket.targets to the .paket dir
let downloadLatestBootstrapperAndTargets environment =
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather inline this and above functions - they seem pretty straightforward

let exeDir = Path.Combine(environment.RootDirectory.FullName, Constants.PaketFolderName)

downloadLatestVersionOf [Constants.TargetsFileName; Constants.BootstrapperFileName] exeDir
38 changes: 7 additions & 31 deletions src/Paket.Core/VSIntegration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,26 @@ open Logging
open System
open Chessie.ErrorHandling
open Domain
open Releases


let private getLatestVersionFromJson (data : string) =
try
let start = data.IndexOf("tag_name") + 11
let end' = data.IndexOf("\"", start)
(data.Substring(start, end' - start)) |> SemVer.Parse |> ok
with _ ->
fail ReleasesJsonParseError

/// Activates the Visual Studio Nuget autorestore feature in all projects
let TurnOnAutoRestore environment =
let exeDir = Path.Combine(environment.RootDirectory.FullName, ".paket")

use client = createWebClient("https://github.com",None)

let download version file =
trial {
do! createDir(exeDir)
let fileName = Path.Combine(exeDir, file)
let url = sprintf "https://github.com/fsprojects/Paket/releases/download/%s/%s" (string version) file

do! downloadFileSync url fileName client
}

trial {
let releasesUrl = "https://api.github.com/repos/fsprojects/Paket/releases";

let! data = client |> downloadStringSync releasesUrl
let! latestVersion = getLatestVersionFromJson data

let! downloads =
["paket.targets"; "paket.bootstrapper.exe"]
|> List.map (download latestVersion)
|> collect
trial {
do! downloadLatestBootstrapperAndTargets environment
let paketTargetsPath = Path.Combine(exeDir, "paket.targets")

environment.Projects
|> List.map fst
|> List.iter (fun project ->
let relativePath = createRelativePath project.FileName (Path.Combine(exeDir, "paket.targets"))
let relativePath = createRelativePath project.FileName paketTargetsPath
project.AddImportForPaketTargets(relativePath)
project.Save()
)
}

/// Deactivates the Visual Studio Nuget autorestore feature in all projects
let TurnOffAutoRestore environment =
let exeDir = Path.Combine(environment.RootDirectory.FullName, ".paket")

Expand Down
2 changes: 2 additions & 0 deletions src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open System.IO

open Paket.Logging
open Paket.Commands
open Paket.Releases

open Nessos.UnionArgParser
open PackageSources
Expand Down Expand Up @@ -122,6 +123,7 @@ let findRefs (results : ArgParseResults<_>) =

let init (results : ArgParseResults<InitArgs>) =
Dependencies.Init()
Dependencies.Locate().DownloadLatestBootstrapper()

let install (results : ArgParseResults<_>) =
let force = results.Contains <@ InstallArgs.Force @>
Expand Down