release: 1.4.15

This commit is contained in:
2026-06-10 21:52:43 +08:00
parent f0a21e33ec
commit f1084a5db9
5 changed files with 280 additions and 48 deletions

View File

@@ -13,10 +13,13 @@ namespace Topon_Adapter.Editor
{
private const string Tag = "[TopOn Build]";
private const string DebuggerDependency = "com.anythink.sdk:debugger-ui:+";
private const string VerbtoDependency = "com.verbto.tools:util:1.1.3";
private const string DebuggerDependencyMarker = "com.anythink.sdk:debugger-ui";
private const string VerbtoDependencyMarker = "com.verbto.tools:util";
private const string DebuggerRepositoryUrl = "https://jfrog.anythinktech.com/artifactory/debugger";
private const string DepsStart = "// TopOn Debugger UI Dependencies Start";
private const string DepsEnd = "// TopOn Debugger UI Dependencies End";
private const string VerbtoDepsStart = "// TopOn Verbto Util Dependency Start";
private const string VerbtoDepsEnd = "// TopOn Verbto Util Dependency End";
private const string ReposStart = "// TopOn Debugger UI Repository Start";
private const string ReposEnd = "// TopOn Debugger UI Repository End";
@@ -49,19 +52,25 @@ namespace Topon_Adapter.Editor
Path.Combine(gradleRoot, "launcher", "build.gradle"),
Path.Combine(gradleRoot, "build.gradle")
};
var forceVerbtoUtilVersion = settings.forceVerbtoUtilVersion;
var verbtoDependency = ToponBuildSettingsStore.GetVerbtoUtilDependency(settings);
foreach (var gradleFile in gradleFiles)
{
StripDebuggerFromGradleFile(gradleFile);
StripManagedDependenciesFromGradleFile(gradleFile, forceVerbtoUtilVersion);
}
StripDebuggerFromGradleFile(Path.Combine(gradleRoot, "settings.gradle"));
StripManagedDependenciesFromGradleFile(Path.Combine(gradleRoot, "settings.gradle"), forceVerbtoUtilVersion);
if (settings.enableDebuggerUI)
if (settings.enableDebuggerUI || forceVerbtoUtilVersion)
{
InjectRepository(Path.Combine(gradleRoot, "settings.gradle"));
InjectRepository(Path.Combine(gradleRoot, "build.gradle"));
InjectDependencies(Path.Combine(path, "build.gradle"), settings.forceVerbtoUtilVersion);
}
if (settings.enableDebuggerUI)
{
InjectDebuggerDependency(Path.Combine(path, "build.gradle"));
Debug.Log($"{Tag} DebugUI dependency enabled for this build.");
}
else
@@ -73,6 +82,17 @@ namespace Topon_Adapter.Editor
Debug.Log($"{Tag} DebugUI dependency disabled for this build.");
}
if (forceVerbtoUtilVersion)
{
InjectVerbtoUtilDependency(Path.Combine(path, "build.gradle"), verbtoDependency);
RemoveGeneratedStaleVerbtoUtilArtifacts(gradleRoot, verbtoDependency);
Debug.Log($"{Tag} Verbto util dependency forced to {verbtoDependency}.");
}
else
{
Debug.Log($"{Tag} Verbto util dependency is not modified by TopOn build settings.");
}
}
private static string GetGradleRoot(string unityLibraryPath)
@@ -84,7 +104,7 @@ namespace Topon_Adapter.Editor
#endif
}
private static void StripDebuggerFromGradleFile(string filePath)
private static void StripManagedDependenciesFromGradleFile(string filePath, bool forceVerbtoUtilVersion)
{
if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
{
@@ -94,9 +114,13 @@ namespace Topon_Adapter.Editor
var content = File.ReadAllText(filePath);
var original = content;
content = RemoveMarkedBlock(content, DepsStart, DepsEnd);
content = RemoveMarkedBlock(content, VerbtoDepsStart, VerbtoDepsEnd);
content = RemoveMarkedBlock(content, ReposStart, ReposEnd);
content = RemoveDebuggerRepositoryBlocks(content);
content = RemoveLinesContaining(content, "com.anythink.sdk:debugger-ui", "com.verbto.tools:util");
content = RemoveLinesContaining(content, DebuggerDependencyMarker);
if (forceVerbtoUtilVersion)
{
content = RemoveLinesContaining(content, VerbtoDependencyMarker);
}
if (!string.Equals(original, content, StringComparison.Ordinal))
{
@@ -104,7 +128,17 @@ namespace Topon_Adapter.Editor
}
}
private static void InjectDependencies(string buildGradlePath, bool forceVerbtoUtilVersion)
private static void InjectDebuggerDependency(string buildGradlePath)
{
InjectDependencyBlock(buildGradlePath, DepsStart, DepsEnd, DebuggerDependency);
}
private static void InjectVerbtoUtilDependency(string buildGradlePath, string dependency)
{
InjectDependencyBlock(buildGradlePath, VerbtoDepsStart, VerbtoDepsEnd, dependency);
}
private static void InjectDependencyBlock(string buildGradlePath, string startMarker, string endMarker, string dependency)
{
if (!File.Exists(buildGradlePath))
{
@@ -112,16 +146,17 @@ namespace Topon_Adapter.Editor
return;
}
var content = File.ReadAllText(buildGradlePath);
var block = new StringBuilder();
block.AppendLine(DepsStart);
block.AppendLine($" implementation '{DebuggerDependency}'");
if (forceVerbtoUtilVersion)
if (string.IsNullOrWhiteSpace(dependency))
{
block.AppendLine($" implementation '{VerbtoDependency}'");
Debug.LogWarning($"{Tag} dependency is empty, skip injecting {startMarker}.");
return;
}
block.AppendLine($" {DepsEnd}");
var content = File.ReadAllText(buildGradlePath);
var block = new StringBuilder();
block.AppendLine(startMarker);
block.AppendLine($" implementation '{dependency.Trim()}'");
block.AppendLine($" {endMarker}");
var pattern = new Regex(@"(dependencies\s*\{)");
if (!pattern.IsMatch(content))
@@ -142,6 +177,11 @@ namespace Topon_Adapter.Editor
}
var content = File.ReadAllText(gradlePath);
if (content.Contains(DebuggerRepositoryUrl))
{
return;
}
var block = $"{ReposStart}\n maven {{ url '{DebuggerRepositoryUrl}' }}\n {ReposEnd}";
Regex pattern;
if (Path.GetFileName(gradlePath).Equals("settings.gradle", StringComparison.OrdinalIgnoreCase))
@@ -196,26 +236,47 @@ namespace Topon_Adapter.Editor
}
}
private static void RemoveGeneratedStaleVerbtoUtilArtifacts(string gradleRoot, string expectedDependency)
{
if (string.IsNullOrWhiteSpace(gradleRoot) || !Directory.Exists(gradleRoot))
{
return;
}
var root = Path.GetFullPath(gradleRoot).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
foreach (var path in Directory.GetFiles(root, "*", SearchOption.AllDirectories))
{
var fileName = Path.GetFileName(path);
if (!ToponBuildSettingsStore.IsVerbtoUtilArtifactFileName(fileName) ||
ToponBuildSettingsStore.IsExpectedVerbtoUtilArtifactFileName(fileName, expectedDependency))
{
continue;
}
var fullPath = Path.GetFullPath(path);
if (!fullPath.StartsWith(root, StringComparison.OrdinalIgnoreCase))
{
continue;
}
try
{
File.Delete(fullPath);
Debug.Log($"{Tag} Removed stale verbto util artifact: {fullPath}");
}
catch (Exception exception)
{
Debug.LogWarning($"{Tag} Failed to remove stale verbto util artifact: {exception.Message}");
}
}
}
private static string RemoveMarkedBlock(string content, string startMarker, string endMarker)
{
var pattern = new Regex($@"\s*{Regex.Escape(startMarker)}[\s\S]*?{Regex.Escape(endMarker)}\s*");
return pattern.Replace(content, "\n");
}
private static string RemoveDebuggerRepositoryBlocks(string content)
{
var escapedUrl = Regex.Escape(DebuggerRepositoryUrl);
content = Regex.Replace(
content,
$@"\r?\n\s*maven\s*\{{\s*url\s*['""]{escapedUrl}['""][^\r\n]*\s*\}}",
string.Empty);
content = Regex.Replace(
content,
$@"\r?\n\s*maven\s*\{{\s*\r?\n\s*url\s*['""]{escapedUrl}['""][^\r\n]*\r?\n\s*\}}",
string.Empty);
return content;
}
private static string RemoveLinesContaining(string content, params string[] markers)
{
var lines = content.Replace("\r\n", "\n").Replace('\r', '\n').Split('\n');