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

Content none mode #211

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/Paket/AddProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let Add(package, version, force, hard, interactive, installAfter, dependenciesFi
let lockFileName = DependenciesFile.FindLockfile dependenciesFileName

let lockFile =
let lockFile = LockFile(lockFileName.FullName, dependenciesFile.Strict, resolvedPackages, resolution.ResolvedSourceFiles)
let lockFile = LockFile(lockFileName.FullName, dependenciesFile.Options, resolvedPackages, resolution.ResolvedSourceFiles)
lockFile.Save()
lockFile

Expand Down
39 changes: 24 additions & 15 deletions src/Paket/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ open Paket.ModuleResolver
open Paket.PackageResolver
open Paket.PackageSources

/// [omit]
type InstallOptions =
{ Strict : bool
OmitContent : bool }

static member Default = { Strict = false; OmitContent = false}

/// [omit]
module DependenciesFileParser =

Expand Down Expand Up @@ -64,7 +71,7 @@ module DependenciesFileParser =
| _ -> failwithf "could not parse version range \"%s\"" text


let private (|Remote|Package|Blank|ReferencesMode|SourceFile|) (line:string) =
let private (|Remote|Package|Blank|ReferencesMode|OmitContent|SourceFile|) (line:string) =
match line.Trim() with
| _ when String.IsNullOrWhiteSpace line -> Blank
| trimmed when trimmed.StartsWith "source" ->
Expand All @@ -89,6 +96,7 @@ module DependenciesFileParser =
| name :: [] -> Package(name,">= 0")
| _ -> failwithf "could not retrieve nuget package from %s" trimmed
| trimmed when trimmed.StartsWith "references" -> ReferencesMode(trimmed.Replace("references","").Trim() = "strict")
| trimmed when trimmed.StartsWith "content" -> OmitContent(trimmed.Replace("content","").Trim() = "none")
| trimmed when trimmed.StartsWith "github" ->
let parts = trimmed.Replace("\"", "").Trim().Split([|' '|],StringSplitOptions.RemoveEmptyEntries)
let getParts (projectSpec:string) =
Expand All @@ -102,29 +110,30 @@ module DependenciesFileParser =
| _ -> Blank

let parseDependenciesFile fileName (lines:string seq) =
((0, false, [], [], []), lines)
||> Seq.fold(fun (lineNo, referencesMode, sources: PackageSource list, packages, sourceFiles: UnresolvedSourceFile list) line ->
((0, InstallOptions.Default, [], [], []), lines)
||> Seq.fold(fun (lineNo, options, sources: PackageSource list, packages, sourceFiles: UnresolvedSourceFile list) line ->
let lineNo = lineNo + 1
try
match line with
| Remote(newSource,auth) -> lineNo, referencesMode, (PackageSource.Parse(newSource.TrimEnd([|'/'|]),auth) :: sources), packages, sourceFiles
| Blank -> lineNo, referencesMode, sources, packages, sourceFiles
| ReferencesMode mode -> lineNo, mode, sources, packages, sourceFiles
| Remote(newSource,auth) -> lineNo, options, (PackageSource.Parse(newSource.TrimEnd([|'/'|]),auth) :: sources), packages, sourceFiles
| Blank -> lineNo, options, sources, packages, sourceFiles
| ReferencesMode mode -> lineNo, { options with Strict = mode }, sources, packages, sourceFiles
| OmitContent omit -> lineNo, { options with OmitContent = omit }, sources, packages, sourceFiles
| Package(name,version) ->
lineNo, referencesMode, sources,
lineNo, options, sources,
{ Sources = sources
Name = name
ResolverStrategy = parseResolverStrategy version
Parent = DependenciesFile fileName
VersionRequirement = parseVersionRequirement(version.Trim '!') } :: packages, sourceFiles
| SourceFile((owner,project, commit), path) ->
lineNo, referencesMode, sources, packages, { Owner = owner; Project = project; Commit = commit; Name = path } :: sourceFiles
lineNo, options, sources, packages, { Owner = owner; Project = project; Commit = commit; Name = path } :: sourceFiles

with
| exn -> failwithf "Error in paket.dependencies line %d%s %s" lineNo Environment.NewLine exn.Message)
|> fun (_,mode,_,packages,remoteFiles) ->
|> fun (_,options,_,packages,remoteFiles) ->
fileName,
mode,
options,
packages |> List.rev,
remoteFiles |> List.rev

Expand Down Expand Up @@ -155,7 +164,7 @@ module DependenciesFileSerializer =
if text <> "" && preReleases <> "" then text + " " + preReleases else text + preReleases

/// Allows to parse and analyze paket.dependencies files.
type DependenciesFile(fileName,strictMode,packages : PackageRequirement list, remoteFiles : UnresolvedSourceFile list) =
type DependenciesFile(fileName,options,packages : PackageRequirement list, remoteFiles : UnresolvedSourceFile list) =
let packages = packages |> Seq.toList
let dependencyMap = Map.ofSeq (packages |> Seq.map (fun p -> p.Name, p.VersionRequirement))

Expand All @@ -170,7 +179,7 @@ type DependenciesFile(fileName,strictMode,packages : PackageRequirement list, re
member __.Packages = packages
member __.HasPackage (name : string) = packages |> List.exists (fun p -> p.Name.ToLower() = name.ToLower())
member __.RemoteFiles = remoteFiles
member __.Strict = strictMode
member __.Options = options
member __.FileName = fileName
member __.Sources = sources
member this.Resolve(force) =
Expand Down Expand Up @@ -207,7 +216,7 @@ type DependenciesFile(fileName,strictMode,packages : PackageRequirement list, re
ResolverStrategy = DependenciesFileParser.parseResolverStrategy version
Parent = PackageRequirementSource.DependenciesFile fileName }
tracefn "Adding %s %s to paket.dependencies" packageName (versionRange.ToString())
DependenciesFile(fileName,strictMode,packages @ [newPackage], remoteFiles)
DependenciesFile(fileName,options,packages @ [newPackage], remoteFiles)

override __.ToString() =
let sources =
Expand All @@ -219,8 +228,8 @@ type DependenciesFile(fileName,strictMode,packages : PackageRequirement list, re
let hasReportedSource = ref false
let hasReportedFirst = ref false
let hasReportedSecond = ref false
[ if strictMode then
yield "references strict"
[ if options.Strict then yield "references strict"
if options.OmitContent then yield "content none"
for sources, packages in sources do
for source in sources do
hasReportedSource := true
Expand Down
2 changes: 1 addition & 1 deletion src/Paket/FindOutdated.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let FindOutdated(strict,includingPrereleases,dependenciesFileName) =
| false,false -> VersionRequirement.AllReleases
{ p with VersionRequirement = requirement})

DependenciesFile(loadedFile.FileName,loadedFile.Strict,newPackages,loadedFile.RemoteFiles)
DependenciesFile(loadedFile.FileName,loadedFile.Options,newPackages,loadedFile.RemoteFiles)

let resolution = dependenciesFile.Resolve(true)
let resolvedPackages = resolution.ResolvedPackages.GetModelOrFail()
Expand Down
13 changes: 8 additions & 5 deletions src/Paket/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let private findPackagesWithContent (usedPackages:Dictionary<_,_>) =
|> Seq.choose (fun packageDir -> packageDir.GetDirectories("Content") |> Array.tryFind (fun _ -> true))
|> Seq.toList

let private copyContentFilesToProject (project : ProjectFile) packagesWithContent =
let private copyContentFiles (project : ProjectFile, packagesWithContent) =

let onBlackList (fi : FileInfo) =
let rules : list<(FileInfo -> bool)> = [
Expand Down Expand Up @@ -156,7 +156,7 @@ let Install(sources,force, hard, lockFile:LockFile) =
match usedPackages.TryGetValue name with
| false,_ ->
usedPackages.Add(name,directly)
if not lockFile.Strict then
if not lockFile.Options.Strict then
for d,_ in package.Dependencies do
addPackage false d
| true,v -> usedPackages.[name] <- v || directly
Expand All @@ -172,8 +172,11 @@ let Install(sources,force, hard, lockFile:LockFile) =
|> project.UpdateSourceFiles

removeContentFiles project
let packagesWithContent = findPackagesWithContent usedPackages
let contentFiles = copyContentFilesToProject project packagesWithContent
project.UpdateContentFiles(contentFiles)
project.DeletePaketNodes("Content")

if not lockFile.Options.OmitContent then
let packagesWithContent = findPackagesWithContent usedPackages
let contentFiles = copyContentFiles(project, packagesWithContent)
project.UpdateContentFiles(contentFiles, hard)

project.Save()
28 changes: 16 additions & 12 deletions src/Paket/LockFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module LockFileSerializer =
| Range(_, v1, v2, _) -> ">= " + v1.ToString() + ", < " + v2.ToString()

/// [omit]
let serializePackages strictMode (resolved : PackageResolution) =
let serializePackages options (resolved : PackageResolution) =
let sources =
resolved
|> Seq.map (fun kv ->
Expand All @@ -29,8 +29,8 @@ module LockFileSerializer =

let all =
let hasReported = ref false
[ if strictMode then
yield "REFERENCES: STRICT"
[ if options.Strict then yield "REFERENCES: STRICT"
if options.OmitContent then yield "CONTENT: NONE"
for (source, _), packages in sources do
if not !hasReported then
yield "NUGET"
Expand Down Expand Up @@ -71,16 +71,19 @@ module LockFileParser =
Packages : ResolvedPackage list
SourceFiles : ResolvedSourceFile list
LastWasPackage : bool
Strict: bool }
Options: InstallOptions }

type private InstallOptionCase = StrictCase | OmitContentCase

let private (|Remote|NugetPackage|NugetDependency|SourceFile|RepositoryType|Blank|ReferencesMode|) (state, line:string) =
let private (|Remote|NugetPackage|NugetDependency|SourceFile|RepositoryType|Blank|InstallOption|) (state, line:string) =
match (state.RepositoryType, line.Trim()) with
| _, "NUGET" -> RepositoryType "NUGET"
| _, "GITHUB" -> RepositoryType "GITHUB"
| _, _ when String.IsNullOrWhiteSpace line -> Blank
| _, trimmed when trimmed.StartsWith "remote:" -> Remote(trimmed.Substring(trimmed.IndexOf(": ") + 2).Split(' ').[0])
| _, trimmed when trimmed.StartsWith "specs:" -> Blank
| _, trimmed when trimmed.StartsWith "REFERENCES:" -> ReferencesMode(trimmed.Replace("REFERENCES:","").Trim() = "STRICT")
| _, trimmed when trimmed.StartsWith "REFERENCES:" -> InstallOption(StrictCase,trimmed.Replace("REFERENCES:","").Trim() = "STRICT")
| _, trimmed when trimmed.StartsWith "CONTENT:" -> InstallOption(OmitContentCase,trimmed.Replace("CONTENT:","").Trim() = "NONE")
| _, trimmed when line.StartsWith " " ->
let parts = trimmed.Split '('
NugetDependency (parts.[0].Trim(),parts.[1].Replace("(", "").Replace(")", "").Trim())
Expand All @@ -92,12 +95,13 @@ module LockFileParser =
let Parse(lockFileLines) =
let remove textToRemove (source:string) = source.Replace(textToRemove, "")
let removeBrackets = remove "(" >> remove ")"
({ RepositoryType = None; RemoteUrl = None; Packages = []; SourceFiles = []; Strict = false; LastWasPackage = false }, lockFileLines)
({ RepositoryType = None; RemoteUrl = None; Packages = []; SourceFiles = []; Options = InstallOptions.Default; LastWasPackage = false }, lockFileLines)
||> Seq.fold(fun state line ->
match (state, line) with
| Remote(url) -> { state with RemoteUrl = Some url }
| Blank -> state
| ReferencesMode mode -> { state with Strict = mode }
| InstallOption (StrictCase,mode) -> { state with Options = {state.Options with Strict = mode} }
| InstallOption (OmitContentCase,omit) -> { state with Options = {state.Options with OmitContent = omit} }
| RepositoryType repoType -> { state with RepositoryType = Some repoType }
| NugetPackage details ->
match state.RemoteUrl with
Expand Down Expand Up @@ -137,23 +141,23 @@ module LockFileParser =


/// Allows to parse and analyze paket.lock files.
type LockFile(fileName:string,strictMode,resolution:PackageResolution,remoteFiles:ResolvedSourceFile list) =
type LockFile(fileName:string,options,resolution:PackageResolution,remoteFiles:ResolvedSourceFile list) =
member __.SourceFiles = remoteFiles
member __.ResolvedPackages = resolution
member __.FileName = fileName
member __.Strict = strictMode
member __.Options = options

/// Updates the Lock file with the analyzed dependencies from the paket.dependencies file.
member __.Save() =
let output =
String.Join
(Environment.NewLine,
LockFileSerializer.serializePackages strictMode resolution,
LockFileSerializer.serializePackages options resolution,
LockFileSerializer.serializeSourceFiles remoteFiles)
File.WriteAllText(fileName, output)
tracefn "Locked version resolutions written to %s" fileName

/// Parses a paket.lock file from lines
static member LoadFrom(lockFileName) : LockFile =
LockFileParser.Parse(File.ReadAllLines lockFileName)
|> fun state -> LockFile(lockFileName,state.Strict,state.Packages |> Seq.fold (fun map p -> Map.add p.Name p map) Map.empty, List.rev state.SourceFiles)
|> fun state -> LockFile(lockFileName, state.Options ,state.Packages |> Seq.fold (fun map p -> Map.add p.Name p map) Map.empty, List.rev state.SourceFiles)
2 changes: 1 addition & 1 deletion src/Paket/NugetConvert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ let private convertNugetsToDepFile(nugetPackagesConfigs) =
|> Set.toList

let packages = packagesToAdd |> List.map (fun (name,v) -> nugetPackageRequirement(name,v,nugetSources))
DependenciesFile(Constants.DependenciesFile, false, packages, []).Save()
DependenciesFile(Constants.DependenciesFile, InstallOptions.Default, packages, []).Save()
| Some depFile ->
if not (packagesToAdd |> List.isEmpty)
then (packagesToAdd |> List.fold (fun (d : DependenciesFile) (name,version) -> d.Add(name,version)) depFile).Save()
Expand Down
12 changes: 9 additions & 3 deletions src/Paket/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ type ProjectFile =
this.FindPaketNodes("Content")
|> List.map (fun n -> FileInfo(Path.Combine(Path.GetDirectoryName(this.FileName), n.Attributes.["Include"].Value)))

member this.UpdateContentFiles(contentFiles : list<FileInfo>) =
member this.UpdateContentFiles(contentFiles : list<FileInfo>, hard) =
let contentNode (fi: FileInfo) =
this.CreateNode "Content"
|> addAttribute "Include" (createRelativePath this.FileName fi.FullName)
Expand All @@ -249,7 +249,6 @@ type ProjectFile =
match [ for node in this.Document.SelectNodes("//ns:Project", this.Namespaces) -> node ] with
| [] -> ()
| projectNode :: _ ->
this.DeletePaketNodes("Content")
let itemGroupNode = this.Document.CreateElement("ItemGroup", ProjectFile.DefaultNameSpace)

let firstNodeForDirs =
Expand All @@ -268,7 +267,14 @@ type ProjectFile =
|> Seq.cast<XmlNode> |> Seq.firstOrDefault) with
| Some (existingNode) ->
if not <| (existingNode.ChildNodes |> Seq.cast<XmlNode> |> Seq.exists (fun n -> n.Name = "Paket"))
then existingNode :?> XmlElement |> addChild (this.CreateNode("Paket", "True")) |> ignore
then
if hard
then existingNode :?> XmlElement |> addChild (this.CreateNode("Paket", "True")) |> ignore
else
existingNode.ParentNode.InsertBefore(paketNode, existingNode) |> ignore
traceWarnfn "Duplicated content file '%s for project %s"
existingNode.Attributes.["Include"].Value
this.FileName
| None -> firstNodeForDir.ParentNode.InsertBefore(paketNode, firstNodeForDir) |> ignore

| None -> itemGroupNode.AppendChild(paketNode) |> ignore )
Expand Down
6 changes: 3 additions & 3 deletions src/Paket/Simplifier.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ let Analyze(allPackages : list<ResolvedPackage>, depFile : DependenciesFile, ref
allDeps |> List.filter (fun dep -> not <| Set.contains ((depNameFun dep).ToLower()) depsToRemove)

let simplifiedDeps = depFile.Packages |> getSimplifiedDeps (fun p -> p.Name) depFile.FileName |> Seq.toList
let refFiles' = if depFile.Strict
let refFiles' = if depFile.Options.Strict
then refFiles
else refFiles |> List.map (fun refFile -> {refFile with NugetPackages =
refFile.NugetPackages |> getSimplifiedDeps id refFile.FileName})

DependenciesFile(depFile.FileName, depFile.Strict, simplifiedDeps, depFile.RemoteFiles), refFiles'
DependenciesFile(depFile.FileName, depFile.Options, simplifiedDeps, depFile.RemoteFiles), refFiles'

let Simplify (interactive, dependenciesFileName) =
if not <| File.Exists(dependenciesFileName) then
Expand All @@ -72,7 +72,7 @@ let Simplify (interactive, dependenciesFileName) =
printfn ""
simplify depFile.FileName <| depFile.ToString() <| simplifiedDepFile.ToString()

if depFile.Strict then
if depFile.Options.Strict then
traceWarn ("Strict mode detected. Will not attempt to simplify " + Constants.ReferencesFile + " files.")
else
for refFile in simplifiedRefFiles do
Expand Down
2 changes: 1 addition & 1 deletion src/Paket/UpdateProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let Update(dependenciesFileName, forceResolution, force, hard) =
let resolution = dependenciesFile.Resolve force
let lockFile =
LockFile
(lockFileName.FullName, dependenciesFile.Strict, resolution.ResolvedPackages.GetModelOrFail(),
(lockFileName.FullName, dependenciesFile.Options, resolution.ResolvedPackages.GetModelOrFail(),
resolution.ResolvedSourceFiles)
lockFile.Save()
dependenciesFile.Sources, lockFile
Expand Down
Loading