Skip to content

Commit b0b0064

Browse files
author
Stewart Miles
committed
Fixed Version Control compatibility with Unity 2019.1+
Fixes #262 Bug: 138441374 Change-Id: I261628d816de2d5f11bf105253a36f88ec7de3df
1 parent 22679a9 commit b0b0064

File tree

5 files changed

+52
-29
lines changed

5 files changed

+52
-29
lines changed

source/PlayServicesResolver/src/GradleTemplateResolver.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,10 @@ public static bool InjectDependencies(ICollection<Dependency> dependencies) {
326326
}
327327
outputLines.AddRange(currentOutputLines);
328328
}
329-
if (!FileUtils.CheckoutFile(GradleTemplatePath))
330-
{
329+
if (!FileUtils.CheckoutFile(GradleTemplatePath, PlayServicesResolver.logger)) {
331330
PlayServicesResolver.Log(
332-
String.Format("Unable to checkou '{0}'.", GradleTemplatePath), level: LogLevel.Error);
331+
String.Format("Failed to checkout '{0}', unable to patch the file.",
332+
GradleTemplatePath), level: LogLevel.Error);
333333
return false;
334334
}
335335
PlayServicesResolver.Log(

source/PlayServicesResolver/src/LocalMavenRepository.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ public static bool PatchPomFile(string artifactFilename) {
129129
updatedPackaging = true;
130130
}
131131
}
132-
if (!FileUtils.CheckoutFile(pomFilename))
133-
{
134-
PlayServicesResolver.Log(String.Format("Unable to checkout '{0}'.", pomFilename), LogLevel.Error);
132+
if (!FileUtils.CheckoutFile(pomFilename, PlayServicesResolver.logger)) {
133+
PlayServicesResolver.Log(
134+
String.Format("Unable to checkout '{0}' to patch the file for inclusion in a " +
135+
"Gradle project.", pomFilename), LogLevel.Error);
135136
return false;
136137
}
137138
if (updatedPackaging) {

source/PlayServicesResolver/src/PlayServicesResolver.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ private static IEnumerable<string> SortSet(IEnumerable<string> setToSort) {
9797
public void WriteToFile() {
9898
try {
9999
Directory.CreateDirectory(Path.GetDirectoryName(DEPENDENCY_STATE_FILE));
100-
if (!FileUtils.CheckoutFile(DEPENDENCY_STATE_FILE))
101-
{
102-
logger.Log(
103-
String.Format("Unable to checkout '{0}'. Dependency state has not been saved!",
104-
DEPENDENCY_STATE_FILE), LogLevel.Error);
100+
if (!FileUtils.CheckoutFile(DEPENDENCY_STATE_FILE, logger)) {
101+
logger.Log(String.Format(
102+
"Unable to checkout '{0}'. Resolution results can't be saved, " +
103+
"disabling auto-resolution.", DEPENDENCY_STATE_FILE), LogLevel.Error);
104+
SettingsDialogObj.EnableAutoResolution = false;
105105
return;
106106
}
107107
using (var writer = new XmlTextWriter(new StreamWriter(DEPENDENCY_STATE_FILE)) {

source/VersionHandlerImpl/src/FileUtils.cs

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -293,21 +293,44 @@ public static string FindDirectoryByCaseInsensitivePath(string pathToFind) {
293293
/// Checks out a file should Version Control be active and valid.
294294
/// </summary>
295295
/// <param name="path">Path to the file that needs checking out.</param>
296+
/// <param name="logger">Logger, used to log any error messages.</param>
296297
/// <returns>False should the checkout fail, otherwise true.</returns>
297-
public static bool CheckoutFile(string path)
298-
{
299-
if (UnityEditor.VersionControl.Provider.enabled && UnityEditor.VersionControl.Provider.isActive &&
300-
(!UnityEditor.VersionControl.Provider.requiresNetwork ||
301-
UnityEditor.VersionControl.Provider.onlineState == UnityEditor.VersionControl.OnlineState.Online))
302-
{
303-
var task = UnityEditor.VersionControl.Provider.Checkout(path,
304-
UnityEditor.VersionControl.CheckoutMode.Exact);
305-
task.Wait();
306-
if (!task.success)
307-
return false;
298+
public static bool CheckoutFile(string path, Logger logger) {
299+
try {
300+
if (UnityEditor.VersionControl.Provider.enabled &&
301+
UnityEditor.VersionControl.Provider.isActive &&
302+
(!UnityEditor.VersionControl.Provider.requiresNetwork ||
303+
UnityEditor.VersionControl.Provider.onlineState ==
304+
UnityEditor.VersionControl.OnlineState.Online)) {
305+
// Unity 2019.1+ broke backwards compatibility of Checkout() by adding an
306+
// optional argument to the method so we dynamically invoke the method to add
307+
// the optional
308+
// argument for the Unity 2019.1+ overload at runtime.
309+
var task = (UnityEditor.VersionControl.Task)VersionHandler.InvokeStaticMethod(
310+
typeof(UnityEditor.VersionControl.Provider),
311+
"Checkout",
312+
new object[] { path, UnityEditor.VersionControl.CheckoutMode.Exact },
313+
namedArgs: null);
314+
task.Wait();
315+
if (!task.success) {
316+
var errorMessage = new List<string>();
317+
errorMessage.Add(String.Format("Failed to checkout {0}.", path));
318+
if (task.messages != null) {
319+
foreach (var message in task.messages) {
320+
if (message != null) errorMessage.Add(message.message);
321+
}
322+
}
323+
logger.Log(String.Join("\n", errorMessage.ToArray()),
324+
level: LogLevel.Warning);
325+
return false;
326+
}
327+
}
328+
return true;
329+
} catch (Exception ex) {
330+
logger.Log(String.Format("Failed to checkout {0} ({1}.", path, ex),
331+
level: LogLevel.Warning);
332+
return false;
308333
}
309-
310-
return true;
311334
}
312335
}
313336
}

source/VersionHandlerImpl/src/ProjectSettings.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,10 @@ private static void Save() {
406406
return;
407407
}
408408
Directory.CreateDirectory(Path.GetDirectoryName(PROJECT_SETTINGS_FILE));
409-
if (!FileUtils.CheckoutFile(PROJECT_SETTINGS_FILE))
410-
{
409+
if (!FileUtils.CheckoutFile(PROJECT_SETTINGS_FILE, logger)) {
411410
logger.Log(
412-
String.Format("Unable to checkout '{0}'. Project settings have not been saved!",
413-
PROJECT_SETTINGS_FILE), LogLevel.Error);
411+
String.Format("Unable to checkout '{0}'. Project settings were not saved!",
412+
PROJECT_SETTINGS_FILE), LogLevel.Error);
414413
return;
415414
}
416415
using (var writer = new XmlTextWriter(new StreamWriter(PROJECT_SETTINGS_FILE)) {
@@ -430,4 +429,4 @@ private static void Save() {
430429
}
431430
}
432431
}
433-
}
432+
}

0 commit comments

Comments
 (0)