<commit_before>﻿/// Contains tasks to generate AssemblyInfo files for C# and F#
module Fake.AssemblyInfoFile

/// Represents AssemblyInfo attributes
type Attribute(name,value,inNamespace) =
   member this.Name = name
   member this.Value = value
   member this.Namespace = inNamespace

   /// Creates a simple attribute with string values. Used as base for other attributes
   static member StringAttribute(name,value,inNamespace) = Attribute(name,sprintf "\"%s\"" value,inNamespace)
   /// Creates a simple attribute with boolean values. Used as base for other attributes
   static member BoolAttribute(name,value,inNamespace) = Attribute(name,sprintf "%b" value,inNamespace)

   /// Creates an attribute which holds the company information
   static member Company(value) = Attribute.StringAttribute("AssemblyCompany",value,"System.Reflection")
   /// Creates an attribute which holds the product name
   static member Product(value) = Attribute.StringAttribute("AssemblyProduct",value,"System.Reflection")
   /// Creates an attribute which holds the copyright information
   static member Copyright(value) = Attribute.StringAttribute("AssemblyCopyright",value,"System.Reflection")
   /// Creates an attribute which holds the product title
   static member Title(value) = Attribute.StringAttribute("AssemblyTitle",value,"System.Reflection")
   /// Creates an attribute which holds the product description
   static member Description(value) = Attribute.StringAttribute("AssemblyDescription",value,"System.Reflection")
   /// Creates an attribute which holds the assembly culture information
   static member Culture(value) = Attribute.StringAttribute("AssemblyCulture",value,"System.Reflection")
   /// Creates an attribute which holds the assembly configuration
   static member Configuration(value) = Attribute.StringAttribute("AssemblyConfiguration",value,"System.Reflection")
   /// Creates an attribute which holds the trademark
   static member Trademark(value) = Attribute.StringAttribute("AssemblyTrademark",value,"System.Reflection")
   /// Creates an attribute which holds the assembly version
   static member Version(value) = Attribute.StringAttribute("AssemblyVersion",value,"System.Reflection")
   /// Creates an attribute which holds the assembly key file
   static member KeyFile(value) = Attribute.StringAttribute("AssemblyKeyFile",value,"System.Reflection")
   /// Creates an attribute which holds the assembly key name
   static member KeyName(value) = Attribute.StringAttribute("AssemblyKeyName",value,"System.Reflection")
   /// Creates an attribute which holds the assembly file version
   static member FileVersion(value) = Attribute.StringAttribute("AssemblyFileVersion",value,"System.Reflection")
   /// Creates an attribute which holds an assembly information version
   static member InformationalVersion(value) = Attribute.StringAttribute("AssemblyInformationalVersion",value,"System.Reflection")
   /// Creates an attribute which holds the Guid
   static member Guid(value) = Attribute.StringAttribute("Guid",value,"System.Runtime.InteropServices")
   /// Creates an attribute which specifies if the assembly is visible via COM
   static member ComVisible(?value) = Attribute.BoolAttribute("ComVisible",defaultArg value false,"System.Runtime.InteropServices")
   /// Creates an attribute which specifies if the assembly is CLS compliant
   static member CLSCompliant(?value) = Attribute.BoolAttribute("CLSCompliant",defaultArg value false,"System")
   /// Creates an attribute which specifies if the assembly uses delayed signing
   static member DelaySign(value) = Attribute.BoolAttribute("AssemblyDelaySign",defaultArg value false,"System.Reflection")

let private writeToFile outputFileName (lines: seq<string>) =    
    let fi = fileInfo outputFileName
    fi.Delete()

    use writer = new System.IO.StreamWriter(outputFileName,false,System.Text.Encoding.UTF8) 
    lines |> Seq.iter writer.WriteLine
    tracefn "Created AssemblyInfo file \"%s\"." outputFileName

let private getDependencies attributes =
    attributes
    |> Seq.map (fun (attr:Attribute) -> attr.Namespace)
    |> Set.ofSeq
    |> Seq.toList

