Class BugReportBundle

java.lang.Object
megamek.common.util.BugReportBundle

public class BugReportBundle extends Object
Collects the files a MegaMek bug report needs and writes them into a single zip archive that the player can attach to a GitHub issue.

The file list is a deliberate manifest rather than a directory scan. MegaMek's log directory also accumulates one gamelog*.html combat report per game and a Bot_*.mul unit list per bot per game, so a working installation can hold hundreds of megabytes there. Sweeping the directory wholesale would produce an archive far too large to attach, while a naive *.log filter would miss the combat report, which is usually the single most useful artifact in a MegaMek bug report.

The archive is capped at MAX_ARCHIVE_BYTES. Candidates are added in priority order and any that would push the total past the cap are skipped and named in the returned BugReportBundle.BundleResult, so the caller can tell the player exactly what was left out instead of silently truncating.

This class deliberately has no Swing or game-state dependencies so that it can be exercised headlessly.

See Also:
  • Field Details

    • MAX_ARCHIVE_BYTES

      public static final long MAX_ARCHIVE_BYTES
      GitHub refuses issue attachments larger than 25 MB, whatever the file type.
      See Also:
    • SYSTEM_INFO_ENTRY_NAME

      public static final String SYSTEM_INFO_ENTRY_NAME
      The archive entry holding the version, OS and Java details.
      See Also:
  • Constructor Details

    • BugReportBundle

      public BugReportBundle(File logDirectory, @Nullable File saveGameFile, String systemInformation, @Nullable String gameLogFileName)
      Creates a bundle description. Nothing is read from disk until writeTo(File) is called.
      Parameters:
      logDirectory - the directory holding MegaMek's logs; read from ClientPreferences.getLogDirectory() rather than assumed, because players can relocate it. A directory that does not exist is tolerated and yields a logs-free archive.
      saveGameFile - the saved game to place at the archive root, or null when no game was running (the main-menu and startup-crash cases)
      systemInformation - the version, OS and Java details to write to "system-info.txt"
      gameLogFileName - the configured combat-report filename, normally gamelog.html, used to find the newest matching report; or null to collect no combat report
  • Method Details

    • writeTo

      public BugReportBundle.BundleResult writeTo(File archiveFile) throws IOException
      Writes the archive, adding candidates in priority order until the size cap is reached.

      Reaching the cap is not an error: remaining candidates are recorded as skipped and the archive is still completed, because a partial bundle is far more useful to a maintainer than none.

      Parameters:
      archiveFile - the zip file to create, overwriting any existing file at that path
      Returns:
      a description of what was written
      Throws:
      IOException - if the archive itself cannot be created or written