Skip to content

Commit c752a86

Browse files
committed
Clarify how manifest.json will be changed in UI
Add a new section at the bottom of Package Manager Resolver window to clarify how manifest.json will be changed. Change-Id: I25c430babb862fdd08c8a815d4c9e4b458f391b0
1 parent fa6eca4 commit c752a86

File tree

5 files changed

+265
-98
lines changed

5 files changed

+265
-98
lines changed

README.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Unity plugin that requires:
1111
[AARs](https://developer.android.com/studio/projects/android-library.html)).
1212
* iOS [CocoaPods](https://cocoapods.org/).
1313
* Version management of transitive dependencies.
14-
* Management of Unity Package Manager (UPM) Registries.
14+
* Management of Package Manager (PM) Registries.
1515

1616
Updated releases are available on
1717
[GitHub](https://github.com/googlesamples/unity-jar-resolver)
@@ -69,20 +69,20 @@ Using CocoaPods allows multiple plugins to utilize shared components without
6969
forcing developers to fix either duplicate or incompatible versions of
7070
libraries included through multiple Unity plugins in their project.
7171

72-
## Unity Package Manager Registry Setup
72+
## Package Manager Registry Setup
7373

74-
The [Unity Package Manager](https://docs.unity3d.com/Manual/Packages.html)
75-
(UPM) makes use of [NPM](https://www.npmjs.com/) registry servers for package
74+
The [Package Manager](https://docs.unity3d.com/Manual/Packages.html)
75+
(PM) makes use of [NPM](https://www.npmjs.com/) registry servers for package
7676
hosting and provides ways to discover, install, upgrade and uninstall packages.
7777
This makes it easier for developers to manage plugins within their projects.
7878

7979
However, installing additional package registries requires a few manual steps
8080
that can potentially be error prone. The *Package Manager Resolver*
8181
component of this plugin integrates with
82-
[UPM](https://docs.unity3d.com/Manual/Packages.html) to provide a way to
83-
auto-install UPM package registries when a `.unitypackage` is installed which
82+
[PM](https://docs.unity3d.com/Manual/Packages.html) to provide a way to
83+
auto-install PM package registries when a `.unitypackage` is installed which
8484
allows plugin maintainers to ship a `.unitypackage` that can provide access
85-
to their own UPM registry server to make it easier for developers to
85+
to their own PM registry server to make it easier for developers to
8686
manage their plugins.
8787

8888
## Unity Plugin Version Management
@@ -135,7 +135,7 @@ depends upon the `PluginImporter` UnityEditor API.
135135
The *Package Manager Resolver* component only works with
136136
Unity 2018.4 or above, when
137137
[scoped registry](https://docs.unity3d.com/Manual/upm-scoped.html)
138-
support was added to the Unity Package Manager.
138+
support was added to the Package Manager.
139139

140140
# Getting Started
141141

@@ -205,7 +205,7 @@ target in the Unity editor.
205205
2. Copy and rename the
206206
[SampleDependencies.xml](https://github.com/googlesamples/unity-jar-resolver/blob/master/sample/Assets/ExternalDependencyManager/Editor/SampleDependencies.xml)
207207
file into your plugin and add the dependencies your plugin requires.
208-
208+
209209
The XML file just needs to be under an `Editor` directory and match the
210210
name `*Dependencies.xml`. For example,
211211
`MyPlugin/Editor/MyPluginDependencies.xml`.
@@ -405,7 +405,7 @@ Dependencies for iOS are added by referring to CocoaPods.
405405
2. Copy and rename the
406406
[SampleDependencies.xml](https://github.com/googlesamples/unity-jar-resolver/blob/master/sample/Assets/ExternalDependencyManager/Editor/SampleDependencies.xml)
407407
file into your plugin and add the dependencies your plugin requires.
408-
408+
409409
The XML file just needs to be under an `Editor` directory and match the
410410
name `*Dependencies.xml`. For example,
411411
`MyPlugin/Editor/MyPluginDependencies.xml`.
@@ -459,10 +459,10 @@ private static void PostProcessBuild_iOS(BuildTarget target, string buildPath)
459459
# Package Manager Resolver Usage
460460

461461
Adding registries to the
462-
[Unity Package Manager](https://docs.unity3d.com/Manual/Packages.html)
463-
(UPM) is a manual process. The Package Manager Resolver (PMR) component
464-
of this plugin makes it easy for plugin maintainers to distribute new UPM
465-
registry servers and easy for plugin users to manage UPM registry servers.
462+
[Package Manager](https://docs.unity3d.com/Manual/Packages.html)
463+
(PM) is a manual process. The Package Manager Resolver (PMR) component
464+
of this plugin makes it easy for plugin maintainers to distribute new PM
465+
registry servers and easy for plugin users to manage PM registry servers.
466466

467467
## Adding Registries
468468

@@ -474,7 +474,7 @@ registry servers and easy for plugin users to manage UPM registry servers.
474474
2. Copy and rename the
475475
[SampleRegistries.xml](https://github.com/googlesamples/unity-jar-resolver/blob/master/sample/Assets/ExternalDependencyManager/Editor/sample/Assets/ExternalDependencyManager/Editor/SampleRegistries.xml)
476476
file into your plugin and add the registries your plugin requires.
477-
477+
478478
The XML file just needs to be under an `Editor` directory and match the
479479
name `*Registries.xml` or labeled with `gumpr_registries`. For example,
480480
`MyPlugin/Editor/MyPluginRegistries.xml`.
@@ -510,24 +510,24 @@ XML configuration files via the following menu options:
510510

511511
* `Assets > External Dependency Manager > Package Manager Resolver >
512512
Add Registries` will prompt the user with a window which allows them to
513-
add registries discovered in the project to the Unity Package Manager.
513+
add registries discovered in the project to the Package Manager.
514514
* `Assets > External Dependency Manager > Package Manager Resolver >
515515
Remove Registries` will prompt the user with a window which allows them to
516-
remove registries discovered in the project from the Unity Package Manager.
516+
remove registries discovered in the project from the Package Manager.
517517
* `Assets > External Dependency Manager > Package Manager Resolver >
518518
Modify Registries` will prompt the user with a window which allows them to
519519
add or remove registries discovered in the project.
520520

521521
## Migration
522522

523523
PMR can migrate Version Handler packages installed in the `Assets` folder
524-
to UPM packages. This requires the plugins to implement the following:
524+
to PM packages. This requires the plugins to implement the following:
525525

526526
* `.unitypackage` must include a Version Handler manifests that describes
527527
the components of the plugin. If the plugin has no dependencies
528528
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
529+
* The PM package JSON provided by the registry must include a keyword
530+
(in the `versions.VERSION.keyword` list) that maps the PM package
531531
to a Version Handler package using the format
532532
`vh-name:VERSION_HANDLER_MANIFEST_NAME` where `VERSION_HANDLER_MANIFEST_NAME`
533533
is the name of the manifest defined in the `.unitypackage`. For
@@ -539,10 +539,10 @@ Package Manager Resolver > Migrate Packages` menu option, PMR then
539539
will:
540540

541541
* List all Version Handler manager packages in the project.
542-
* Search all available packages in the UPM registries and fetch keywords
542+
* Search all available packages in the PM registries and fetch keywords
543543
associated with each package parsing the Version Handler manifest names
544544
for each package.
545-
* Map each installed Version Handler package to a UPM package.
545+
* Map each installed Version Handler package to a PM package.
546546
* Prompt the user to migrate the discovered packages.
547547
* Perform package migration for all selected packages if the user clicks
548548
the `Apply` button.
@@ -554,13 +554,13 @@ Package Manager Resolver > Settings` menu option:
554554

555555
* `Add package registries` when enabled, when the plugin loads or registry
556556
configuration files change, this will prompt the user to add registries
557-
that are not present in the Unity Package Manager.
557+
that are not present in the Package Manager.
558558
* `Prompt to add package registries` will cause a developer to be prompted
559559
with a window that will ask for confirmation before adding registries.
560560
When this is disabled registries are added silently to the project.
561561
* `Prompt to migrate packages` will cause a developer to be prompted
562562
with a window that will ask for confirmation before migrating packages
563-
installed in the `Assets` directory to UPM packages.
563+
installed in the `Assets` directory to PM packages.
564564
* `Enable Analytics Reporting` when enabled, reports the use of the plugin
565565
to the developers so they can make imrpovements.
566566
* `Verbose logging` when enabled prints debug information to the console
@@ -578,9 +578,9 @@ The Version Handler component of this plugin manages:
578578

579579
Since the Version Handler needs to modify Unity asset metadata (`.meta` files),
580580
to enable / disable components, rename and delete asset files it does not
581-
work with Unity Package Manager installed packages. It's still possible to
582-
include EDM4U in Unity Package Manager packages, the Version Handler component
583-
simply won't do anything to UPM plugins in this case.
581+
work with Package Manager installed packages. It's still possible to
582+
include EDM4U in Package Manager packages, the Version Handler component
583+
simply won't do anything to PM plugins in this case.
584584

585585
## Using Version Handler Managed Plugins
586586

source/PackageManagerResolver/src/PackageManagerResolver.cs

Lines changed: 116 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ internal enum ManifestModificationMode {
4444
}
4545

4646
private const string ADD_REGISTRIES_QUESTION =
47-
"Add the selected Unity Package Manager registries to your project?";
47+
"Add the selected Package Manager registries to your project?";
4848
private const string REMOVE_REGISTRIES_QUESTION =
49-
"Remove the selected Unity Package Manager registries from your project?";
49+
"Remove the selected Package Manager registries from your project?";
5050
private const string ADD_REGISTRIES_DESCRIPTION =
5151
"Adding a registry will allow you to install, upgrade and remove packages from the " +
52-
"registry's server in the Unity Package Manager. By adding the selected registries, you " +
52+
"registry's server in the Package Manager. By adding the selected registries, you " +
5353
"agree that your use of these registries are subject to their terms of service and you " +
5454
"acknowledge that data will be collected in accordance with each registry's privacy " +
5555
"policy.";
5656
private const string REMOVE_REGISTRIES_DESCRIPTION =
5757
"Removing a registry will prevent you from installing and upgrading packages from the " +
58-
"registry's server in the Unity Package Manager. It will not remove packages from the " +
58+
"registry's server in the Package Manager. It will not remove packages from the " +
5959
"registry's server that are already installed";
6060
private const string ADD_OR_REMOVE_REGISTRIES_QUESTION =
61-
"Add the selected Unity Package Manager (UPM) registries to and remove the " +
62-
"unselected UPM registries from your project?";
61+
"Add the selected Package Manager registries to and remove the " +
62+
"unselected registries from your project?";
6363
private const string MODIFY_MENU_ITEM_DESCRIPTION =
6464
"You can always add or remove registries at a later time using menu item:\n" +
6565
"'Assets > External Dependency Manager > Package Manager Resolver > " +
@@ -71,7 +71,17 @@ internal enum ManifestModificationMode {
7171
private static readonly string[] googleScopes = new [] { "com.google" };
7272

7373
/// <summary>
74-
/// Enables / disables external package registries for Unity Package Manager.
74+
/// Scroll location of the manifest view on the left in the registry selection window.
75+
/// </summary>
76+
private static Vector2 scrollManifestViewLeft;
77+
78+
/// <summary>
79+
/// Scroll location of the manifest view on the right in the registry selection window.
80+
/// </summary>
81+
private static Vector2 scrollManifestViewRight;
82+
83+
/// <summary>
84+
/// Enables / disables external package registries for Package Manager.
7585
/// </summary>
7686
static PackageManagerResolver() {
7787
logger.Log("Loaded PackageManagerResolver", level: LogLevel.Verbose);
@@ -219,9 +229,11 @@ private static Dictionary<string, PackageManagerRegistry> ReadRegistriesFromXml(
219229
}
220230

221231
/// <summary>
222-
/// Apply registry changes to the projects manifest.
232+
/// Apply registry changes to the modifier.
223233
/// </summary>
224234
/// <param name="manifestModifier">Object that modifies the project's manifest.</param>
235+
/// <param name="registriesToAdd">Registries added to the modifier.</param>
236+
/// <param name="registriesToRemove">Registries removed from the modifier.</param>
225237
/// <param name="availableRegistries">Registries that are available in the
226238
/// configuration.</param>
227239
/// <param name="manifestRegistries">Registries that are present in the manifest.</param>
@@ -233,21 +245,20 @@ private static Dictionary<string, PackageManagerRegistry> ReadRegistriesFromXml(
233245
/// <param name="invertSelection">If false, adds the selected registries and removes the
234246
/// unselected registries. If true, removes the selected registries and adds the unselected
235247
/// registries.</param>
236-
/// <param name="addedRegistries">If specified, is extended with the list of registries added
237-
/// to the manifest.<param>
238-
/// <returns>true if successful, false otherwise.</returns>
239-
private static bool SyncRegistriesToManifest(
248+
/// <returns>true if the manifest is modified.</returns>
249+
private static bool SyncRegistriesToModifier(
240250
PackageManifestModifier manifestModifier,
251+
out List<PackageManagerRegistry> registriesToAdd,
252+
out List<PackageManagerRegistry> registriesToRemove,
241253
Dictionary<string, PackageManagerRegistry> availableRegistries,
242254
Dictionary<string, List<PackageManagerRegistry>> manifestRegistries,
243255
HashSet<string> selectedRegistryUrls,
244256
bool addRegistries = true,
245257
bool removeRegistries = true,
246-
bool invertSelection = false,
247-
List<PackageManagerRegistry> addedRegistries = null) {
248-
// Build a list of registries to add to and remove from the manifest.
249-
var registriesToAdd = new List<PackageManagerRegistry>();
250-
var registriesToRemove = new List<PackageManagerRegistry>();
258+
bool invertSelection = false) {
259+
// Build a list of registries to add to and remove from the modifier.
260+
registriesToAdd = new List<PackageManagerRegistry>();
261+
registriesToRemove = new List<PackageManagerRegistry>();
251262

252263
foreach (var availableRegistry in availableRegistries.Values) {
253264
var url = availableRegistry.Url;
@@ -276,6 +287,42 @@ private static bool SyncRegistriesToManifest(
276287
manifestModifier.RemoveRegistries(registriesToRemove);
277288
manifestModified = true;
278289
}
290+
return manifestModified;
291+
}
292+
293+
/// <summary>
294+
/// Apply registry changes to the projects manifest.
295+
/// </summary>
296+
/// <param name="manifestModifier">Object that modifies the project's manifest.</param>
297+
/// <param name="availableRegistries">Registries that are available in the
298+
/// configuration.</param>
299+
/// <param name="manifestRegistries">Registries that are present in the manifest.</param>
300+
/// <param name="selectedRegistryUrls">URLs of selected registries, these should be items in
301+
/// availableRegistries.</param>
302+
/// <param name="addRegistries">Whether to add selected registries to the manifest.</param>
303+
/// <param name="removeRegistries">Whether to remove unselected registries from the
304+
/// manifest.</param>
305+
/// <param name="invertSelection">If false, adds the selected registries and removes the
306+
/// unselected registries. If true, removes the selected registries and adds the unselected
307+
/// registries.</param>
308+
/// <param name="addedRegistries">If specified, is extended with the list of registries added
309+
/// to the manifest.<param>
310+
/// <returns>true if successful, false otherwise.</returns>
311+
private static bool SyncRegistriesToManifest(
312+
PackageManifestModifier manifestModifier,
313+
Dictionary<string, PackageManagerRegistry> availableRegistries,
314+
Dictionary<string, List<PackageManagerRegistry>> manifestRegistries,
315+
HashSet<string> selectedRegistryUrls,
316+
bool addRegistries = true,
317+
bool removeRegistries = true,
318+
bool invertSelection = false,
319+
List<PackageManagerRegistry> addedRegistries = null) {
320+
List<PackageManagerRegistry> registriesToAdd;
321+
List<PackageManagerRegistry> registriesToRemove;
322+
bool manifestModified = SyncRegistriesToModifier(
323+
manifestModifier, out registriesToAdd, out registriesToRemove,
324+
availableRegistries, manifestRegistries, selectedRegistryUrls,
325+
addRegistries, removeRegistries, invertSelection);
279326

280327
bool successful = true;
281328
if (manifestModified) {
@@ -401,6 +448,22 @@ internal static void UpdateManifest(ManifestModificationMode mode,
401448
}
402449
};
403450

451+
// Get the manifest json string based on the current selection and mode.
452+
Func<HashSet<string>, string> getManifestJsonAfterChange = (urlSelectionToApply) => {
453+
PackageManifestModifier clonedModifier = new PackageManifestModifier(modifier);
454+
List<PackageManagerRegistry> toAdd;
455+
List<PackageManagerRegistry> toRemove;
456+
SyncRegistriesToModifier(clonedModifier, out toAdd, out toRemove,
457+
xmlRegistries, manifestRegistries,
458+
urlSelectionToApply,
459+
addRegistries: (mode == ManifestModificationMode.Add ||
460+
mode == ManifestModificationMode.Modify),
461+
removeRegistries: (mode == ManifestModificationMode.Remove ||
462+
mode == ManifestModificationMode.Modify),
463+
invertSelection: mode == ManifestModificationMode.Remove);
464+
return clonedModifier.GetManifestJson();
465+
};
466+
404467
if (xmlRegistries.Count > 0) {
405468
if (promptBeforeAction) {
406469
// Build a list of items to display.
@@ -455,6 +518,42 @@ internal static void UpdateManifest(ManifestModificationMode mode,
455518
}
456519
}
457520
};
521+
// Set the scroll position to the bottom since "scopedRegistry" section is most
522+
// likely at the bottom of the file.
523+
scrollManifestViewLeft = new Vector2(0.0f, float.PositiveInfinity);
524+
scrollManifestViewRight = new Vector2(0.0f, float.PositiveInfinity);
525+
526+
// Render the change in manifest.json dynamically.
527+
window.RenderAfterItems = () => {
528+
GUILayout.Label("Changes to Packages/manifest.json");
529+
EditorGUILayout.Space();
530+
531+
EditorGUILayout.BeginHorizontal();
532+
533+
EditorGUILayout.BeginVertical();
534+
GUILayout.Label("Before", EditorStyles.boldLabel);
535+
EditorGUILayout.Space();
536+
scrollManifestViewLeft =
537+
EditorGUILayout.BeginScrollView(scrollManifestViewLeft,
538+
GUILayout.MaxWidth(window.position.width / 2.0f));
539+
EditorGUILayout.TextArea(modifier.GetManifestJson());
540+
EditorGUILayout.EndScrollView();
541+
EditorGUILayout.EndVertical();
542+
543+
EditorGUILayout.Space();
544+
545+
EditorGUILayout.BeginVertical();
546+
GUILayout.Label("After", EditorStyles.boldLabel);
547+
EditorGUILayout.Space();
548+
scrollManifestViewRight =
549+
EditorGUILayout.BeginScrollView(scrollManifestViewRight,
550+
GUILayout.MaxWidth(window.position.width / 2.0f));
551+
EditorGUILayout.TextArea(getManifestJsonAfterChange(window.SelectedItems));
552+
EditorGUILayout.EndScrollView();
553+
EditorGUILayout.EndVertical();
554+
555+
EditorGUILayout.EndHorizontal();
556+
};
458557
if (showDisableButton) {
459558
window.RenderBeforeCancelApply = () => {
460559
if (GUILayout.Button("Disable Registry Addition")) {

0 commit comments

Comments
 (0)