Skip to content

Commit 9268342

Browse files
author
Krispy Uccello
committed
Refactor Package Manager to use xml dependency declaration
Changed the packaging model for packaged plugins so that they now use xml to declare all dependencies. This change allows for labeling of the resolved dependencies and clean plugin removals even if the transitive dependency graph changes due to external library versioning. Install and Uninstall of packaged plugins has changed. Change-Id: I8ec5394e01f3d4c0104bac11e027cc6cc7ae66a0
1 parent 343cc7f commit 9268342

File tree

9 files changed

+733
-132
lines changed

9 files changed

+733
-132
lines changed

source/PackageManager/src/Controllers.cs

Lines changed: 638 additions & 114 deletions
Large diffs are not rendered by default.

source/PackageManager/src/Models.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public abstract class PackageManagerModel<T> {
3333
[XmlElement("xmlModelVersion")]
3434
public string xmlModelVersion;
3535

36-
// TODO(krispy): add xmlModelVersion validation.
36+
// TODO: b/34936401 add xmlModelVersion validation.
3737

3838
/// <summary>
3939
/// Deserializes a model from a provided stream containing XML data for the model.
@@ -390,5 +390,12 @@ public class ProjectClient : PackageManagerLabeledModel<ProjectClient> {
390390
/// </summary>
391391
[XmlElement("ios-resolved")]
392392
public bool resolvedForIOS = false;
393+
394+
[XmlIgnore]
395+
public string Name {
396+
get {
397+
return string.Format("{0}{1}{2}",groupId, Constants.STRING_KEY_BINDER, artifactId);
398+
}
399+
}
393400
}
394401
}

