Skip to content

Commit

Permalink
Instance refac pt2
Browse files Browse the repository at this point in the history
  • Loading branch information
richardelms committed Nov 22, 2024
1 parent ad2999a commit 74d4eed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 40 deletions.
54 changes: 18 additions & 36 deletions Bugsnag/Assets/Bugsnag/Editor/SymbolUpload/BugsnagCLI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,19 @@ internal class BugsnagCLI
private readonly string _cliExecutablePath;
public BugsnagCLI()
{
try
var config = BugsnagSettingsObject.GetSettingsObject();

if (string.IsNullOrEmpty(config.BugsnagCLIExecutablePath))
{
var config = BugsnagSettingsObject.GetSettingsObject();
if (config == null)
{
return;
}
if (string.IsNullOrEmpty(config.BugsnagCLIExecutablePath))
{
_cliExecutablePath = GetBugsnagCLI();
}
else
{
_cliExecutablePath = config.BugsnagCLIExecutablePath;
}
if (!File.Exists(_cliExecutablePath))
{
throw new Exception($"BugSnag CLI not found at expected path: {_cliExecutablePath}");
}
_cliExecutablePath = DownloadBugsnagCLI();
}
else
{
_cliExecutablePath = config.BugsnagCLIExecutablePath;
}
catch (Exception ex)
if (!File.Exists(_cliExecutablePath))
{
UnityEngine.Debug.LogError($"Failed to setup Bugsnag CLI: {ex.Message}");
throw new Exception($"BugSnag CLI not found at path: {_cliExecutablePath}");
}
}

Expand All @@ -57,24 +47,16 @@ public void UploadAndroidSymbols(string buildOutputPath, string apiKey, string v
}
}

public string GetBugsnagCLI()
public string DownloadBugsnagCLI()
{
try
EnsureDirectoryExists();
if (File.Exists(DOWNLOADED_CLI_PATH) && GetCurrentCliVersion() == DOWNLOADED_CLI_VERSION)
{
EnsureDirectoryExists();
if (File.Exists(DOWNLOADED_CLI_PATH) && GetCurrentCliVersion() == DOWNLOADED_CLI_VERSION)
{
return DOWNLOADED_CLI_PATH;
}
DownloadCLI();
MakeExecutable();
return DOWNLOADED_CLI_PATH;
}
catch (Exception ex)
{
UnityEngine.Debug.LogError($"Failed to setup Bugsnag CLI: {ex.Message}");
return null;
}
DownloadCLI();
MakeExecutable();
return DOWNLOADED_CLI_PATH;
}

private void EnsureDirectoryExists()
Expand Down Expand Up @@ -153,7 +135,7 @@ private void MakeExecutable()
int exitCode = StartProcess("chmod", $"+x {DOWNLOADED_CLI_PATH}", out _, out _);
if(exitCode != 0)
{
throw new InvalidOperationException("Failed to make CLI executable");
throw new InvalidOperationException("Failed to make BugSnag CLI executable");
}
}
}
Expand All @@ -162,7 +144,7 @@ private string GetCurrentCliVersion()
{
if (!File.Exists(DOWNLOADED_CLI_PATH))
{
UnityEngine.Debug.LogError($"Bugsnag CLI not found at {DOWNLOADED_CLI_PATH}");
UnityEngine.Debug.LogError($"BugSnag CLI not found at {DOWNLOADED_CLI_PATH}");
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ public void OnPostprocessBuild(BuildReport report)

if (report.summary.platform == BuildTarget.Android)
{
EditorUtility.DisplayProgressBar("Bugsnag Symbol Upload", "Uploading Android symbol files", 0.0f);
EditorUtility.DisplayProgressBar("BugSnag Symbol Upload", "Uploading Android symbol files", 0.0f);
try
{
UploadAndroidSymbols(buildOutputPath, config.ApiKey, config.AppVersion, config.VersionCode);
}
catch (System.Exception e)
{
UnityEngine.Debug.LogError($"Failed to upload Android symbol files to Bugsnag: {e.Message}");
UnityEngine.Debug.LogError($"Failed to upload Android symbol files to BugSnag. Error: {e.Message}");
}
EditorUtility.ClearProgressBar();
}
else if (report.summary.platform == BuildTarget.iOS)
{
//TODO implement iOS symbol upload
//TODO implement iOS post build script generation
}
else if (report.summary.platform == BuildTarget.StandaloneOSX)
{
// TODO implement macOS symbol upload
// TODO implement macOS post build script generation
}

}
Expand Down

0 comments on commit 74d4eed

Please sign in to comment.