/// <summary> /// Check if the mapping for the regex match is valid /// </summary> /// <param name="mapping">The class, field or method mapping from the database</param> /// <param name="match">The regex match for the keyword</param> /// <param name="failedMappings">The list to insert failed mappings into</param> /// <returns></returns> private static string CheckMatch(Mapping mapping, Capture match, List <string> failedMappings = null) { if (mapping != null) { Lumberjack.Log($"{match.Value}\t-> {mapping.GetMappingString()}"); return(mapping.MappedShortName); } Lumberjack.Warn($"{match.Value}\t-> ??? (No mapping)"); failedMappings?.Add(match.Value); return(match.Value); }
private static void LoadRemoteMappings(MappingDatabase mappingDatabase, string version) { Lumberjack.Log("Fetching mapping versions from remote..."); var yarnVersions = YarnUtil.GetYarnVersions(); if (yarnVersions == null) { // If we couldn't get them, try to use the ones we've already cached Lumberjack.Warn("Working in offline mode. Only local Yarn mappings will be available."); yarnVersions = mappingDatabase.GetYarnVersions(); } if (yarnVersions.All(mapping => mapping.Version != version)) { // If a specific mapping version was specified that doesn't exist in the version listing, fail Lumberjack.Error($"Could not find mapping version {version}!"); return; } var mappingVersion = yarnVersions.First(mapping => mapping.Version == version); if (!mappingDatabase.HasMappingSet(mappingVersion)) { // If we don't have those mappings cached, download them and cache them Lumberjack.Log("Fetching mappings from remote..."); var mappings = YarnUtil.GetYarnMappings(mappingVersion); if (mappings != null) { Lumberjack.Log("Updating database..."); mappingDatabase.CreateMappingSet(mappingVersion, mappings); } else { Lumberjack.Error($"Failed to load requested mappings {mappingVersion.Version}"); Environment.Exit((int)ExitConditions.MappingVersionNotFound); } } else { Lumberjack.Log("Local database contains required mappings."); } InteractiveMapper.SetYarnVersion(mappingVersion); Lumberjack.Log($"Using mappings from yarn {version}"); }
public void Update() { if (_worker is null) { _worker = new Thread(() => { while (true) { while (!_bgJobs.IsEmpty) { if (!_bgJobs.TryDequeue(out var job)) { Lumberjack.Warn("Unable to dequeue BG job"); return; } job.Execute(this); } _workerHandle.Reset(); _workerHandle.WaitOne(); } }); _worker.Start(); } while (!_fgJobs.IsEmpty) { if (!_fgJobs.TryDequeue(out var job)) { Lumberjack.Warn("Unable to dequeue FG job"); return; } job.Execute(this); Application.DoEvents(); } _perfGraphFps.UpdateGraph((float)_window.RenderTime); }
/// <summary> /// Iterates over the files in an archive and maps the intermediary names in the java files /// </summary> /// <param name="mappingSource">The mapping provider</param> /// <param name="srcArchive">The archive to iterate through</param> /// <param name="destDir">The destination for the mapped files</param> public static void MapArchive(IMappingSource mappingSource, string srcArchive, string destDir) { // Keep the failed mappings to create a report at the end var failedMappings = new List <string>(); destDir = Path.Combine(Program.BaseDirOutput, destDir); using (var srcZip = ZipFile.OpenRead(srcArchive)) { foreach (var srcEntry in srcZip.Entries) { // Directories are entries too, skip them if (srcEntry.FullName.EndsWith("/")) { continue; } var destFile = $"{destDir}/{srcEntry.FullName}"; var fileDir = Path.GetDirectoryName(destFile); Debug.Assert(fileDir != null); // Make sure the output directory structure exists Directory.CreateDirectory(fileDir); if (Path.GetExtension(srcEntry.Name) == ".java") { // Read and map java files Lumberjack.Log(srcEntry.FullName); string file; using (var reader = new StreamReader(srcEntry.Open())) file = reader.ReadToEnd(); Lumberjack.PushIndent(); var mappedContents = MapString(mappingSource, file, failedMappings); File.WriteAllBytes(destFile, Encoding.UTF8.GetBytes((string)mappedContents)); Lumberjack.PopIndent(); } else { // Copy all files directly that aren't java files using (var reader = srcEntry.Open()) using (var writer = File.Open(destFile, FileMode.Create)) reader.CopyTo(writer); } } } // Report all of the failed mappings if (failedMappings.Count > 0) { Lumberjack.Warn("Failed mappings:"); Lumberjack.PushIndent(); Lumberjack.PushCategory("Failed"); foreach (var failedMapping in failedMappings) { Lumberjack.Warn(failedMapping); } Lumberjack.PopCategory(); Lumberjack.PopIndent(); } else { Lumberjack.Log("No failed mappings"); } }