let private getAssemblyVersionInfo attributes =
    match attributes |> Seq.tryFind (fun (attr:Attribute) -> attr.Name = "AssemblyVersion") with
    | Some attr -> attr.Value
    | None _ -> "\"" + buildVersion + "\""

/// Creates a C# AssemblyInfo file with the given attributes.
/// The generated AssemblyInfo file contains an AssemblyVersionInformation class which can be used to retrieve the current version no. from inside of an assembly.
let CreateCSharpAssemblyInfo outputFileName attributes =
    traceStartTask "AssemblyInfo" outputFileName

    "// <auto-generated/>" ::
    (getDependencies attributes |> List.map (sprintf "using %s;")) @ [""] @
    (attributes |> Seq.toList |> List.map (fun (attr:Attribute) -> sprintf "[assembly: %sAttribute(%s)]" attr.Name attr.Value)) @
    ["class AssemblyVersionInformation {"
     "    AssemblyVersionInformation() { }"
     sprintf "    public const string Version = %s;" (getAssemblyVersionInfo attributes)
     "}"]
    |> writeToFile outputFileName
    
    traceEndTask "AssemblyInfo" outputFileName

/// Creates a F# AssemblyInfo file with the given attributes.
/// The generated AssemblyInfo file contains an AssemblyVersionInformation class which can be used to retrieve the current version no. from inside of an assembly.
let CreateFSharpAssemblyInfo outputFileName attributes =
    traceStartTask "AssemblyInfo" outputFileName

    ["module internal AssemblyInfo"] @
    (getDependencies attributes |> List.map (sprintf "open %s")) @ [""] @
    (attributes |> Seq.toList |> List.map (fun (attr:Attribute) -> sprintf "[<assembly: %sAttribute(%s)>]" attr.Name attr.Value)) @
    [""
     "()"
     ""
     "type AssemblyVersionInformation() ="
     "    static member Version"
     sprintf "        with get() = %s" (getAssemblyVersionInfo attributes)]
    |> writeToFile outputFileName
<commit_msg>Fix FxCop violations CA1050 and CA1052<commit_after>﻿/// Contains tasks to generate AssemblyInfo files for C# and F#
module Fake.AssemblyInfoFile

/// Represents AssemblyInfo attributes
type Attribute(name,value,inNamespace) =
   member this.Name = name
   member this.Value = value
   member this.Namespace = inNamespace

   /// Creates a simple attribute with string values. Used as base for other attributes
   static member StringAttribute(name,value,inNamespace) = Attribute(name,sprintf "\"%s\"" value,inNamespace)
   /// Creates a simple attribute with boolean values. Used as base for other attributes
   static member BoolAttribute(name,value,inNamespace) = Attribute(name,sprintf "%b" value,inNamespace)

   /// Creates an attribute which holds the company information
   static member Company(value) = Attribute.StringAttribute("AssemblyCompany",value,"System.Reflection")
   /// Creates an attribute which holds the product name
   static member Product(value) = Attribute.StringAttribute("AssemblyProduct",value,"System.Reflection")
   /// Creates an attribute which holds the copyright information
   static member Copyright(value) = Attribute.StringAttribute("AssemblyCopyright",value,"System.Reflection")
   /// Creates an attribute which holds the product title
   static member Title(value) = Attribute.StringAttribute("AssemblyTitle",value,"System.Reflection")
   /// Creates an attribute which holds the product description
   static member Description(value) = Attribute.StringAttribute("AssemblyDescription",value,"System.Reflection")
   /// Creates an attribute which holds the assembly culture information
   static member Culture(value) = Attribute.StringAttribute("AssemblyCulture",value,"System.Reflection")
   /// Creates an attribute which holds the assembly configuration
   static member Configuration(value) = Attribute.StringAttribute("AssemblyConfiguration",value,"System.Reflection")
   /// Creates an attribute which holds the trademark
   static member Trademark(value) = Attribute.StringAttribute("AssemblyTrademark",value,"System.Reflection")
   /// Creates an attribute which holds the assembly version
   static member Version(value) = Attribute.StringAttribute("AssemblyVersion",value,"System.Reflection")
   /// Creates an attribute which holds the assembly key file
   static member KeyFile(value) = Attribute.StringAttribute("AssemblyKeyFile",value,"System.Reflection")
   /// Creates an attribute which holds the assembly key name
   static member KeyName(value) = Attribute.StringAttribute("AssemblyKeyName",value,"System.Reflection")
   /// Creates an attribute which holds the assembly file version
   static member FileVersion(value) = Attribute.StringAttribute("AssemblyFileVersion",value,"System.Reflection")
   /// Creates an attribute which holds an assembly information version
   static member InformationalVersion(value) = Attribute.StringAttribute("AssemblyInformationalVersion",value,"System.Reflection")
   /// Creates an attribute which holds the Guid
   static member Guid(value) = Attribute.StringAttribute("Guid",value,"System.Runtime.InteropServices")
   /// Creates an attribute which specifies if the assembly is visible via COM
   static member ComVisible(?value) = Attribute.BoolAttribute("ComVisible",defaultArg value false,"System.Runtime.InteropServices")
   /// Creates an attribute which specifies if the assembly is CLS compliant
   static member CLSCompliant(?value) = Attribute.BoolAttribute("CLSCompliant",defaultArg value false,"System")
   /// Creates an attribute which specifies if the assembly uses delayed signing
   static member DelaySign(value) = Attribute.BoolAttribute("AssemblyDelaySign",defaultArg value false,"System.Reflection")

