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 5 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
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>
5 changes: 5 additions & 0 deletions src/Paket.Core/PublicAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ type Dependencies(dependenciesFileName: string) =
|> this.Process
|> List.map (fun (PackageName p,_,newVersion) -> p,newVersion)

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
61 changes: 61 additions & 0 deletions src/Paket.Core/Releases.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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 "https://github.com/fsprojects/Paket/releases/download/%s/%s" (string version) file.Name

do! downloadFileSync url file.FullName client
}

let private existsNotOrIsNewer (file:FileInfo) latest =
Copy link
Member

Choose a reason for hiding this comment

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

doesNotExist ?

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

let downloadLatestVersionOf files destDir =
let releasesUrl = "https://api.github.com/repos/fsprojects/Paket/releases";
Copy link
Member

Choose a reason for hiding this comment

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

please move this into the Constants module

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

Choose a reason for hiding this comment

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

Also Constants


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

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

ignore downloads
}

let downloadLatestBootstrapper environment =
let exeDir = Path.Combine(environment.RootDirectory.FullName, ".paket")

downloadLatestVersionOf ["paket.bootstrapper.exe"] exeDir
Copy link
Member

Choose a reason for hiding this comment

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

I know this is all refactored from existing code, but please put all these constants into the Constants module


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, ".paket")

downloadLatestVersionOf ["paket.targets"; "paket.bootstrapper.exe"] exeDir
36 changes: 5 additions & 31 deletions src/Paket.Core/VSIntegration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,19 @@ open Logging
open System
open Chessie.ErrorHandling
open 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
open Releases

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