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

feature/nuget-in-path: Also search for the NuGet executable in the PATH #708

Merged
merged 5 commits into from
Mar 24, 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
6 changes: 6 additions & 0 deletions src/app/FakeLib/EnvironmentHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ let environVarOrNone name =
if String.IsNullOrEmpty var then None
else Some var

/// Splits the entries of an environment variable and removes the empty ones.
let splitEnvironVar name =
let var = environVarOrNone name
if var = None then [ ]
else var.Value.Split([| Path.PathSeparator |]) |> Array.toList

/// Retrieves the application settings variable with the given name
let appSetting (name : string) = ConfigurationManager.AppSettings.[name]

Expand Down
6 changes: 6 additions & 0 deletions src/app/FakeLib/FileSystemHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,9 @@ let isDirectory path =

/// Detects whether the given path is a file.
let isFile path = isDirectory path |> not

/// Detects whether the given path does not contains invalid characters.
let isValidPath (path:string) =
Path.GetInvalidPathChars()
|> Array.filter (fun char -> path.Contains(char.ToString()))
|> Array.isEmpty
11 changes: 9 additions & 2 deletions src/app/FakeLib/ProcessHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ let ExecProcessElevated cmd args timeOut =
si.FileName <- cmd
si.UseShellExecute <- true) timeOut

/// Gets the list of valid directories included in the PATH environment variable.
let pathDirectories =
splitEnvironVar "PATH"
|> Seq.map (fun value -> value.Trim())
|> Seq.filter (fun value -> not <| isNullOrEmpty value)
|> Seq.filter isValidPath

/// Sets the environment Settings for the given startInfo.
/// Existing values will be overriden.
/// [omit]
Expand Down Expand Up @@ -339,8 +346,8 @@ let findFile dirs file =
/// ## Parameters
/// - `exe` - The executable file to locate
let tryFindFileOnPath (file : string) : string option =
Environment.GetEnvironmentVariable("PATH").Split([| Path.PathSeparator |])
|> Seq.append ["."]
pathDirectories
|> Seq.append [ "." ]
|> fun path -> tryFindFile path file

/// Returns the AppSettings for the key - Splitted on ;
Expand Down
1 change: 1 addition & 0 deletions src/app/FakeLib/RestorePackageHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let findNuget defaultPath =
currentDirectory @@ ".nuget"
currentDirectory @@ "packages" @@ "NuGet.Commandline" @@ "tools"
currentDirectory @@ "packages" @@ "Nuget.Commandline" @@ "tools"]
|> Seq.append pathDirectories

let exeNames = ["nuget.exe"; "NuGet.exe"; "Nuget.exe"]

Expand Down