let private writeToFile outputFileName (lines: seq<string>) =    
    let fi = fileInfo outputFileName
    fi.Delete()

    use writer = new System.IO.StreamWriter(outputFileName,false,System.Text.Encoding.UTF8) 
    lines |> Seq.iter writer.WriteLine
    tracefn "Created AssemblyInfo file \"%s\"." outputFileName

let private getDependencies attributes =
    attributes
    |> Seq.map (fun (attr:Attribute) -> attr.Namespace)
    |> Set.ofSeq
    |> Seq.toList

let private getAssemblyVersionInfo attributes =
    match attributes |> Seq.tryFind (fun (attr:Attribute) -> attr.Name = "AssemblyVersion") with
    | Some attr -> attr.Value
    | None _ -> "\"" + buildVersion + "\""

/// Creates a C# AssemblyInfo file with the given attributes.
/// The generated AssemblyInfo file contains an AssemblyVersionInformation class which can be used to retrieve the current version no. from inside of an assembly.
let CreateCSharpAssemblyInfo outputFileName attributes =
    traceStartTask "AssemblyInfo" outputFileName

    "// <auto-generated/>" ::
    (getDependencies attributes |> List.map (sprintf "using %s;")) @ [""] @
    (attributes |> Seq.toList |> List.map (fun (attr:Attribute) -> sprintf "[assembly: %sAttribute(%s)]" attr.Name attr.Value)) @
    ["namespace AssemblyInfo {"
     "    internal static class AssemblyVersionInformation {"
     sprintf "        internal const string Version = %s;" (getAssemblyVersionInfo attributes)
     "    }"
     "}"]
    |> writeToFile outputFileName
    
    traceEndTask "AssemblyInfo" outputFileName

/// Creates a F# AssemblyInfo file with the given attributes.
/// The generated AssemblyInfo file contains an AssemblyVersionInformation class which can be used to retrieve the current version no. from inside of an assembly.
let CreateFSharpAssemblyInfo outputFileName attributes =
    traceStartTask "AssemblyInfo" outputFileName

    ["namespace AssemblyInfo"] @
    (getDependencies attributes |> List.map (sprintf "open %s")) @ [""] @
    (attributes |> Seq.toList |> List.map (fun (attr:Attribute) -> sprintf "[<assembly: %sAttribute(%s)>]" attr.Name attr.Value)) @
    [""
     "()"
     ""
     "module internal AssemblyVersionInformation ="
     sprintf "    let [<Literal>] Version = %s" (getAssemblyVersionInfo attributes)]
    |> writeToFile outputFileName

{'fraction_non_alphanumeric': 0.09924487594390508, 'fraction_numerical': 0.0008298066550493735, 'mean_word_length': 4.703738760056791, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5507801', 'n_tokens_mistral': 2883, 'n_tokens_neox': 2828, 'n_words': 972}