From 53d2c142c7d5570668b29db885f2329ed8b4aae5 Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Fri, 17 Oct 2025 05:57:58 -0400 Subject: [PATCH] GP-6005: Improving vsconfig.gradle version sort (Closes #8568) --- GPL/vsconfig.gradle | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/GPL/vsconfig.gradle b/GPL/vsconfig.gradle index 5e0d35c4ae..8a44282c49 100644 --- a/GPL/vsconfig.gradle +++ b/GPL/vsconfig.gradle @@ -98,17 +98,29 @@ if (!hasProperty("VISUAL_STUDIO_INSTALL_DIR") && isCurrentWindows()) { def sortVisualStudioVersions(vswhereJson) { - // Try to parse each version using Java's own version parser, marking the entries that failed + // Try to parse each version using Gradle's own version parser, marking the entries that failed // (none should fail) + def validVersions = true vswhereJson.each { try { - Runtime.Version.parse(it.installationVersion) + GradleVersion.version(it.installationVersion) } catch (Exception e) { it.put("unsupportedVersion", "true") + validVersions = false } } - vswhereJson.sort { a, b -> b.instanceId <=> a.instanceId } // secondary sort - vswhereJson.sort { a, b -> Runtime.Version.parse(b.installationVersion) <=> Runtime.Version.parse(a.installationVersion) } // primary sort + // Establish a consistent ordering by first sorting by instance ID + vswhereJson.sort { a, b -> b.instanceId <=> a.instanceId } + + // Primary sort by installation version. If all the version numbers were parseable with the + // GradleVersion class, use that class to achieve the correct ordering. Otherwise, fall back to + // lexicographic order. + if (validVersions) { + vswhereJson.sort { a, b -> GradleVersion.version(b.installationVersion) <=> GradleVersion.version(a.installationVersion) } // primary sort + } + else { + vswhereJson.sort { a, b -> b.installationVersion <=> a.installationVersion } // primary sort + } }