-
-
Notifications
You must be signed in to change notification settings - Fork 56
fix: Prevent appending uploadTask
more than once
#2300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
ca19697
f45b2ef
8037577
b149120
dd16024
92828fe
0bf7dbc
b2e5c6c
d34d0db
80e7272
f63e0fc
7e784eb
d21434d
6f56182
73437cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
@@ -30,8 +31,8 @@ internal class DebugSymbolUpload | |
private readonly List<string> _symbolUploadPaths; | ||
private readonly string _mappingFilePath; | ||
|
||
private const string SymbolUploadTaskStartComment = "// Autogenerated Sentry symbol upload task [start]"; | ||
private const string SymbolUploadTaskEndComment = "// Autogenerated Sentry symbol upload task [end]"; | ||
internal const string SymbolUploadTaskStartComment = "// Autogenerated Sentry symbol upload task [start]"; | ||
internal const string SymbolUploadTaskEndComment = "// Autogenerated Sentry symbol upload task [end]"; | ||
private const string SentryCliMarker = "SENTRY_CLI"; | ||
private const string UploadArgsMarker = "UPLOAD_ARGS"; | ||
private const string ProguardArgsMarker = "PROGUARD_ARGS"; | ||
|
@@ -102,8 +103,6 @@ public DebugSymbolUpload(IDiagnosticLogger logger, | |
|
||
public void AppendUploadToGradleFile(string sentryCliPath) | ||
{ | ||
RemoveUploadFromGradleFile(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This now happens outside and before calling this method. Added a sanity check before actually writing to disk. |
||
|
||
_logger.LogInfo("Appending debug symbols upload task to gradle file."); | ||
|
||
sentryCliPath = ConvertSlashes(sentryCliPath); | ||
|
@@ -162,10 +161,17 @@ public void AppendUploadToGradleFile(string sentryCliPath) | |
symbolUploadText = symbolUploadText.Replace(UploadArgsMarker, uploadDifArguments); | ||
symbolUploadText = symbolUploadText.Replace(ProguardArgsMarker, uploadProguardArguments); | ||
|
||
using var streamWriter = File.AppendText(_gradleScriptPath); | ||
streamWriter.WriteLine(SymbolUploadTaskStartComment); | ||
streamWriter.WriteLine(symbolUploadText); | ||
streamWriter.WriteLine(SymbolUploadTaskEndComment); | ||
var gradleBuildFile = LoadGradleScript(); | ||
if (gradleBuildFile.Contains("task sentryUploadSymbols")) | ||
|
||
{ | ||
throw new InvalidOperationException("Failed to create Debug Symbol Upload Task. Task already exists in gradle file. Consider creating a clean build."); | ||
} | ||
|
||
var stringBuilder = new StringBuilder(gradleBuildFile); | ||
stringBuilder.AppendLine(SymbolUploadTaskStartComment); | ||
stringBuilder.AppendLine(symbolUploadText); | ||
stringBuilder.AppendLine(SymbolUploadTaskEndComment); | ||
File.WriteAllText(_gradleScriptPath, stringBuilder.ToString()); | ||
} | ||
|
||
private string LoadGradleScript() | ||
|
@@ -182,13 +188,14 @@ public void RemoveUploadFromGradleFile() | |
{ | ||
_logger.LogDebug("Attempting to remove the previous upload task from the gradle project."); | ||
var gradleBuildFile = LoadGradleScript(); | ||
if (!gradleBuildFile.Contains("sentry.properties")) | ||
if (!gradleBuildFile.Contains(SymbolUploadTaskStartComment)) | ||
{ | ||
_logger.LogDebug("No previous upload task found."); | ||
return; | ||
} | ||
|
||
var regex = new Regex(Regex.Escape(SymbolUploadTaskStartComment) + ".*" + Regex.Escape(SymbolUploadTaskEndComment), RegexOptions.Singleline); | ||
var pattern = Regex.Escape(SymbolUploadTaskStartComment) + @"\r?\n.*?\r?\n" + Regex.Escape(SymbolUploadTaskEndComment); | ||
var regex = new Regex(pattern, RegexOptions.Singleline); | ||
bitsandfoxes marked this conversation as resolved.
Show resolved
Hide resolved
bitsandfoxes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
gradleBuildFile = regex.Replace(gradleBuildFile, ""); | ||
|
||
using var streamWriter = File.CreateText(_gradleScriptPath); | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated but: To reduce logging noise when the SDK is disabled.