/// <summary> /// Saves the napack attributions file by parsing all the licenses of the specified napacks. /// </summary> internal static void SaveNapackAttributionsFile(string projectDirectory, Dictionary <string, NapackVersion> allNapackVersions) { const int lineLength = 70; StringBuilder fileBuilder = new StringBuilder(); fileBuilder.AppendLine("======================== Napack Attributions ========================"); foreach (KeyValuePair <string, NapackVersion> napack in allNapackVersions) { string napackVersionNameStart = napack.Key + "." + napack.Value.Major + " License Start "; fileBuilder.Append(napackVersionNameStart); fileBuilder.Append('=', Math.Max(10, lineLength - napackVersionNameStart.Length)); fileBuilder.AppendLine(); fileBuilder.AppendLine(); NapackAttributions.AppendNapackLicense(napack.Value.Authors, napack.Value.License, fileBuilder); fileBuilder.AppendLine(); fileBuilder.AppendLine(); string napackVersionNameEnd = napack.Key + "." + napack.Value.Major + " License End "; fileBuilder.Append(napackVersionNameEnd); fileBuilder.Append('=', Math.Max(10, lineLength - napackVersionNameEnd.Length)); fileBuilder.AppendLine(); } fileBuilder.AppendLine("====================================================================="); File.WriteAllText(Path.Combine(projectDirectory, NapackAttributions.NapackAttributionsFileName), fileBuilder.ToString()); }
public void PerformOperation() { // The specified napacks. NapackClient.Log("Reading in the Napacks JSON file..."); Dictionary <string, string> rawNapacks = Serializer.Deserialize <Dictionary <string, string> >(File.ReadAllText(this.NapacksFile)); List <NapackVersionIdentifier> listedNapacks = rawNapacks.Select(item => new NapackVersionIdentifier(item.Key + "." + item.Value)).ToList(); // The specified napacks, plus those dependencies. This doesn't have to exist -- we'll detect everything as unused if it doesn't and clear the napack folder. Dictionary <string, List <NapackVersion> > knownNapacks = new Dictionary <string, List <NapackVersion> >(); try { knownNapacks = Serializer.Deserialize <Dictionary <string, List <NapackVersion> > >(File.ReadAllText(this.NapacksFile + UpdateOperation.LockFileSuffix)); } catch (Exception) { NapackClient.Log("Didn't find the napack lock file; packages may be redownloaded."); } NapackClient.Log("Reading in the Napack Settings JSON file..."); NapackClientSettings settings = Serializer.Deserialize <NapackClientSettings>(File.ReadAllText(this.NapackSettingsFile)); // Now that we've read in everything, start processing. knownNapacks = this.RemoveUnusedNapacks(knownNapacks); using (NapackServerClient client = new NapackServerClient(settings.NapackFrameworkServer)) { this.AcquireNapacks(client, listedNapacks, knownNapacks); } // Save the lock file now that we're in an updated state. foreach (NapackVersion knownNapack in knownNapacks.Values.SelectMany(value => value)) { // Clear the files so we aren't duplicating them in the lock file. knownNapack.Files.Clear(); } File.WriteAllText(this.NapacksFile + UpdateOperation.LockFileSuffix, Serializer.Serialize(knownNapacks)); // Extract out our version identifiers List <NapackVersionIdentifier> napackVersionIdentifiers = new List <NapackVersionIdentifier>(); Dictionary <string, NapackVersion> allNapackVersions = new Dictionary <string, NapackVersion>(); foreach (KeyValuePair <string, List <NapackVersion> > napackVersions in knownNapacks) { foreach (NapackVersion napackVersion in napackVersions.Value) { napackVersionIdentifiers.Add(new NapackVersionIdentifier(napackVersions.Key, napackVersion.Major, napackVersion.Minor, napackVersion.Patch)); allNapackVersions.Add(napackVersions.Key, napackVersion); } } NapackTargets.SaveNapackTargetsFile(this.ProjectDirectory, this.NapackDirectory, napackVersionIdentifiers); NapackAttributions.SaveNapackAttributionsFile(this.ProjectDirectory, allNapackVersions); }