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

Support content and source files from github and nuget #213

5 changes: 3 additions & 2 deletions src/Paket/AddProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ let Add(package, version, force, hard, interactive, installAfter, dependenciesFi

if interactive then
let di = DirectoryInfo(".")
for proj in ProjectFile.FindAllProjects(".") do
if Utils.askYesNo(sprintf " Install to %s?" (proj.FullName.Replace(di.FullName,""))) then
for project in ProjectFile.FindAllProjects(".") do
if Utils.askYesNo(sprintf " Install to %s?" (project.FileName.Replace(di.FullName,""))) then
let proj = FileInfo(project.FileName)
match ProjectFile.FindReferencesFile proj with
| None ->
let newFileName =
Expand Down
108 changes: 57 additions & 51 deletions src/Paket/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ open Paket.PackageResolver
open System.IO
open System.Collections.Generic
open Paket.PackageSources
open System.Text.RegularExpressions

/// Downloads and extracts all packages.
let ExtractPackages(sources,force, packages:PackageResolution) =
Expand Down Expand Up @@ -72,14 +71,15 @@ let private findPackagesWithContent (usedPackages:Dictionary<_,_>) =

let private copyContentFiles (project : ProjectFile, packagesWithContent) =

let onBlackList (fi : FileInfo) =
let rules : list<(FileInfo -> bool)> = [
let rules : list<(FileInfo -> bool)> = [
fun f -> f.Name = "_._"
fun f -> Regex(".*\.transform").IsMatch f.Name
fun f -> Regex(".*\.pp").IsMatch f.Name
fun f -> f.Name.EndsWith(".transform")
fun f -> f.Name.EndsWith(".pp")
fun f -> f.Name.EndsWith(".tt")
fun f -> f.Name.EndsWith(".ttinclude")
]
rules
|> List.exists (fun rule -> rule(fi))

let onBlackList (fi : FileInfo) = rules |> List.exists (fun rule -> rule(fi))

let rec copyDirContents (fromDir : DirectoryInfo, toDir : Lazy<DirectoryInfo>) =
fromDir.GetDirectories() |> Array.toList
Expand All @@ -93,7 +93,12 @@ let private copyContentFiles (project : ProjectFile, packagesWithContent) =
packagesWithContent
|> List.collect (fun packageDir -> copyDirContents (packageDir, lazy (DirectoryInfo(Path.GetDirectoryName(project.FileName)))))

let private removeContentFiles (project: ProjectFile) =
let private removeCopiedFiles (project: ProjectFile) =
let rec removeEmptyDirHierarchy (dir : DirectoryInfo) =
if dir.Exists && dir.EnumerateFileSystemInfos() |> Seq.isEmpty then
dir.Delete()
removeEmptyDirHierarchy dir.Parent

let removeFilesAndTrimDirs (files: FileInfo list) =
for f in files do
if f.Exists then
Expand All @@ -107,20 +112,12 @@ let private removeContentFiles (project: ProjectFile) =
|> List.rev

for dirPath in dirsPathsDeepestFirst do
let dir = DirectoryInfo dirPath
if dir.Exists && dir.EnumerateFileSystemInfos() |> Seq.isEmpty then
dir.Delete()
removeEmptyDirHierarchy (DirectoryInfo dirPath)

project.GetContentFiles()
project.GetPaketFileItems()
|> List.filter (fun fi -> not <| fi.FullName.Contains("paket-files"))
|> removeFilesAndTrimDirs

let extractReferencesFromListFile projectFile =
match ProjectFile.FindReferencesFile <| FileInfo(projectFile) with
| Some file -> File.ReadAllLines file
| None -> [||]
|> Array.map (fun s -> s.Trim())
|> Array.filter (fun s -> System.String.IsNullOrWhiteSpace s |> not)


/// Installs the given packageFile.
let Install(sources,force, hard, lockFile:LockFile) =
Expand All @@ -131,14 +128,15 @@ let Install(sources,force, hard, lockFile:LockFile) =
|> Async.RunSynchronously
|> Array.choose id

for proj in ProjectFile.FindAllProjects(".") do
verbosefn "Installing to %s" proj.FullName
let directPackages = extractReferencesFromListFile proj.FullName
let project = ProjectFile.Load proj.FullName
let applicableProjects =
ProjectFile.FindAllProjects(".")
|> List.choose (fun p -> ProjectFile.FindReferencesFile (FileInfo(p.FileName))
|> Option.map (fun r -> p, ReferencesFile.FromFile(r)))

for project,referenceFile in applicableProjects do
verbosefn "Installing to %s" project.FileName

if directPackages |> Array.isEmpty |> not then verbosefn " - direct packages: %A" directPackages
let usedPackages = new Dictionary<_,_>()
let usedSourceFiles = new HashSet<_>()

let allPackages =
extractedPackages
Expand All @@ -147,36 +145,44 @@ let Install(sources,force, hard, lockFile:LockFile) =

let rec addPackage directly (name:string) =
let identity = name.ToLower()
if identity.StartsWith "file:" then
let sourceFile = name.Split(':').[1]
usedSourceFiles.Add sourceFile |> ignore
else
match allPackages |> Map.tryFind identity with
| Some package ->
match usedPackages.TryGetValue name with
| false,_ ->
usedPackages.Add(name,directly)
if not lockFile.Options.Strict then
for d,_ in package.Dependencies do
addPackage false d
| true,v -> usedPackages.[name] <- v || directly
| None -> failwithf "Project %s references package %s, but it was not found in the paket.lock file." proj.FullName name

directPackages
|> Array.iter (addPackage true)
match allPackages |> Map.tryFind identity with
| Some package ->
match usedPackages.TryGetValue name with
| false,_ ->
usedPackages.Add(name,directly)
if not lockFile.Options.Strict then
for d,_ in package.Dependencies do
addPackage false d
| true,v -> usedPackages.[name] <- v || directly
| None -> failwithf "Project %s references package %s, but it was not found in the paket.lock file." project.FileName name

referenceFile.NugetPackages
|> List.iter (addPackage true)

project.UpdateReferences(extractedPackages,usedPackages,hard)

removeCopiedFiles project

lockFile.SourceFiles
|> List.filter (fun file -> usedSourceFiles.Contains(file.Name))
|> project.UpdateSourceFiles
let getGitHubFilePath name =
(lockFile.SourceFiles |> List.find (fun f -> Path.GetFileName(f.Name) = name)).FilePath

removeContentFiles project
project.DeletePaketNodes("Content")
let gitHubFileItems =
referenceFile.GitHubFiles
|> List.map (fun file ->
{ BuildAction = project.DetermineBuildAction file.Name
Include = createRelativePath project.FileName (getGitHubFilePath file.Name)
Link = Some(Path.Combine(file.Link, Path.GetFileName(file.Name))) })

if not lockFile.Options.OmitContent then
let packagesWithContent = findPackagesWithContent usedPackages
let contentFiles = copyContentFiles(project, packagesWithContent)
project.UpdateContentFiles(contentFiles, hard)
let nuGetFileItems =
if not lockFile.Options.OmitContent
then
let files = copyContentFiles(project, findPackagesWithContent usedPackages)
files |> List.map (fun file ->
{ BuildAction = project.DetermineBuildAction file.Name
Include = createRelativePath project.FileName file.FullName
Link = None })
else []

project.UpdateFileItems(gitHubFileItems @ nuGetFileItems, hard)

project.Save()
3 changes: 1 addition & 2 deletions src/Paket/NugetConvert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ let ConvertFromNuget(force, installAfter, initAutoRestore, dependenciesFileName)
solution.AddPaketFolder(dependenciesFileName, if installAfter then Some("paket.lock") else None)
solution.Save()

for projFile in ProjectFile.FindAllProjects(".") do
let project = ProjectFile.Load(projFile.FullName)
for project in ProjectFile.FindAllProjects(".") do
project.ReplaceNugetPackagesFile()
project.RemoveNugetTargetsEntries()
project.Save()
Expand Down
Loading