Skip to content

Commit 4514961

Browse files
author
Stewart Miles
committed
Integrate VH -> UPM package migration into UPMR
The Unity Package Manager Resolver will now prompt the user to migrate packages if any Version Handler packages are found in the project with equivalent UPM packages. Bug: 150471207 Change-Id: Idfc35428b6dc70816dde8c5abbebaff7483ed9e3
1 parent 052c9f3 commit 4514961

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,35 @@ XML configuration files via the following menu options:
518518
Modify Registries` will prompt the user with a window which allows them to
519519
add or remove registries discovered in the project.
520520

521+
## Migration
522+
523+
UPMR can migrate Version Handler packages installed in the `Assets` folder
524+
to UPM packages. This requires the plugins to implement the following:
525+
526+
* `.unitypackage` must include a Version Handler manifests that describes
527+
the components of the plugin. If the plugin has no dependencies
528+
the manifest would just include the files in the plugin.
529+
* The UPM package JSON provided by the registry must include a keyword
530+
(in the `versions.VERSION.keyword` list) that maps the UPM package
531+
to a Version Handler package using the format
532+
`vh-name:VERSION_HANDLER_MANIFEST_NAME` where `VERSION_HANDLER_MANIFEST_NAME`
533+
is the name of the manifest defined in the `.unitypackage`. For
534+
more information see the description of the `gvhp_manifestname` asset label
535+
in the *Version Handler Usage* section.
536+
537+
When using the `Assets > External Dependency Manager >
538+
Unity Package Manager Resolver > Migrate Packages` menu option, UPMR then
539+
will:
540+
541+
* List all Version Handler manager packages in the project.
542+
* Search all available packages in the UPM registries and fetch keywords
543+
associated with each package parsing the Version Handler manifest names
544+
for each package.
545+
* Map each installed Version Handler package to a UPM package.
546+
* Prompt the user to migrate the discovered packages.
547+
* Perform package migration for all selected packages if the user clicks
548+
the `Apply` button.
549+
521550
## Configuration
522551

523552
UPMR can be configured via the `Assets > External Dependency Manager >
@@ -529,6 +558,9 @@ Unity Package Manager Resolver > Settings` menu option:
529558
* `Prompt to add package registries` will cause a developer to be prompted
530559
with a window that will ask for confirmation before adding registries.
531560
When this is disabled registries are added silently to the project.
561+
* `Prompt to migrate packages` will cause a developer to be prompted
562+
with a window that will ask for confirmation before migrating packages
563+
installed in the `Assets` directory to UPM packages.
532564
* `Enable Analytics Reporting` when enabled, reports the use of the plugin
533565
to the developers so they can make imrpovements.
534566
* `Verbose logging` when enabled prints debug information to the console

source/UnityPackageManagerResolver/src/SettingsDialog.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ private class Settings {
4040
/// </summary>
4141
internal bool promptToAddRegistries;
4242

43+
44+
/// <summary>
45+
/// Whether to prompt the user to migrate Version Handler to UPM packages after a
46+
/// registry has been added.
47+
/// </summary>
48+
internal bool promptToMigratePackages;
49+
4350
/// <summary>
4451
/// Whether to enable / disable verbose logging.
4552
/// </summary>
@@ -61,6 +68,7 @@ private class Settings {
6168
internal Settings() {
6269
enable = UnityPackageManagerResolver.Enable;
6370
promptToAddRegistries = UnityPackageManagerResolver.PromptToAddRegistries;
71+
promptToMigratePackages = UnityPackageManagerResolver.PromptToMigratePackages;
6472
verboseLoggingEnabled = UnityPackageManagerResolver.VerboseLoggingEnabled;
6573
useProjectSettings = UnityPackageManagerResolver.UseProjectSettings;
6674
analyticsSettings =
@@ -73,6 +81,7 @@ internal Settings() {
7381
internal void Save() {
7482
UnityPackageManagerResolver.Enable = enable;
7583
UnityPackageManagerResolver.PromptToAddRegistries = promptToAddRegistries;
84+
UnityPackageManagerResolver.PromptToMigratePackages = promptToMigratePackages;
7685
UnityPackageManagerResolver.VerboseLoggingEnabled = verboseLoggingEnabled;
7786
UnityPackageManagerResolver.UseProjectSettings = useProjectSettings;
7887
analyticsSettings.Save();
@@ -81,6 +90,8 @@ internal void Save() {
8190

8291
private Settings settings;
8392

93+
private Vector2 scrollPosition = new Vector2(0, 0);
94+
8495
/// <summary>
8596
/// Load settings for this dialog.
8697
/// </summary>
@@ -92,7 +103,7 @@ private void LoadSettings() {
92103
/// Setup the window's initial position and size.
93104
/// </summary>
94105
public void Initialize() {
95-
minSize = new Vector2(350, 400);
106+
minSize = new Vector2(350, 430);
96107
position = new Rect(UnityEngine.Screen.width / 3,
97108
UnityEngine.Screen.height / 3,
98109
minSize.x, minSize.y);
@@ -120,6 +131,8 @@ public void OnGUI() {
120131
UnityPackageManagerResolverVersionNumber.Value.Minor,
121132
UnityPackageManagerResolverVersionNumber.Value.Build));
122133

134+
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
135+
123136
if (!UnityPackageManagerResolver.ScopedRegistriesSupported) {
124137
GUILayout.Label(
125138
String.Format("Only supported from Unity {0} and above.",
@@ -146,6 +159,15 @@ public void OnGUI() {
146159
"before adding Unity Package Manager registries to the project's " +
147160
"manifest.");
148161

162+
GUILayout.BeginHorizontal();
163+
GUILayout.Label("Prompt to migrate packages", EditorStyles.boldLabel);
164+
settings.promptToMigratePackages = EditorGUILayout.Toggle(settings.promptToMigratePackages);
165+
GUILayout.EndHorizontal();
166+
GUILayout.Label("When this option is enabled, this plugin will search the Unity Package " +
167+
"Manager (UPM) for available packages that are currently installed in " +
168+
"the project in the `Assets` directory that have equivalent or newer " +
169+
"versions available on UPM and prompt to migrate these packages.");
170+
149171
settings.analyticsSettings.RenderGui();
150172

151173
GUILayout.BeginHorizontal();
@@ -196,6 +218,8 @@ public void OnGUI() {
196218
UnityPackageManagerResolver.CheckRegistries();
197219
}
198220
GUILayout.EndHorizontal();
221+
222+
EditorGUILayout.EndScrollView();
199223
GUILayout.EndVertical();
200224

201225
// Re-enable GUI

source/UnityPackageManagerResolver/src/UnityPackageManagerResolver.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ private static Dictionary<string, UnityPackageManagerRegistry> ReadRegistriesFro
230230
/// <param name="invertSelection">If false, adds the selected registries and removes the
231231
/// unselected registries. If true, removes the selected registries and adds the unselected
232232
/// registries.</param>
233+
/// <param name="addedRegistries">If specified, is extended with the list of registries added
234+
/// to the manifest.<param>
233235
/// <returns>true if successful, false otherwise.</returns>
234236
private static bool SyncRegistriesToManifest(
235237
PackageManifestModifier manifestModifier,
@@ -238,7 +240,8 @@ private static bool SyncRegistriesToManifest(
238240
HashSet<string> selectedRegistryUrls,
239241
bool addRegistries = true,
240242
bool removeRegistries = true,
241-
bool invertSelection = false) {
243+
bool invertSelection = false,
244+
List<UnityPackageManagerRegistry> addedRegistries = null) {
242245
// Build a list of registries to add to and remove from the manifest.
243246
var registriesToAdd = new List<UnityPackageManagerRegistry>();
244247
var registriesToRemove = new List<UnityPackageManagerRegistry>();
@@ -280,6 +283,7 @@ private static bool SyncRegistriesToManifest(
280283
"Added registries to {0}:\n{1}",
281284
PackageManifestModifier.MANIFEST_FILE_PATH,
282285
UnityPackageManagerRegistry.ToString(registriesToAdd)));
286+
if (addedRegistries != null) addedRegistries.AddRange(registriesToAdd);
283287
}
284288
if (registriesToRemove.Count > 0) {
285289
logger.Log(String.Format(
@@ -379,13 +383,19 @@ internal static void UpdateManifest(ManifestModificationMode mode,
379383

380384
// Applies the manifest modification based upon the modification mode.
381385
Action<HashSet<string>> syncRegistriesToManifest = (urlSelectionToApply) => {
386+
var addedRegistries = new List<UnityPackageManagerRegistry>();
382387
SyncRegistriesToManifest(modifier, xmlRegistries, manifestRegistries,
383388
urlSelectionToApply,
384389
addRegistries: (mode == ManifestModificationMode.Add ||
385390
mode == ManifestModificationMode.Modify),
386391
removeRegistries: (mode == ManifestModificationMode.Remove ||
387392
mode == ManifestModificationMode.Modify),
388-
invertSelection: mode == ManifestModificationMode.Remove);
393+
invertSelection: mode == ManifestModificationMode.Remove,
394+
addedRegistries: addedRegistries);
395+
// If any registries were added try migration if enabled.
396+
if (addedRegistries.Count > 0 && PromptToMigratePackages) {
397+
PackageMigrator.MigratePackages();
398+
}
389399
};
390400

391401
if (xmlRegistries.Count > 0) {
@@ -470,12 +480,15 @@ internal static void RestoreDefaultSettings() {
470480
"Google.UnityPackageManagerResolver.Enable";
471481
private const string PreferencePromptToAddRegistries =
472482
"Google.UnityPackageManagerResolver.PromptToAddRegistries";
483+
private const string PreferencePromptToMigratePackages =
484+
"Google.UnityPackageManagerResolver.PromptToMigratePackages";
473485
private const string PreferenceVerboseLoggingEnabled =
474486
"Google.UnityPackageManagerResolver.VerboseLoggingEnabled";
475487
// List of preference keys, used to restore default settings.
476488
private static string[] PreferenceKeys = new[] {
477489
PreferenceEnable,
478490
PreferencePromptToAddRegistries,
491+
PreferencePromptToMigratePackages,
479492
PreferenceVerboseLoggingEnabled
480493
};
481494

@@ -531,6 +544,15 @@ public static bool PromptToAddRegistries {
531544
set { settings.SetBool(PreferencePromptToAddRegistries, value); }
532545
}
533546

547+
/// <summary>
548+
/// Enable / disable prompting the user to migrate Version Handler to UPM packages after a
549+
/// registry has been added.
550+
/// </summary>
551+
public static bool PromptToMigratePackages {
552+
get { return settings.GetBool(PreferencePromptToMigratePackages, defaultValue: true); }
553+
set { settings.SetBool(PreferencePromptToMigratePackages, value); }
554+
}
555+
534556
/// <summary>
535557
/// Enable / disable verbose logging.
536558
/// </summary>

0 commit comments

Comments
 (0)