{"action":"opened","issue":{"url":"https://api.github.com/repos/xamarin/xamarin-android/issues/2323","repository_url":"https://api.github.com/repos/xamarin/xamarin-android","labels_url":"https://api.github.com/repos/xamarin/xamarin-android/issues/2323/labels{/name}","comments_url":"https://api.github.com/repos/xamarin/xamarin-android/issues/2323/comments","events_url":"https://api.github.com/repos/xamarin/xamarin-android/issues/2323/events","html_url":"https://github.com/xamarin/xamarin-android/issues/2323","id":371785506,"node_id":"MDU6SXNzdWUzNzE3ODU1MDY=","number":2323,"title":"`ConvertResourcesCases` does not replace managed type names in `class` attributes on `<view>` elements","user":{"login":"brendanzagaeski","id":4934473,"node_id":"MDQ6VXNlcjQ5MzQ0NzM=","avatar_url":"https://avatars3.githubusercontent.com/u/4934473?v=4","gravatar_id":"","url":"https://api.github.com/users/brendanzagaeski","html_url":"https://github.com/brendanzagaeski","followers_url":"https://api.github.com/users/brendanzagaeski/followers","following_url":"https://api.github.com/users/brendanzagaeski/following{/other_user}","gists_url":"https://api.github.com/users/brendanzagaeski/gists{/gist_id}","starred_url":"https://api.github.com/users/brendanzagaeski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendanzagaeski/subscriptions","organizations_url":"https://api.github.com/users/brendanzagaeski/orgs","repos_url":"https://api.github.com/users/brendanzagaeski/repos","events_url":"https://api.github.com/users/brendanzagaeski/events{/privacy}","received_events_url":"https://api.github.com/users/brendanzagaeski/received_events","type":"User","site_admin":false},"labels":[{"id":769337515,"node_id":"MDU6TGFiZWw3NjkzMzc1MTU=","url":"https://api.github.com/repos/xamarin/xamarin-android/labels/Area:%20App+Library%20Build","name":"Area: App+Library Build","color":"000000","default":false},{"id":349989585,"node_id":"MDU6TGFiZWwzNDk5ODk1ODU=","url":"https://api.github.com/repos/xamarin/xamarin-android/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/xamarin/xamarin-android/milestones/3","html_url":"https://github.com/xamarin/xamarin-android/milestone/3","labels_url":"https://api.github.com/repos/xamarin/xamarin-android/milestones/3/labels","id":2962579,"node_id":"MDk6TWlsZXN0b25lMjk2MjU3OQ==","number":3,"title":"far future","description":"","creator":{"login":"jonpryor","id":155958,"node_id":"MDQ6VXNlcjE1NTk1OA==","avatar_url":"https://avatars3.githubusercontent.com/u/155958?v=4","gravatar_id":"","url":"https://api.github.com/users/jonpryor","html_url":"https://github.com/jonpryor","followers_url":"https://api.github.com/users/jonpryor/followers","following_url":"https://api.github.com/users/jonpryor/following{/other_user}","gists_url":"https://api.github.com/users/jonpryor/gists{/gist_id}","starred_url":"https://api.github.com/users/jonpryor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonpryor/subscriptions","organizations_url":"https://api.github.com/users/jonpryor/orgs","repos_url":"https://api.github.com/users/jonpryor/repos","events_url":"https://api.github.com/users/jonpryor/events{/privacy}","received_events_url":"https://api.github.com/users/jonpryor/received_events","type":"User","site_admin":false},"open_issues":14,"closed_issues":2,"state":"open","created_at":"2017-12-06T18:55:53Z","updated_at":"2018-10-19T02:43:47Z","due_on":null,"closed_at":null},"comments":0,"created_at":"2018-10-19T02:43:47Z","updated_at":"2018-10-19T02:43:47Z","closed_at":null,"author_association":"MEMBER","body":"This is a follow-up to <https://github.com/xamarin/xamarin-android/issues/2310> and <https://github.com/xamarin/xamarin-android/issues/2321>. Once those issues are fixed, the same logic should be added for `class` attributes on `<view>` elements (`//view/@class` nodes in XPath syntax). Currently, managed type names in these attributes are not replaced at all. They should go through all the same replacements as in the other similar attributes.\r\n\r\nReferences:\r\n- <https://developer.android.com/reference/android/view/View> includes an example of `<view class= ... />`\r\n- [`LayoutInflater` uses the `class` attribute to set the Java type of the `view`.](https://android.googlesource.com/platform/frameworks/base/+/pie-release/core/java/android/view/LayoutInflater.java#751)\r\n\r\nI searched a bit for other uses of `class` attributes in the Android source code. Apart from `<fragment>` and `<transition>`, it looks like the one other interesting example at the moment is [`<drawable>`](https://android.googlesource.com/platform/frameworks/base/+/pie-release/graphics/java/android/graphics/drawable/DrawableInflater.java#131). So it might be appropriate to replace managed type names in `//drawable/@class` nodes too, but I haven't had a chance to double-check that yet.\r\n\r\n### Steps to Reproduce\r\n\r\nAdd the following test to `ConvertResourcesCasesTests` and run it:\r\n\r\n```csharp\r\n\t\t[Test]\r\n\t\tpublic void CustomViewClassAttributes ()\r\n\t\t{\r\n\t\t\tvar path = Path.Combine (Root, \"temp\", \"CustomViewClassAttributes\");\r\n\t\t\tDirectory.CreateDirectory (path);\r\n\t\t\tvar resPath = Path.Combine (path, \"res\");\r\n\t\t\tDirectory.CreateDirectory (Path.Combine (resPath, \"layout\"));\r\n\t\t\tFile.WriteAllText (Path.Combine (resPath, \"layout\", \"main.xml\"), @\"<?xml version='1.0' ?>\r\n<LinearLayout xmlns:android='http://schemas.android.com/apk/res/android'>\r\n<view class='ClassLibrary1.CustomView' />\r\n<view class='classLibrary1.CustomView' />\r\n</LinearLayout>\r\n\");\r\n\t\t\tvar errors = new List<BuildErrorEventArgs> ();\r\n\t\t\tIBuildEngine engine = new MockBuildEngine (TestContext.Out, errors);\r\n\t\t\tvar task = new ConvertResourcesCases {\r\n\t\t\t\tBuildEngine = engine\r\n\t\t\t};\r\n\t\t\ttask.ResourceDirectories = new ITaskItem [] {\r\n\t\t\t\tnew TaskItem (resPath),\r\n\t\t\t};\r\n\t\t\ttask.AcwMapFile = Path.Combine (path, \"acwmap.txt\");\r\n\t\t\ttask.CustomViewMapFile = Path.Combine (path, \"classmap.txt\");\r\n\t\t\tFile.WriteAllLines (task.AcwMapFile, new string [] {\r\n\t\t\t\t\"ClassLibrary1.CustomView, ClassLibrary1;md5d6f7135293df7527c983d45d07471c5e.CustomView\",\r\n\t\t\t\t\"ClassLibrary1.CustomView;md5d6f7135293df7527c983d45d07471c5e.CustomView\",\r\n\t\t\t\t\"classLibrary1.CustomView;md5d6f7135293df7527c983d45d07471c5e.CustomView\"\r\n\t\t\t});\r\n\t\t\tAssert.IsTrue (task.Execute (), \"Task should have executed successfully\");\r\n\t\t\tvar custom = new ConvertCustomView () {\r\n\t\t\t\tBuildEngine = engine,\r\n\t\t\t\tCustomViewMapFile = task.CustomViewMapFile,\r\n\t\t\t\tAcwMapFile = task.AcwMapFile,\r\n\t\t\t\tResourceDirectories = new ITaskItem [] {\r\n\t\t\t\t\tnew TaskItem (resPath),\r\n\t\t\t\t},\r\n\t\t\t};\r\n\t\t\tAssert.IsTrue (custom.Execute (), \"Task should have executed successfully\");\r\n\t\t\tvar output = File.ReadAllText (Path.Combine (resPath, \"layout\", \"main.xml\"));\r\n\t\t\tStringAssert.Contains (\"md5d6f7135293df7527c983d45d07471c5e.CustomView\", output, \"md5d6f7135293df7527c983d45d07471c5e.CustomView should exist in the main.xml\");\r\n\t\t\tStringAssert.DoesNotContain (\"ClassLibrary1.CustomView\", output, \"ClassLibrary1.CustomView should have been replaced in all cases.\");\r\n\t\t\tDirectory.Delete (path, recursive: true);\r\n\t\t}\r\n```\r\n\r\n### Expected Behavior\r\n\r\nThe tests pass. Both appearances of type names in `class` attributes are replaced by the corresponding Java type names from the *acwmap.txt* file.\r\n\r\n### Actual Behavior\r\n\r\nThe test fails. The type names in the `class` attributes are not replaced.\r\n\r\n```\r\n1) Failed : Xamarin.Android.Build.Tests.ConvertResourcesCasesTests.CustomViewClassAttributes\r\n  md5d6f7135293df7527c983d45d07471c5e.CustomView should exist in the main.xml\r\n  Expected: String containing \"md5d6f7135293df7527c983d45d07471c5e.CustomView\"\r\n  But was:  \"<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"><view class=\"ClassLibrary1.CustomView\" /><view class=\"classLibrary1.CustomView\" /></LinearLayout>\"\r\nat Xamarin.Android.Build.Tests.ConvertResourcesCasesTests.CustomViewClassAttributes()\r\n```"}}
{"actor":{"display_login":"brendanzagaeski"}}