source/PackageManager/src/Utilities.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
// </copyright>
1616
namespace Google.PackageManager {
1717
using System;
18+
using System.Collections.Generic;
1819
using System.IO;
1920
using System.Linq;
21+
using System.Reflection;
2022

2123
/// <summary>
2224
/// A collection of useful utility methods.

source/PackageManager/src/Views.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ public class PluginManagerView : EditorWindow {
173173
/// Called by Unity editor when the Window is created and becomes active.
174174
/// </summary>
175175
void OnEnable() {
176-
LoggingController.Log("PluginManagerView:OnEnable called - refreshing plugins");
177176
plugins = PluginManagerController.GetListOfAllPlugins(true);
178177
}
179178

@@ -185,10 +184,7 @@ void OnInspectorGUI() {
185184
/// Ensures that the plugin details are up to date for rendering UI elements.
186185
/// </summary>
187186
void RefreshPluginDataForWindow() {
188-
LoggingController.Log("RefreshPluginDataForWindow()");
189187
plugins = PluginManagerController.GetListOfAllPlugins(true);
190-
LoggingController.Log(
191-
string.Format("RefreshPluginDataForWindow: plugin count = {0}", plugins.Count));
192188
}
193189

194190
/// <summary>
@@ -198,12 +194,8 @@ void RefreshPluginDataForWindow() {
198194
/// </summary>
199195
void Update() {
200196
if (pluginDataDirty) {
201-
LoggingController.Log("plugin data marked dirty - refreshing...");
202197
pluginDataDirty = false;
203198
RefreshPluginDataForWindow();
204-
LoggingController.Log(
205-
string.Format("plugin data marked dirty - refreshed and sees {0} plugins",
206-
plugins.Count));
207199
}
208200

209201
while (installPlugins.Count > 0) {
@@ -213,7 +205,7 @@ void Update() {
213205
EditorUtility.DisplayDialog("Plugin Install Error",
214206
"There was a problem installing the selected plugin.",
215207
"Ok");
216-
LoggingController.Log(
208+
LoggingController.LogError(
217209
string.Format("Could not install plugin with key {0}." +
218210
"Got {1} response code.", pluginKey, rc));
219211
} else {
@@ -240,7 +232,7 @@ void Update() {
240232
EditorUtility.DisplayDialog("Plugin Uninstall Error",
241233
"There was a problem removing the selected plugin.",
242234
"Ok");
243-
LoggingController.Log(
235+
LoggingController.LogError(
244236
string.Format("Could not uninstall plugin with key {0}." +
245237
"Got {1} response code.", pluginKey, rc));
246238
} else {

source/PackageManagerTests/PackageManagerTests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@
5656
<None Include="testData\registry2\com.google.unity.example2\package-manifest.xml" />
5757
<None Include="testData\registry2\com.google.unity.example2\gpm-example2-plugin\4.3.2.1\description.xml" />
5858
<None Include="testData\registry2\com.google.unity.example2\gpm-example2-plugin\4.3.2.1\gpm-example2-plugin.unitypackage" />
59+
<None Include="testData\flatdeps\group.id.example-artifact.gpm.deps.xml" />
5960
</ItemGroup>
6061
<ItemGroup>
6162
<ProjectReference Include="..\PackageManager\PackageManager.csproj">
6263
<Project>{8B0A2564-01ED-426B-AF33-33EED4A81828}</Project>
6364
<Name>PackageManager</Name>
6465
</ProjectReference>
6566
</ItemGroup>
67+
<ItemGroup>
68+
<Folder Include="testData\flatdeps\" />
69+
</ItemGroup>
6670
</Project>

source/PackageManagerTests/src/Google.PackageManager.Tests/ControllerTests.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public ResponseCode BlockingFetchAsBytes(Uri uri, out byte[] result) {
175175
}
176176

177177
/// <summary>
178-
/// Package manager controller tests.
178+
/// Test case set that excercises the PackageManagerController.
179179
/// </summary>
180180
[TestFixture]
181181
public class ControllerTests {
@@ -197,7 +197,7 @@ public void Setup() {
197197
ResponseCode.FETCH_COMPLETE);
198198
var rb = new RegistryManagerController.RegistryDatabase();
199199
rb.registryLocation.Add(TestableConstants.DefaultRegistryLocation);
200-
UnityController.editorPrefs.SetString(Constants.KEY_REGISTRIES,
200+
UnityController.EditorPrefs.SetString(Constants.KEY_REGISTRIES,
201201
rb.SerializeToXMLString());
202202

203203
var u = new Uri(Path.GetFullPath(Path.Combine(TestData.PATH,"registry2/registry.xml")));
@@ -206,8 +206,23 @@ public void Setup() {
206206
ResponseCode.FETCH_COMPLETE);
207207

208208
UriDataFetchController.SwapUriDataFetcher(mockFetcher);
209+
UnityController.SwapEditorPrefs(TestData.editorPrefs);
210+
211+
var rdb = new RegistryManagerController.RegistryDatabase();
212+
rdb.registryLocation.Add(TestableConstants.DefaultRegistryLocation);
213+
/// <summary>
214+
/// ISO 8601 format: yyyy-MM-ddTHH:mm:ssZ
215+
/// </summary>
216+
rdb.lastUpdate = DateTime.UtcNow.ToString("o"); // "o" = ISO 8601 formatting
217+
Console.Write(rdb.SerializeToXMLString());
218+
TestData.editorPrefs.SetString(Constants.KEY_REGISTRIES, rdb.SerializeToXMLString());
219+
209220
}
210221

222+
/// <summary>
223+
/// Tests the settings controller by toggleing the boolean settings and
224+
/// ensuring the DownloadCache location is set by default.
225+
/// </summary>
211226
[Test]
212227
public void TestSettingsController() {
213228
// DowloadCachePath should start with a value (system dependent).

source/PackageManagerTests/src/Google.PackageManager.Tests/ModelTests.cs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ namespace Google.PackageManager.Tests {
1717
using System.IO;
1818
using PackageManager;
1919
using NUnit.Framework;
20+
using System;
2021

21-
/// <summary>
22-
/// Package manager model tests.
23-
/// </summary>
2422
[TestFixture]
2523
public class PackageManagerModelTests {
2624
// Path to test data, contains a mock registry and settings config.
@@ -64,6 +62,43 @@ public void TestLoadFromFile() {
6462
Assert.NotNull(description.languages);
6563
Assert.AreEqual(1,description.languages.Count);
6664
}
67-
// TODO(krispy): add test cases - serialization, model differences
65+
66+
[Test]
67+
public void TestPackageDependencies() {
68+
var pd = new PackageDependencies();
69+
pd.groupId = "my.group.id";
70+
pd.artifactId = "my-artifact-id";
71+
72+
var dep = new AndroidPackageDependency();
73+
dep.group = "com.google.android.gms";
74+
dep.artifact = "play-services-ads";
75+
dep.version = "LATEST";
76+
77+
var arg = new DependencyArgument();
78+
arg.packageIds.Add("extra-google-m2repository");
79+
arg.packageIds.Add("extra-google-m2repository");
80+
arg.repositories.Add("some-repository");
81+
82+
dep.args = arg;
83+
pd.androidDependencies.Add(dep);
84+
85+
var xml = pd.SerializeToXMLString();
86+
// these can come back out of order on inflate - so we remove them
87+
xml = xml.Replace("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"","");
88+
xml = xml.Replace("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"","");
89+
Console.WriteLine("Actual: "+xml+"\n\n");
90+
xml = xml.Substring(1); // strip BOM for test
91+
var expectedXml = File.ReadAllText(
92+
Path.Combine(
93+
Path.Combine(
94+
Path.GetFullPath(TestData.PATH),
95+
"flatdeps"),
96+
"group.id.example-artifact.gpm.deps.xml"));
97+
// these can come back out of order on inflate - so we remove them
98+
expectedXml = expectedXml.Replace("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"","");
99+
expectedXml = expectedXml.Replace("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"","");
100+
Console.WriteLine("Expected: " + xml + "\n\n");
101+
Assert.AreEqual(expectedXml,xml);
102+
}
68103
}
69104
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package-dependencies xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3+
<groupId>my.group.id</groupId>
4+
<artifactId>my-artifact-id</artifactId>
5+
<android-dependencies>
6+
<android-dependency>
7+
<group>com.google.android.gms</group>
8+
<artifact>play-services-ads</artifact>
9+
<version>LATEST</version>
10+
<args>
11+
<android-packages>
12+
<android-package>extra-google-m2repository</android-package>
13+
<android-package>extra-google-m2repository</android-package>
14+
</android-packages>
15+
<repositories>
16+
<repository>some-repository</repository>
17+
</repositories>
18+
</args>
19+
</android-dependency>
20+
</android-dependencies>
21+
<ios-pod-dependencies />
22+
</package-dependencies>

source/PlayServicesResolver/src/PlayServicesResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public static bool HandleOverwriteConfirmation(Dependency oldDep, Dependency new
432432
string msg = "Replace " + oldDep.Artifact + " version " +
433433
oldDep.BestVersion + " with version " + newDep.BestVersion + "?";
434434
return EditorUtility.DisplayDialog("Android Jar Dependencies",
435-
msg, "OK", "Keep");
435+
msg,"Replace","Keep");
436436
}
437437
return true;
438438
}

0 commit comments

Comments
 (0)