public void UpdateLayoutIdIsIncludedInDesigner([Values(true, false)] bool useRtxt) { var path = Path.Combine("temp", TestName + " Some Space"); CreateResourceDirectory(path); if (useRtxt) { File.WriteAllText(Path.Combine(Root, path, "R.txt"), Rtxt); } IBuildEngine engine = new MockBuildEngine(TestContext.Out); var task = new GenerateResourceDesigner { BuildEngine = engine }; task.UseManagedResourceGenerator = true; task.DesignTimeBuild = true; task.Namespace = "Foo.Foo"; task.NetResgenOutputFile = Path.Combine(Root, path, "Resource.designer.cs"); task.ProjectDir = Path.Combine(Root, path); task.ResourceDirectory = Path.Combine(Root, path, "res") + Path.DirectorySeparatorChar; task.Resources = new TaskItem [] { new TaskItem(Path.Combine(Root, path, "res", "values", "strings.xml"), new Dictionary <string, string> () { { "LogicalName", "values\\strings.xml" }, }), }; task.AdditionalResourceDirectories = new TaskItem [] { new TaskItem(Path.Combine(Root, path, "lp", "res")), }; task.ResourceFlagFile = Path.Combine(Root, path, "AndroidResgen.flag"); File.WriteAllText(task.ResourceFlagFile, string.Empty); task.IsApplication = true; task.JavaPlatformJarPath = Path.Combine(AndroidSdkDirectory, "platforms", "android-27", "android.jar"); Assert.IsTrue(task.Execute(), "Task should have executed successfully."); Assert.IsTrue(File.Exists(task.NetResgenOutputFile), $"{task.NetResgenOutputFile} should have been created."); var expected = Path.Combine(Root, "Expected", "GenerateDesignerFileExpected.cs"); Assert.IsTrue(FileCompare(task.NetResgenOutputFile, expected), $"{task.NetResgenOutputFile} and {expected} do not match."); // Update the id, and force the managed parser to re-parse the output File.WriteAllText(Path.Combine(Root, path, "res", "layout", "main.xml"), Main.Replace("@+id/textview.withperiod", "@+id/textview.withperiod2")); File.SetLastWriteTimeUtc(task.ResourceFlagFile, DateTime.UtcNow); Assert.IsTrue(task.Execute(), "Task should have executed successfully."); Assert.IsTrue(File.Exists(task.NetResgenOutputFile), $"{task.NetResgenOutputFile} should have been created."); var data = File.ReadAllText(expected); var expectedWithNewId = Path.Combine(Root, path, "GenerateDesignerFileExpectedWithNewId.cs"); File.WriteAllText(expectedWithNewId, data.Replace("withperiod", "withperiod2")); Assert.IsTrue(FileCompare(task.NetResgenOutputFile, expectedWithNewId), $"{task.NetResgenOutputFile} and {expectedWithNewId} do not match."); Directory.Delete(Path.Combine(Root, path), recursive: true); }
public void GenerateDesignerFileWithÜmläüts() { var path = Path.Combine("temp", TestName + " Some Space"); CreateResourceDirectory(path); IBuildEngine engine = new MockBuildEngine(TestContext.Out); var task = new GenerateResourceDesigner { BuildEngine = engine }; task.UseManagedResourceGenerator = true; task.DesignTimeBuild = true; task.Namespace = "Foo.Foo"; task.NetResgenOutputFile = Path.Combine(Root, path, "Resource.designer.cs"); task.ProjectDir = Path.Combine(Root, path); task.ResourceDirectory = Path.Combine(Root, path, "res") + Path.DirectorySeparatorChar; task.Resources = new TaskItem [] { new TaskItem(Path.Combine(Root, path, "res", "values", "strings.xml"), new Dictionary <string, string> () { { "LogicalName", "values\\strings.xml" }, }), }; task.AdditionalResourceDirectories = new TaskItem [] { new TaskItem(Path.Combine(Root, path, "lp", "res")), }; task.IsApplication = true; task.JavaPlatformJarPath = Path.Combine(AndroidSdkDirectory, "platforms", "android-27", "android.jar"); Assert.IsTrue(task.Execute(), "Task should have executed successfully."); Assert.IsTrue(File.Exists(task.NetResgenOutputFile), $"{task.NetResgenOutputFile} should have been created."); var expected = Path.Combine(Root, "Expected", "GenerateDesignerFileExpected.cs"); Assert.IsTrue(FileCompare(task.NetResgenOutputFile, expected), $"{task.NetResgenOutputFile} and {expected} do not match."); Directory.Delete(Path.Combine(Root, path), recursive: true); }
public void GenerateDesignerFile() { var path = Path.Combine("temp", TestName); Directory.CreateDirectory(Path.Combine(Root, path, "res", "values")); Directory.CreateDirectory(Path.Combine(Root, path, "res", "transition")); Directory.CreateDirectory(Path.Combine(Root, path, "res", "raw")); File.WriteAllText(Path.Combine(Root, path, "res", "values", "strings.xml"), StringsXml); File.WriteAllText(Path.Combine(Root, path, "res", "transition", "transition.xml"), Transition); File.WriteAllText(Path.Combine(Root, path, "res", "raw", "foo.txt"), "Foo"); Directory.CreateDirectory(Path.Combine(Root, path, "lp", "res", "animator")); Directory.CreateDirectory(Path.Combine(Root, path, "lp", "res", "font")); Directory.CreateDirectory(Path.Combine(Root, path, "lp", "res", "values")); Directory.CreateDirectory(Path.Combine(Root, path, "lp", "res", "drawable")); Directory.CreateDirectory(Path.Combine(Root, path, "lp", "res", "menu")); Directory.CreateDirectory(Path.Combine(Root, path, "lp", "res", "mipmap-hdpi")); File.WriteAllText(Path.Combine(Root, path, "lp", "res", "animator", "slide_in_bottom.xml"), Animator); File.WriteAllText(Path.Combine(Root, path, "lp", "res", "font", "arial.ttf"), ""); File.WriteAllText(Path.Combine(Root, path, "lp", "res", "values", "strings.xml"), StringsXml2); File.WriteAllText(Path.Combine(Root, path, "lp", "res", "values", "dimen.xml"), Dimen); using (var stream = typeof(XamarinAndroidCommonProject).Assembly.GetManifestResourceStream("Xamarin.ProjectTools.Resources.Base.Icon.png")) { var icon_binary_mdpi = new byte [stream.Length]; stream.Read(icon_binary_mdpi, 0, (int)stream.Length); File.WriteAllBytes(Path.Combine(Root, path, "lp", "res", "drawable", "ic_menu_preferences.png"), icon_binary_mdpi); File.WriteAllBytes(Path.Combine(Root, path, "lp", "res", "mipmap-hdpi", "icon.png"), icon_binary_mdpi); } File.WriteAllText(Path.Combine(Root, path, "lp", "res", "menu", "Options.xml"), Menu); IBuildEngine engine = new MockBuildEngine(TestContext.Out); var task = new GenerateResourceDesigner { BuildEngine = engine }; task.UseManagedResourceGenerator = true; task.DesignTimeBuild = true; task.Namespace = "Foo.Foo"; task.NetResgenOutputFile = Path.Combine(Root, path, "Resource.designer.cs"); task.ProjectDir = Path.Combine(Root, path); task.ResourceDirectory = Path.Combine(Root, path, "res") + Path.DirectorySeparatorChar; task.Resources = new TaskItem [] { new TaskItem(Path.Combine(Root, path, "res", "values", "strings.xml"), new Dictionary <string, string> () { { "LogicalName", "values\\strings.xml" }, }), }; task.AdditionalResourceDirectories = new TaskItem [] { new TaskItem(Path.Combine(Root, path, "lp", "res")), }; task.IsApplication = true; Assert.IsTrue(task.Execute(), "Task should have executed successfully."); Assert.IsTrue(File.Exists(task.NetResgenOutputFile), $"{task.NetResgenOutputFile} should have been created."); var expected = Path.Combine(Root, "Expected", "GenerateDesignerFileExpected.cs"); Assert.IsTrue(FileCompare(task.NetResgenOutputFile, expected), $"{task.NetResgenOutputFile} and {expected} do not match."); Directory.Delete(Path.Combine(Root, path), recursive: true); }
public void GenerateDesignerFileFromRtxt([Values(false, true)] bool withLibraryReference) { var path = Path.Combine("temp", TestName + " Some Space"); CreateResourceDirectory(path); File.WriteAllText(Path.Combine(Root, path, "R.txt"), Rtxt); IBuildEngine engine = new MockBuildEngine(TestContext.Out); var task = new GenerateResourceDesigner { BuildEngine = engine }; task.UseManagedResourceGenerator = true; task.DesignTimeBuild = true; task.Namespace = "Foo.Foo"; task.RTxtFile = Path.Combine(Root, path, "R.txt"); task.NetResgenOutputFile = Path.Combine(Root, path, "Resource.designer.cs"); task.ProjectDir = Path.Combine(Root, path); task.ResourceDirectory = Path.Combine(Root, path, "res") + Path.DirectorySeparatorChar; task.Resources = new TaskItem [] { new TaskItem(Path.Combine(Root, path, "res", "values", "strings.xml"), new Dictionary <string, string> () { { "LogicalName", "values\\strings.xml" }, }), }; task.AdditionalResourceDirectories = new TaskItem [] { new TaskItem(Path.Combine(Root, path, "lp", "res")), }; task.IsApplication = true; task.JavaPlatformJarPath = Path.Combine(AndroidSdkDirectory, "platforms", "android-27", "android.jar"); if (withLibraryReference) { var libraryPath = Path.Combine(path, "Library"); BuildLibraryWithResources(libraryPath); task.References = new TaskItem [] { new TaskItem(Path.Combine(Root, libraryPath, "bin", "Debug", "Library.dll")) }; } Assert.IsTrue(task.Execute(), "Task should have executed successfully."); Assert.IsTrue(File.Exists(task.NetResgenOutputFile), $"{task.NetResgenOutputFile} should have been created."); var expected = Path.Combine(Root, "Expected", withLibraryReference ? "GenerateDesignerFileWithLibraryReferenceExpected.cs" : "GenerateDesignerFileExpected.cs"); CompareFilesIgnoreRuntimeInfoString(task.NetResgenOutputFile, expected); Directory.Delete(Path.Combine(Root, path), recursive: true); }
public void GenerateDesignerFileWithElevenStyleableAttributesFromRtxt() { var styleable = @"<resources> <declare-styleable name = ""ElevenAttributes""> <attr name = ""attr00"" format=""string"" /> <attr name = ""attr01"" format=""string"" /> <attr name = ""attr02"" format=""string"" /> <attr name = ""attr03"" format=""string"" /> <attr name = ""attr04"" format=""string"" /> <attr name = ""attr05"" format=""string"" /> <attr name = ""attr06"" format=""string"" /> <attr name = ""attr07"" format=""string"" /> <attr name = ""attr08"" format=""string"" /> <attr name = ""attr09"" format=""string"" /> <attr name = ""attr10"" format=""string"" /> </declare-styleable> </resources>"; var rtxt = @"int attr attr00 0x7f010000 int attr attr01 0x7f010001 int attr attr02 0x7f010002 int attr attr03 0x7f010003 int attr attr04 0x7f010004 int attr attr05 0x7f010005 int attr attr06 0x7f010006 int attr attr07 0x7f010007 int attr attr08 0x7f010008 int attr attr09 0x7f010009 int attr attr10 0x7f01000a int[] styleable ElevenAttributes { 0x7f010000, 0x7f010001, 0x7f010002, 0x7f010003, 0x7f010004, 0x7f010005, 0x7f010006, 0x7f010007, 0x7f010008, 0x7f010009, 0x7f01000a } int styleable ElevenAttributes_attr00 0 int styleable ElevenAttributes_attr01 1 int styleable ElevenAttributes_attr02 2 int styleable ElevenAttributes_attr03 3 int styleable ElevenAttributes_attr04 4 int styleable ElevenAttributes_attr05 5 int styleable ElevenAttributes_attr06 6 int styleable ElevenAttributes_attr07 7 int styleable ElevenAttributes_attr08 8 int styleable ElevenAttributes_attr09 9 int styleable ElevenAttributes_attr10 10"; var path = Path.Combine("temp", TestName); Directory.CreateDirectory(Path.Combine(Root, path)); File.WriteAllText(Path.Combine(Root, path, "AndroidManifest.xml"), AndroidManifest); Directory.CreateDirectory(Path.Combine(Root, path, "res")); Directory.CreateDirectory(Path.Combine(Root, path, "res", "values")); File.WriteAllText(Path.Combine(Root, path, "res", "values", "attrs.xml"), styleable); File.WriteAllText(Path.Combine(Root, path, "R.txt"), rtxt); IBuildEngine engine = new MockBuildEngine(TestContext.Out); var task = new GenerateResourceDesigner { BuildEngine = engine }; task.UseManagedResourceGenerator = true; task.DesignTimeBuild = true; task.Namespace = "Foo.Foo"; task.NetResgenOutputFile = Path.Combine(Root, path, "Resource.designer.cs"); task.ProjectDir = Path.Combine(Root, path); task.ResourceDirectory = Path.Combine(Root, path, "res"); task.Resources = new TaskItem [] {}; task.IsApplication = true; task.JavaPlatformJarPath = Path.Combine(AndroidSdkDirectory, "platforms", "android-27", "android.jar"); Assert.IsTrue(task.Execute(), "Task should have executed successfully."); Assert.IsTrue(File.Exists(task.NetResgenOutputFile), $"{task.NetResgenOutputFile} should have been created."); var expected = Path.Combine(Root, "Expected", "GenerateDesignerFileWithElevenStyleableAttributesExpected.cs"); CompareFilesIgnoreRuntimeInfoString(task.NetResgenOutputFile, expected); Directory.Delete(Path.Combine(Root, path), recursive: true); }
public void CompareAaptAndManagedParserOutputWithCustomIds() { var path = Path.Combine("temp", TestName); CreateResourceDirectory(path); File.WriteAllText(Path.Combine(Root, path, "res", "layout", "custom.xml"), CustomId); File.WriteAllText(Path.Combine(Root, path, "foo.map"), @"a\nb"); Directory.CreateDirectory(Path.Combine(Root, path, "java")); string resPath = Path.Combine(Root, path, "res"); int platform = 0; using (var b = new Builder()) { platform = b.GetMaxInstalledPlatform(); } IBuildEngine engine = new MockBuildEngine(TestContext.Out); var aapt = new Aapt() { BuildEngine = engine, ToolPath = GetPathToAapt(), ResourceDirectory = resPath, ManifestFiles = new ITaskItem [] { new TaskItem(Path.Combine(Root, path, "AndroidManifest.xml")) }, ResourceOutputFile = Path.Combine(Root, path, "foo.apk"), AssemblyIdentityMapFile = Path.Combine(Root, path, "foo.map"), JavaPlatformJarPath = Path.Combine(AndroidSdkDirectory, "platforms", $"android-{platform}", "android.jar"), JavaDesignerOutputDirectory = Path.Combine(Root, path, "java"), ResourceSymbolsTextFileDirectory = Path.Combine(Root, path), AdditionalResourceDirectories = new ITaskItem [] { new TaskItem(Path.Combine(Root, path, "lp", "res")) }, AndroidUseLatestPlatformSdk = true, ApiLevel = $"{platform}", }; Assert.IsTrue(aapt.Execute(), "Aapt should have succeeded."); string rTxt = Path.Combine(Root, path, "R.txt"); FileAssert.Exists(rTxt, $"{rTxt} should have been created."); var task = new GenerateResourceDesigner { BuildEngine = engine }; task.UseManagedResourceGenerator = true; task.DesignTimeBuild = false; task.Namespace = "MonoAndroidApplication4.MonoAndroidApplication4"; task.NetResgenOutputFile = Path.Combine(Root, path, "Resource.designer.aapt.cs"); task.ProjectDir = Path.Combine(Root, path); task.ResourceDirectory = Path.Combine(Root, path, "res") + Path.DirectorySeparatorChar; task.Resources = new TaskItem [] { new TaskItem(Path.Combine(Root, path, "res", "values", "strings.xml"), new Dictionary <string, string> () { { "LogicalName", "values\\strings.xml" }, }), }; task.AdditionalResourceDirectories = new TaskItem [] { new TaskItem(Path.Combine(Root, path, "lp", "res")), }; task.ResourceFlagFile = Path.Combine(Root, path, "AndroidResgen.flag"); task.IsApplication = true; task.JavaPlatformJarPath = aapt.JavaPlatformJarPath; Assert.IsTrue(task.Execute(), "Task should have executed successfully."); string aaptDesigner = Path.Combine(Root, path, "Resource.designer.aapt.cs"); var aaptDesignerText = File.ReadAllText(aaptDesigner); StringAssert.Contains("MyCustomID", aaptDesignerText, ""); StringAssert.Contains("HelloWorldTextView", aaptDesignerText, ""); StringAssert.Contains("ACustomID", aaptDesignerText, ""); StringAssert.Contains("foo1", aaptDesignerText, ""); task.UseManagedResourceGenerator = true; task.DesignTimeBuild = true; task.NetResgenOutputFile = Path.Combine(Root, path, "Resource.designer.managedrtxt.cs"); Assert.IsTrue(task.Execute(), "Task should have executed successfully."); string managedDesignerRtxt = Path.Combine(Root, path, "Resource.designer.managedrtxt.cs"); CompareFilesIgnoreRuntimeInfoString(managedDesignerRtxt, aaptDesigner); File.WriteAllText(task.ResourceFlagFile, string.Empty); File.Delete(Path.Combine(Root, path, "R.txt.bak")); File.Move(rTxt, Path.Combine(Root, path, "R.txt.bak")); task.UseManagedResourceGenerator = true; task.DesignTimeBuild = true; task.NetResgenOutputFile = Path.Combine(Root, path, "Resource.designer.managed.cs"); Assert.IsTrue(task.Execute(), "Task should have executed successfully."); string managedDesigner = Path.Combine(Root, path, "Resource.designer.managed.cs"); var managedDesignerText = File.ReadAllText(managedDesigner); StringAssert.Contains("MyCustomID", managedDesignerText, ""); StringAssert.Contains("HelloWorldTextView", managedDesignerText, ""); StringAssert.Contains("ACustomID", managedDesignerText, ""); StringAssert.Contains("foo1", managedDesignerText, ""); Directory.Delete(Path.Combine(Root, path), recursive: true); }
public void CompareAapt2AndManagedParserOutput() { var path = Path.Combine("temp", TestName); CreateResourceDirectory(path); File.WriteAllText(Path.Combine(Root, path, "foo.map"), @"a\nb"); Directory.CreateDirectory(Path.Combine(Root, path, "java")); IBuildEngine engine = new MockBuildEngine(TestContext.Out); var aapt2Compile = new Aapt2Compile { BuildEngine = engine, ToolPath = GetPathToAapt2(), ResourceDirectories = new ITaskItem [] { new TaskItem(Path.Combine(Root, path, "lp", "res"), new Dictionary <string, string> { { "Hash", "lp" } }), new TaskItem(Path.Combine(Root, path, "res"), new Dictionary <string, string> { { "Hash", "compiled" } }), }, FlatArchivesDirectory = Path.Combine(Root, path), }; Assert.IsTrue(aapt2Compile.Execute(), "Aapt2 Compile should have succeeded."); int platform = 0; using (var b = new Builder()) { platform = b.GetMaxInstalledPlatform(); } string resPath = Path.Combine(Root, path, "res"); string rTxt = Path.Combine(Root, path, "R.txt"); var aapt2Link = new Aapt2Link { BuildEngine = engine, ToolPath = GetPathToAapt2(), ResourceDirectories = new ITaskItem [] { new TaskItem(resPath) }, ManifestFiles = new ITaskItem [] { new TaskItem(Path.Combine(Root, path, "AndroidManifest.xml")) }, AdditionalResourceArchives = new ITaskItem [] { new TaskItem(Path.Combine(Root, path, "lp.flata")) }, CompiledResourceFlatArchive = new TaskItem(Path.Combine(Root, path, "compiled.flata")), OutputFile = Path.Combine(Root, path, "foo.apk"), AssemblyIdentityMapFile = Path.Combine(Root, path, "foo.map"), JavaPlatformJarPath = Path.Combine(AndroidSdkDirectory, "platforms", $"android-{platform}", "android.jar"), JavaDesignerOutputDirectory = Path.Combine(Root, path, "java"), ResourceSymbolsTextFile = rTxt, }; Assert.IsTrue(aapt2Link.Execute(), "Aapt2 Link should have succeeded."); FileAssert.Exists(rTxt, $"{rTxt} should have been created."); var task = new GenerateResourceDesigner { BuildEngine = engine }; task.UseManagedResourceGenerator = true; task.DesignTimeBuild = false; task.Namespace = "MonoAndroidApplication4.MonoAndroidApplication4"; task.NetResgenOutputFile = Path.Combine(Root, path, "Resource.designer.aapt2.cs"); task.ProjectDir = Path.Combine(Root, path); task.ResourceDirectory = Path.Combine(Root, path, "res") + Path.DirectorySeparatorChar; task.Resources = new TaskItem [] { new TaskItem(Path.Combine(Root, path, "res", "values", "strings.xml"), new Dictionary <string, string> () { { "LogicalName", "values\\strings.xml" }, }), }; task.AdditionalResourceDirectories = new TaskItem [] { new TaskItem(Path.Combine(Root, path, "lp", "res")), }; task.ResourceFlagFile = Path.Combine(Root, path, "AndroidResgen.flag"); task.IsApplication = true; task.JavaPlatformJarPath = aapt2Link.JavaPlatformJarPath; Assert.IsTrue(task.Execute(), "Task should have executed successfully."); File.WriteAllText(task.ResourceFlagFile, string.Empty); File.Delete(Path.Combine(Root, path, "R.txt.bak")); File.Move(rTxt, Path.Combine(Root, path, "R.txt.bak")); task.UseManagedResourceGenerator = true; task.DesignTimeBuild = true; task.NetResgenOutputFile = Path.Combine(Root, path, "Resource.designer.managed.cs"); Assert.IsTrue(task.Execute(), "Task should have executed successfully."); string aapt2Designer = Path.Combine(Root, path, "Resource.designer.aapt2.cs"); string managedDesigner = Path.Combine(Root, path, "Resource.designer.managed.cs"); CompareFilesIgnoreRuntimeInfoString(managedDesigner, aapt2Designer); Directory.Delete(Path.Combine(Root, path), recursive: true); }