diff --git a/.external b/.external index 9b16813c5d5..bfd75f844ef 100644 --- a/.external +++ b/.external @@ -1,2 +1,2 @@ -xamarin/monodroid:main@aae6670c6ff4b68d36fb976fd6dec67a2a6d43d7 +xamarin/monodroid:main@7da768cf9ddbd137bbce5326dab79b139bcc59e0 mono/mono:2020-02@5e9cb6d1c1de430965312927d5aed7fcb27bfa73 diff --git a/.vscode/settings.json b/.vscode/settings.json index 26be202bd72..fed91edd84b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,7 +3,6 @@ "nxunitExplorer.modules": [ "bin/TestDebug/MSBuildDeviceIntegration/net472/MSBuildDeviceIntegration.dll", "bin/TestDebug/net472/Xamarin.Android.Build.Tests.dll", - "bin/TestDebug/Xamarin.Android.Build.Tests.Commercial.dll", "bin/TestRelease/MSBuildDeviceIntegration/net472/MSBuildDeviceIntegration.dll", ], "cmake.configureOnOpen": false diff --git a/Configuration.props b/Configuration.props index ad333be0376..418d1c69fe7 100644 --- a/Configuration.props +++ b/Configuration.props @@ -129,10 +129,6 @@ <_TestsProfiledAotName Condition=" '$(AndroidEnableProfiledAot)' == 'true' ">-Profiled <_TestsBundleName Condition=" '$(BundleAssemblies)' == 'true' ">-Bundle $(_TestsProfiledAotName)$(_TestsAotName)$(_TestsBundleName) - 1.0.20 - 0.11.2 - 5.4.0 - 1.1.11 i686-w64-mingw32 diff --git a/Directory.Build.props b/Directory.Build.props index eccf90880e0..b2149d14161 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -25,7 +25,10 @@ + 1.0.20 0.4.1 + 0.11.2 + 5.4.0 diff --git a/Documentation/building/windows/instructions.md b/Documentation/building/windows/instructions.md index 1c842d11720..075c580b20e 100644 --- a/Documentation/building/windows/instructions.md +++ b/Documentation/building/windows/instructions.md @@ -18,15 +18,7 @@ MSBuild version 15 or later is required. 4. (Optional) [Configure the build](../configuration.md). - 5. (For Microsoft team members only) (Optional) In a [Developer Command - Prompt][developer-prompt], prepare external proprietary git - dependencies: - - msbuild Xamarin.Android.sln /t:PrepareExternal - - This will configure external proprietary components such as monodroid. - - 6. In a [Developer Command Prompt][developer-prompt], prepare the project: + 5. In a [Developer Command Prompt][developer-prompt], prepare the project: msbuild Xamarin.Android.sln /t:Prepare @@ -34,10 +26,18 @@ MSBuild version 15 or later is required. `git submodule update`, download NuGet dependencies, and other "preparatory" and pre-build tasks that need to be performed. - 7. Build the project: + 6. Build the project: msbuild Xamarin.Android.sln + 7. (For Microsoft team members only - Optional) In a [Developer Command + Prompt][developer-prompt], build external proprietary git + dependencies: + + msbuild Xamarin.Android.sln /t:BuildExternal + + This will clone and build external proprietary components such as `monodroid`. + After the solution has built successfully, you can [use your build][using-your-build] to build Xamarin.Android application and library projects. Note that by default `Xamarin.Android.sln` only builds support for diff --git a/Makefile b/Makefile index 8a8fb916e0b..8e2ca65870b 100644 --- a/Makefile +++ b/Makefile @@ -136,12 +136,6 @@ uninstall:: topdir := $(shell pwd) -# Used by External XA Build -EXTERNAL_XA_PATH=$(topdir) -EXTERNAL_GIT_PATH=$(topdir)/external - --include $(EXTERNAL_GIT_PATH)/monodroid/xa-integration.mk - include build-tools/scripts/BuildEverything.mk # Must be after BuildEverything.mk - it uses variables defined there diff --git a/Xamarin.Android.Build.Tasks.sln b/Xamarin.Android.Build.Tasks.sln index aaede9eed96..8863d8d2190 100644 --- a/Xamarin.Android.Build.Tasks.sln +++ b/Xamarin.Android.Build.Tasks.sln @@ -25,6 +25,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Debugging.Soft", "exte EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vswhere", "tools\vswhere\vswhere.csproj", "{DBDC804F-8406-4F5E-83C6-720CB0CB6C6F}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Android.Build.BaseTasks", "external\xamarin-android-tools\src\Microsoft.Android.Build.BaseTasks\Microsoft.Android.Build.BaseTasks.csproj", "{3DE17662-DCD6-4F49-AF06-D39AACC8649A}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Android.Tools.AndroidSdk", "external\xamarin-android-tools\src\Xamarin.Android.Tools.AndroidSdk\Xamarin.Android.Tools.AndroidSdk.csproj", "{E34BCFA0-CAA4-412C-AA1C-75DB8D67D157}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Android.Sdk.ILLink", "src\Microsoft.Android.Sdk.ILLink\Microsoft.Android.Sdk.ILLink.csproj", "{2A237E71-1FA3-409B-B13E-F6294932A5A9}" @@ -78,6 +80,10 @@ Global {DBDC804F-8406-4F5E-83C6-720CB0CB6C6F}.Debug|Any CPU.Build.0 = Debug|Any CPU {DBDC804F-8406-4F5E-83C6-720CB0CB6C6F}.Release|Any CPU.ActiveCfg = Release|Any CPU {DBDC804F-8406-4F5E-83C6-720CB0CB6C6F}.Release|Any CPU.Build.0 = Release|Any CPU + {3DE17662-DCD6-4F49-AF06-D39AACC8649A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3DE17662-DCD6-4F49-AF06-D39AACC8649A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3DE17662-DCD6-4F49-AF06-D39AACC8649A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3DE17662-DCD6-4F49-AF06-D39AACC8649A}.Release|Any CPU.Build.0 = Release|Any CPU {E34BCFA0-CAA4-412C-AA1C-75DB8D67D157}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E34BCFA0-CAA4-412C-AA1C-75DB8D67D157}.Debug|Any CPU.Build.0 = Debug|Any CPU {E34BCFA0-CAA4-412C-AA1C-75DB8D67D157}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -96,6 +102,7 @@ Global {90C99ADB-7D4B-4EB4-98C2-40BD1B14C7D2} = {385E71CC-BAE5-488B-805E-ACAE55F01DF5} {372E8E3E-29D5-4B4D-88A2-4711CD628C4E} = {385E71CC-BAE5-488B-805E-ACAE55F01DF5} {DE40756E-57F6-4AF2-B155-55E3A88CCED8} = {385E71CC-BAE5-488B-805E-ACAE55F01DF5} + {3DE17662-DCD6-4F49-AF06-D39AACC8649A} = {385E71CC-BAE5-488B-805E-ACAE55F01DF5} {E34BCFA0-CAA4-412C-AA1C-75DB8D67D157} = {385E71CC-BAE5-488B-805E-ACAE55F01DF5} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/Xamarin.Android.sln b/Xamarin.Android.sln index 55041c964a1..2b4d6c3c192 100644 --- a/Xamarin.Android.sln +++ b/Xamarin.Android.sln @@ -96,6 +96,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mono.Android", "src\Mono.An EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mono.Android.Export", "src\Mono.Android.Export\Mono.Android.Export.csproj", "{B8105878-D423-4159-A3E7-028298281EC6}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Android.Build.BaseTasks", "external\xamarin-android-tools\src\Microsoft.Android.Build.BaseTasks\Microsoft.Android.Build.BaseTasks.csproj", "{3DE17662-DCD6-4F49-AF06-D39AACC8649A}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Android.Tools.AndroidSdk", "external\xamarin-android-tools\src\Xamarin.Android.Tools.AndroidSdk\Xamarin.Android.Tools.AndroidSdk.csproj", "{E34BCFA0-CAA4-412C-AA1C-75DB8D67D157}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Android.Tools.AndroidSdk-Tests", "external\xamarin-android-tools\tests\Xamarin.Android.Tools.AndroidSdk-Tests\Xamarin.Android.Tools.AndroidSdk-Tests.csproj", "{1E5501E8-49C1-4659-838D-CC9720C5208F}" @@ -306,6 +308,10 @@ Global {B8105878-D423-4159-A3E7-028298281EC6}.Debug|AnyCPU.Build.0 = Debug|Any CPU {B8105878-D423-4159-A3E7-028298281EC6}.Release|AnyCPU.ActiveCfg = Release|Any CPU {B8105878-D423-4159-A3E7-028298281EC6}.Release|AnyCPU.Build.0 = Release|Any CPU + {3DE17662-DCD6-4F49-AF06-D39AACC8649A}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU + {3DE17662-DCD6-4F49-AF06-D39AACC8649A}.Debug|AnyCPU.Build.0 = Debug|Any CPU + {3DE17662-DCD6-4F49-AF06-D39AACC8649A}.Release|AnyCPU.ActiveCfg = Release|Any CPU + {3DE17662-DCD6-4F49-AF06-D39AACC8649A}.Release|AnyCPU.Build.0 = Release|Any CPU {E34BCFA0-CAA4-412C-AA1C-75DB8D67D157}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU {E34BCFA0-CAA4-412C-AA1C-75DB8D67D157}.Debug|AnyCPU.Build.0 = Debug|Any CPU {E34BCFA0-CAA4-412C-AA1C-75DB8D67D157}.Release|AnyCPU.ActiveCfg = Release|Any CPU @@ -445,6 +451,7 @@ Global {B7A457E6-9CB6-43F6-BFD6-14D5397FB98D} = {864062D3-A415-4A6F-9324-5820237BA058} {66CF299A-CE95-4131-BCD8-DB66E30C4BF7} = {04E3E11E-B47D-4599-8AFC-50515A95E715} {B8105878-D423-4159-A3E7-028298281EC6} = {04E3E11E-B47D-4599-8AFC-50515A95E715} + {3DE17662-DCD6-4F49-AF06-D39AACC8649A} = {04E3E11E-B47D-4599-8AFC-50515A95E715} {E34BCFA0-CAA4-412C-AA1C-75DB8D67D157} = {04E3E11E-B47D-4599-8AFC-50515A95E715} {1E5501E8-49C1-4659-838D-CC9720C5208F} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483} {1BAFA0CC-0377-46CE-AB7B-7BB2E7B62F63} = {04E3E11E-B47D-4599-8AFC-50515A95E715} diff --git a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks.csproj b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks.csproj index b7103c082fe..a405731955f 100644 --- a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks.csproj +++ b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks.csproj @@ -7,7 +7,7 @@ - + diff --git a/build-tools/automation/yaml-templates/run-msbuild-mac-tests.yaml b/build-tools/automation/yaml-templates/run-msbuild-mac-tests.yaml index ad098004c93..b88eb2e0d01 100644 --- a/build-tools/automation/yaml-templates/run-msbuild-mac-tests.yaml +++ b/build-tools/automation/yaml-templates/run-msbuild-mac-tests.yaml @@ -44,13 +44,6 @@ jobs: # Only run these tests on node 2 - ${{ if eq(parameters.run_extra_tests, true) }}: - - template: run-nunit-tests.yaml - parameters: - useDotNet: $(UseDotNet) - testRunTitle: Xamarin.Android.Build.Tests.Commercial - macOS - testAssembly: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/Xamarin.Android.Build.Tests.Commercial.dll - testResultsFile: TestResult-MSBuildTestsCommercial-macOS-$(XA.Build.Configuration).xml - - template: run-nunit-tests.yaml parameters: useDotNet: $(UseDotNet) diff --git a/build-tools/automation/yaml-templates/run-msbuild-win-tests.yaml b/build-tools/automation/yaml-templates/run-msbuild-win-tests.yaml index 7755dd74de9..986e779c7fd 100644 --- a/build-tools/automation/yaml-templates/run-msbuild-win-tests.yaml +++ b/build-tools/automation/yaml-templates/run-msbuild-win-tests.yaml @@ -51,13 +51,6 @@ jobs: # Only run these tests on node 2 - ${{ if eq(parameters.run_extra_tests, true) }}: - - template: run-nunit-tests.yaml - parameters: - useDotNet: $(UseDotNet) - testRunTitle: Xamarin.Android.Build.Tests.Commercial - Windows - testAssembly: $(System.DefaultWorkingDirectory)\bin\Test$(XA.Build.Configuration)\Xamarin.Android.Build.Tests.Commercial.dll - testResultsFile: TestResult-MSBuildTestsCommercial-Windows-$(XA.Build.Configuration).xml - - template: run-nunit-tests.yaml parameters: useDotNet: $(UseDotNet) diff --git a/build-tools/installers/create-installers.targets b/build-tools/installers/create-installers.targets index 7ba8b43976b..e153788d56c 100644 --- a/build-tools/installers/create-installers.targets +++ b/build-tools/installers/create-installers.targets @@ -202,6 +202,8 @@ <_MSBuildFiles Include="$(MSBuildSrcDir)\logcat-parse.pdb" ExcludeFromAndroidNETSdk="true" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\mdoc.exe" ExcludeFromAndroidNETSdk="true" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\mdoc.pdb" ExcludeFromAndroidNETSdk="true" /> + <_MSBuildFiles Include="$(MSBuildSrcDir)\Microsoft.Android.Build.BaseTasks.dll" /> + <_MSBuildFiles Include="$(MSBuildSrcDir)\Microsoft.Android.Build.BaseTasks.pdb" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\mkbundle.exe" ExcludeFromAndroidNETSdk="true" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\mkbundle.pdb" ExcludeFromAndroidNETSdk="true" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\mkbundle-api.h" /> @@ -244,6 +246,7 @@ <_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.Android.Build.Tasks.dll" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.Android.Build.Tasks.pdb" /> <_MSBuildFiles Include="@(_LocalizationLanguages->'$(MSBuildSrcDir)\%(Identity)\Java.Interop.Localization.resources.dll')" /> + <_MSBuildFiles Include="@(_LocalizationLanguages->'$(MSBuildSrcDir)\%(Identity)\Microsoft.Android.Build.BaseTasks.resources.dll')" /> <_MSBuildFiles Include="@(_LocalizationLanguages->'$(MSBuildSrcDir)\%(Identity)\Xamarin.Android.Build.Tasks.resources.dll')" /> <_MSBuildFiles Include="@(_LocalizationLanguages->'$(MSBuildSrcDir)\%(Identity)\Xamarin.Android.Tools.AndroidSdk.resources.dll')" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.Android.BuildInfo.txt" /> diff --git a/build-tools/scripts/BuildEverything.mk b/build-tools/scripts/BuildEverything.mk index 88324820e72..6519508f656 100644 --- a/build-tools/scripts/BuildEverything.mk +++ b/build-tools/scripts/BuildEverything.mk @@ -18,10 +18,11 @@ ifeq ($(PREPARE_CI_PR)$(PREPARE_CI),00) else $(MAKE) prepare endif - $(MAKE) leeroy $(ZIP_OUTPUT) -ifeq ($(XA_INVERTED_COMMERCIAL_BUILD),true) - $(MAKE) commercial +ifneq ("$(wildcard $(topdir)/external/monodroid/Makefile)","") + cd $(topdir)/external/monodroid && ./configure --with-xamarin-android='$(topdir)' + cd $(topdir)/external/monodroid && $(MAKE) build-monodroid CONFIGURATION=$(CONFIGURATION) XAMARIN_ANDROID_PATH=$(topdir) endif + $(MAKE) leeroy $(ZIP_OUTPUT) leeroy: leeroy-all framework-assemblies opentk-jcw diff --git a/build-tools/scripts/MSBuildReferences.projitems b/build-tools/scripts/MSBuildReferences.projitems deleted file mode 100644 index d63948f4b28..00000000000 --- a/build-tools/scripts/MSBuildReferences.projitems +++ /dev/null @@ -1,52 +0,0 @@ - - - 15.1.0.0 - 16.5 - - - - - - - - - - - - - True - $(MSBuildToolsPath)\Microsoft.Build.dll - - - True - $(MSBuildToolsPath)\Microsoft.Build.Framework.dll - - - True - $(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll - - - True - $(MSBuildToolsPath)\Microsoft.Build.Utilities.Core.dll - - - - - - - All - - - - - - - - - - - PreserveNewest - - - diff --git a/build-tools/scripts/Packaging.mk b/build-tools/scripts/Packaging.mk index e43cb9c3e8f..b83c292457d 100644 --- a/build-tools/scripts/Packaging.mk +++ b/build-tools/scripts/Packaging.mk @@ -1,3 +1,10 @@ +# If commercial components exist in output, set required variables +ifneq ("$(wildcard $(topdir)/bin/$(CONFIGURATION)/lib/xamarin.android/xbuild/Xamarin/Android/Xamarin.Android.Common.Debugging.targets)","") +PKG_LICENSE_EN=$(topdir)/external/monodroid/tools/scripts/License.txt +USE_COMMERCIAL_INSTALLER_NAME=true +EXPERIMENTAL=false +endif + create-installers: create-pkg create-vsix create-pkg: diff --git a/build-tools/scripts/PrepareWindows.targets b/build-tools/scripts/PrepareWindows.targets index 0ec7052fec7..83801b9a5bc 100644 --- a/build-tools/scripts/PrepareWindows.targets +++ b/build-tools/scripts/PrepareWindows.targets @@ -15,6 +15,15 @@ DependsOnTargets="_BuildXAPrepare"> + + + <_MonodroidBuildProps Include="-p:Configuration=$(Configuration)" /> + <_MonodroidBuildProps Include="-p:DebuggingToolsOutputDirectory=$(XAInstallPrefix)xbuild\Xamarin\Android" /> + <_MonodroidBuildProps Include="-p:CompatTargetsOutputDirectory=$(XAInstallPrefix)xbuild\Novell" /> + + + - + diff --git a/external/xamarin-android-tools b/external/xamarin-android-tools index 26d65d95943..8ea78a4fb98 160000 --- a/external/xamarin-android-tools +++ b/external/xamarin-android-tools @@ -1 +1 @@ -Subproject commit 26d65d95943b18bb9575d75c8c60ce36180a0db9 +Subproject commit 8ea78a4fb98cf5b30e87dfb6b9f99f485e297412 diff --git a/src-ThirdParty/android-platform-tools-base/SymbolWriter.cs b/src-ThirdParty/android-platform-tools-base/SymbolWriter.cs index 38ce8a11542..f1dd7856e35 100644 --- a/src-ThirdParty/android-platform-tools-base/SymbolWriter.cs +++ b/src-ThirdParty/android-platform-tools-base/SymbolWriter.cs @@ -6,6 +6,7 @@ using System.Text; using Xamarin.Android.Tools; using Xamarin.Build; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -86,7 +87,7 @@ void GenerateJava (Package package) writer.Flush (); var r_java = Path.Combine (output_directory, package.Name.Replace ('.', Path.DirectorySeparatorChar), "R.java"); - if (MonoAndroidHelper.CopyIfStreamChanged (writer.BaseStream, r_java)) { + if (Files.CopyIfStreamChanged (writer.BaseStream, r_java)) { LogDebugMessage ($"Writing: {r_java}"); } else { LogDebugMessage ($"Up to date: {r_java}"); diff --git a/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/OutputStepWithTimestamps.cs b/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/OutputStepWithTimestamps.cs index b4e9c93608b..bd137612f90 100644 --- a/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/OutputStepWithTimestamps.cs +++ b/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/OutputStepWithTimestamps.cs @@ -3,6 +3,7 @@ using Mono.Cecil.Cil; using Mono.Linker.Steps; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace MonoDroid.Tuner { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Aapt.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Aapt.cs index 511f800f2dd..045dfc2e2f4 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Aapt.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Aapt.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2011 Xamarin, Inc. All rights reserved. +// Copyright (C) 2011 Xamarin, Inc. All rights reserved. using System; using System.Diagnostics; @@ -14,6 +14,7 @@ using System.Collections.Generic; using Xamarin.Android.Tools; using Xamarin.Build; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -169,7 +170,7 @@ bool ExecuteForAbi (string cmd, string currentResourceOutputFile) } if (ret && !string.IsNullOrEmpty (currentResourceOutputFile)) { var tmpfile = currentResourceOutputFile + ".bk"; - MonoAndroidHelper.CopyIfZipChanged (tmpfile, currentResourceOutputFile); + Files.CopyIfZipChanged (tmpfile, currentResourceOutputFile); File.Delete (tmpfile); } return ret; diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs index 3df05768d2a..c970b5b706d 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2011 Xamarin, Inc. All rights reserved. +// Copyright (C) 2011 Xamarin, Inc. All rights reserved. using System; using System.Diagnostics; @@ -16,6 +16,7 @@ using Xamarin.Android.Tools; using ThreadingTasks = System.Threading.Tasks; using Xamarin.Build; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2Compile.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2Compile.cs index 1f5a16e68df..d73de408f19 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2Compile.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2Compile.cs @@ -12,6 +12,7 @@ using System.Text.RegularExpressions; using System.Collections.Generic; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2Link.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2Link.cs index e2d4f2ab5c6..74578f992bc 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2Link.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2Link.cs @@ -12,6 +12,7 @@ using System.Text.RegularExpressions; using System.Collections.Generic; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -108,7 +109,7 @@ public async override System.Threading.Tasks.Task RunTaskAsync () if (File.Exists (tmpfile)) { if (aaptResult) { LogDebugMessage ($"Copying {tmpfile} to {currentResourceOutputFile}"); - MonoAndroidHelper.CopyIfZipChanged (tmpfile, currentResourceOutputFile); + Files.CopyIfZipChanged (tmpfile, currentResourceOutputFile); } File.Delete (tmpfile); } @@ -120,7 +121,7 @@ public async override System.Threading.Tasks.Task RunTaskAsync () } } if (!string.IsNullOrEmpty (ProguardRuleOutput)) - MonoAndroidHelper.CopyIfChanged (proguardRuleOutputTemp, ProguardRuleOutput); + Files.CopyIfChanged (proguardRuleOutputTemp, ProguardRuleOutput); } finally { lock (tempFiles) { foreach (var temp in tempFiles) { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/AdjustJavacVersionArguments.cs b/src/Xamarin.Android.Build.Tasks/Tasks/AdjustJavacVersionArguments.cs index ae8b74a48bb..36681abce26 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/AdjustJavacVersionArguments.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/AdjustJavacVersionArguments.cs @@ -1,9 +1,10 @@ -using System; +using System; using Microsoft.Build.Utilities; using Microsoft.Build.Framework; using System.IO; using System.Diagnostics; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidApkSigner.cs b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidApkSigner.cs index 8eda5111c93..dcc47e96054 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidApkSigner.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidApkSigner.cs @@ -1,8 +1,9 @@ -using System; +using System; using System.IO; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidComputeResPaths.cs b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidComputeResPaths.cs index 8da349b88c9..1c1cbf8273b 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidComputeResPaths.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidComputeResPaths.cs @@ -31,6 +31,7 @@ using System.IO; using System.Collections.Generic; using System.Linq; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidDotnetToolTask.cs b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidDotnetToolTask.cs index 52e65d8d0a6..426dee8eaf7 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidDotnetToolTask.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidDotnetToolTask.cs @@ -3,6 +3,7 @@ using System.Runtime.InteropServices; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidError.cs b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidError.cs index 1a68aa50cd2..db43861cf32 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidError.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidError.cs @@ -1,5 +1,6 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidSignPackage.cs b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidSignPackage.cs index 2ba9d735747..d3cfff2ed48 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidSignPackage.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidSignPackage.cs @@ -2,6 +2,7 @@ using System.IO; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidTask.cs b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidTask.cs deleted file mode 100644 index 492872bec83..00000000000 --- a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidTask.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System; -using Microsoft.Build.Utilities; -using Xamarin.Build; -using static System.Threading.Tasks.TaskExtensions; - -namespace Xamarin.Android.Tasks -{ - // We use this task to ensure that no unhandled exceptions - // escape our tasks which would cause an MSB4018 - public abstract class AndroidTask : Task - { - public abstract string TaskPrefix { get; } - - public override bool Execute () - { - try { - return RunTask (); - } catch (Exception ex) { - Log.LogUnhandledException (TaskPrefix, ex); - return false; - } - } - - public abstract bool RunTask (); - } - - public abstract class AndroidAsyncTask : AsyncTask - { - /// - /// A helper for non-async overrides of RunTaskAsync, etc. - /// - public static readonly System.Threading.Tasks.Task Done = - System.Threading.Tasks.Task.FromResult (true); - - public abstract string TaskPrefix { get; } - - [Obsolete ("You should not use the 'Log' property directly for AsyncTask. Use the 'Log*' methods instead.", error: true)] - public new TaskLoggingHelper Log { - get => base.Log; - } - - public override bool Execute () - { - try { - return RunTask (); - } catch (Exception ex) { - this.LogUnhandledException (TaskPrefix, ex); - return false; - } - } - - public virtual bool RunTask () - { - Yield (); - try { - this.RunTask (() => RunTaskAsync ()) - .Unwrap () - .ContinueWith (Complete); - - // This blocks on AsyncTask.Execute, until Complete is called - return base.Execute (); - } finally { - Reacquire (); - } - } - - /// - /// Override this method for simplicity of AsyncTask usage: - /// * Yield / Reacquire is handled for you - /// * RunTaskAsync is already on a background thread - /// - public virtual System.Threading.Tasks.Task RunTaskAsync () => Done; - } - - public abstract class AndroidToolTask : ToolTask - { - public abstract string TaskPrefix { get; } - - public override bool Execute () - { - try { - return RunTask (); - } catch (Exception ex) { - Log.LogUnhandledException (TaskPrefix, ex); - return false; - } - } - - // Most ToolTask's do not override Execute and - // just expect the base to be called - public virtual bool RunTask () => base.Execute (); - } -} diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidToolTask.cs b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidToolTask.cs deleted file mode 100644 index 32d3732fc43..00000000000 --- a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidToolTask.cs +++ /dev/null @@ -1,123 +0,0 @@ -using System; -using System.IO; -using System.Text.RegularExpressions; -using Microsoft.Build.Utilities; -using Microsoft.Build.Framework; - -namespace Xamarin.Android.Tasks -{ - public abstract class AndroidRunToolTask : AndroidToolTask - { - protected static bool IsWindows = Path.DirectorySeparatorChar == '\\'; - - protected abstract string DefaultErrorCode { get; } - - protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance) - { - base.LogEventsFromTextOutput (singleLine, messageImportance); - - if (messageImportance != StandardErrorLoggingImportance) - return; - - Log.LogFromStandardError (DefaultErrorCode, singleLine); - } - - // Disabled because this regex does not match our errors: - // monodroid : error 1: System.InvalidOperationException: PackageName can only contain lowercase alphanumeric characters (regex: [a-z0-9.]). - - // Code from class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolTask.cs - //protected override void LogEventsFromTextOutput (string singleLine, MessageImportance importance) - //{ - // singleLine = singleLine.Trim (); - // if (singleLine.Length == 0) { - // Log.LogMessage (singleLine, importance); - // return; - // } - - // // When IncludeDebugInformation is true, prevents the debug symbols stats from braeking this. - // if (singleLine.StartsWith ("WROTE SYMFILE") || - // singleLine.StartsWith ("OffsetTable") || - // singleLine.StartsWith ("Compilation succeeded") || - // singleLine.StartsWith ("Compilation failed")) - // return; - - // Match match = ErrorRegex.Match (singleLine); - // if (!match.Success) { - // Log.LogMessage (importance, singleLine); - // return; - // } - - // string filename = match.Result ("${file}") ?? ""; - // string line = match.Result ("${line}"); - // int lineNumber = !string.IsNullOrEmpty (line) ? Int32.Parse (line) : 0; - - // string category = match.Result ("${level}"); - // string text = match.Result ("${message}"); - - // if (!Path.IsPathRooted (filename) && !String.IsNullOrEmpty (BaseDirectory)) - // filename = Path.Combine (BaseDirectory, filename); - - // if (String.Compare (category, "warning", StringComparison.OrdinalIgnoreCase) == 0) { - // Log.LogWarning (null, null, null, filename, lineNumber, 0, -1, - // -1, text, null); - // } else if (String.Compare (category, "error", StringComparison.OrdinalIgnoreCase) == 0) { - // Log.LogError (null, null, null, filename, lineNumber, 0, -1, - // -1, text, null); - // } else { - // Log.LogMessage (importance, singleLine); - // } - //} - - protected virtual Regex ErrorRegex { - get { return AndroidErrorRegex; } - } - - /* This gets pre-pended to any filenames that we get from error strings */ - protected string BaseDirectory { get; set; } - - // Aapt errors looks like this: - // res\layout\main.axml:7: error: No resource identifier found for attribute 'id2' in package 'android' (TaskId:22) - // Resources/values/theme.xml(2): error APT0000: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat'. - // Resources/values/theme.xml:2: error APT0000: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat'. - // res/drawable/foo-bar.jpg: Invalid file name: must contain only [a-z0-9_.] - // Warnings can be like this - // aapt2 W 09-17 18:15:27 98796 12879433 ApkAssets.cpp:138] resources.arsc in APK 'android.jar' is compressed. - // Look for them and convert them to MSBuild compatible errors. - static Regex androidErrorRegex; - public static Regex AndroidErrorRegex { - get { - if (androidErrorRegex == null) - androidErrorRegex = new Regex (@" -^ -( # start optional path followed by `:` - (? - (?.+[\\/][^:\(]+) - ( - ([:](?[\d ]+)) - | - (\((?[\d ]+)\)) - )? - ) - \s* - : -)? -( # optional warning|error|aapt2\sW|aapt2.exe\sW: - \s* - (?(warning|error|aapt2\sW|aapt2.exe\sW)[^:]*)\s* - : -)? -\s* -(?.*) -$ -", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase); - return androidErrorRegex; - } - } - - protected static string QuoteString (string value) - { - return string.Format ("\"{0}\"", value); - } - } -} - diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidWarning.cs b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidWarning.cs index 09fa5c7d4bf..098ca830e70 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidWarning.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidWarning.cs @@ -1,5 +1,6 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidZipAlign.cs b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidZipAlign.cs index cd22da215a4..110d239407d 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidZipAlign.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidZipAlign.cs @@ -1,6 +1,7 @@ using System; using System.IO; using Microsoft.Build.Framework; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Aot.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Aot.cs index 80e5e628ab4..b15e28eb5eb 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Aot.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Aot.cs @@ -13,6 +13,7 @@ using Java.Interop.Tools.Diagnostics; using Xamarin.Android.Tools; using Xamarin.Build; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -445,7 +446,7 @@ bool RunAotCompiler (string assembliesPath, string aotCompiler, string aotOption var stdout_completed = new ManualResetEvent (false); var stderr_completed = new ManualResetEvent (false); - using (var sw = new StreamWriter (responseFile, append: false, encoding: MonoAndroidHelper.UTF8withoutBOM)) { + using (var sw = new StreamWriter (responseFile, append: false, encoding: Files.UTF8withoutBOM)) { sw.WriteLine (aotOptions + " " + QuoteFileName (assembly)); } diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/AppendCustomMetadataToItemGroup.cs b/src/Xamarin.Android.Build.Tasks/Tasks/AppendCustomMetadataToItemGroup.cs index 7822aa20f23..ffd28e90201 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/AppendCustomMetadataToItemGroup.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/AppendCustomMetadataToItemGroup.cs @@ -1,9 +1,10 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { public class AppendCustomMetadataToItemGroup : AndroidTask { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs b/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs index af708ca1ea3..297aa863133 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs @@ -17,6 +17,7 @@ using Mono.Cecil; using Xamarin.Android.Tools; using Xamarin.Tools.Zip; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -660,7 +661,7 @@ private void AddNativeLibraries (ArchiveFileList files, string [] supportedAbis) string GetNativeLibraryAbi (ITaskItem lib) { // If Abi is explicitly specified, simply return it. - var lib_abi = MonoAndroidHelper.GetNativeLibraryAbi (lib); + var lib_abi = AndroidRidAbiHelper.GetNativeLibraryAbi (lib); if (string.IsNullOrWhiteSpace (lib_abi)) { Log.LogCodedError ("XA4301", lib.ItemSpec, 0, Properties.Resources.XA4301_ABI, lib.ItemSpec); @@ -689,7 +690,7 @@ private void AddAdditionalNativeLibraries (ArchiveFileList files, string [] supp return; var libs = AdditionalNativeLibraryReferences - .Select (l => new LibInfo { Path = l.ItemSpec, Abi = MonoAndroidHelper.GetNativeLibraryAbi (l) }); + .Select (l => new LibInfo { Path = l.ItemSpec, Abi = AndroidRidAbiHelper.GetNativeLibraryAbi (l) }); AddNativeLibraries (files, supportedAbis, libs); } diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs b/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs index 0549d6ad244..11f760263b4 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs @@ -1,4 +1,4 @@ -using Microsoft.Build.Framework; +using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CalculateAdditionalResourceCacheDirectories.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CalculateAdditionalResourceCacheDirectories.cs index bef66d9a9a9..d33dcb393d6 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CalculateAdditionalResourceCacheDirectories.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CalculateAdditionalResourceCacheDirectories.cs @@ -1,10 +1,11 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.IO; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CalculateLayoutCodeBehind.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CalculateLayoutCodeBehind.cs index 4cd99f816dd..693360ef75f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CalculateLayoutCodeBehind.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CalculateLayoutCodeBehind.cs @@ -12,6 +12,7 @@ using Microsoft.Build.Framework; using Xamarin.Build; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CalculateProjectDependencies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CalculateProjectDependencies.cs index 0f7396f1448..0426d7fd7fb 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CalculateProjectDependencies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CalculateProjectDependencies.cs @@ -1,9 +1,10 @@ -using System; +using System; using System.IO; using System.Collections.Generic; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CheckDuplicateJavaLibraries.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CheckDuplicateJavaLibraries.cs index ef5eb2fcf2f..33429c6ca37 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CheckDuplicateJavaLibraries.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CheckDuplicateJavaLibraries.cs @@ -3,6 +3,7 @@ using System.Linq; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CheckForInvalidResourceFileNames.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CheckForInvalidResourceFileNames.cs index 03d65105421..c90e4831172 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CheckForInvalidResourceFileNames.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CheckForInvalidResourceFileNames.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Diagnostics; using System.IO; using System.Linq; @@ -10,6 +10,7 @@ using System.Text.RegularExpressions; using System.Collections.Generic; using Xamarin.Android.Tasks; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { public class CheckForInvalidResourceFileNames : AndroidTask { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CheckForRemovedItems.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CheckForRemovedItems.cs index 122fb61e046..7d946aebb76 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CheckForRemovedItems.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CheckForRemovedItems.cs @@ -1,9 +1,10 @@ -using System; +using System; using System.IO; using System.Linq; using System.Collections.Generic; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CheckGoogleSdkRequirements.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CheckGoogleSdkRequirements.cs index 4f403d9f74e..9c1196d6b65 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CheckGoogleSdkRequirements.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CheckGoogleSdkRequirements.cs @@ -7,6 +7,7 @@ using Java.Interop.Tools.Cecil; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -58,4 +59,4 @@ public override bool RunTask () return !Log.HasLoggedErrors; } } -} \ No newline at end of file +} diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CheckProjectItems.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CheckProjectItems.cs index 86bd862cb74..86311dda112 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CheckProjectItems.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CheckProjectItems.cs @@ -4,6 +4,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using System.IO; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CilStrip.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CilStrip.cs index 52b7a53a297..f6c4bd4a772 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CilStrip.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CilStrip.cs @@ -6,6 +6,7 @@ using System.Reflection; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ClassParse.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ClassParse.cs index 977d08dacc6..89a05a7318a 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ClassParse.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ClassParse.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Xamarin, Inc. All rights reserved. +// Copyright (C) 2012 Xamarin, Inc. All rights reserved. using System; using System.Collections.Generic; @@ -10,6 +10,7 @@ using System.Text; using Bytecode = Xamarin.Android.Tools.Bytecode; using System.Diagnostics; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -28,7 +29,7 @@ public class ClassParse : AndroidTask public override bool RunTask () { using (var output = new StreamWriter (OutputFile, append: false, - encoding: MonoAndroidHelper.UTF8withoutBOM)) { + encoding: Files.UTF8withoutBOM)) { Bytecode.Log.OnLog = LogEventHandler; var classPath = new Bytecode.ClassPath () { ApiSource = "class-parse", diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CollectLibraryAssets.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CollectLibraryAssets.cs index a1acb8ad5ba..aa5f2be28f8 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CollectLibraryAssets.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CollectLibraryAssets.cs @@ -2,6 +2,7 @@ using System.Linq; using Microsoft.Build.Utilities; using System.IO; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -17,7 +18,7 @@ public override bool RunTask () if (AdditionalAssetDirectories != null) foreach (var dir in AdditionalAssetDirectories) foreach (var file in Directory.GetFiles (dir, "*", SearchOption.AllDirectories)) - MonoAndroidHelper.CopyIfChanged (file, file.Replace (dir, AssetDirectory)); + Files.CopyIfChanged (file, file.Replace (dir, AssetDirectory)); return true; } } diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CollectNonEmptyDirectories.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CollectNonEmptyDirectories.cs index 43125278b01..ab665b9384e 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CollectNonEmptyDirectories.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CollectNonEmptyDirectories.cs @@ -6,6 +6,7 @@ using Microsoft.Build.Utilities; using Microsoft.Build.Framework; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CollectPdbFiles.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CollectPdbFiles.cs index 78de0c91506..7f5f0baa589 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CollectPdbFiles.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CollectPdbFiles.cs @@ -4,6 +4,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CompileNativeAssembly.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CompileNativeAssembly.cs index c3df94a2a14..f084d749819 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CompileNativeAssembly.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CompileNativeAssembly.cs @@ -9,6 +9,7 @@ using Xamarin.Android.Tools; using Xamarin.Build; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CompileToDalvik.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CompileToDalvik.cs index bccfd9dcae3..dd0357dbc4e 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CompileToDalvik.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CompileToDalvik.cs @@ -9,6 +9,7 @@ using Microsoft.Build.Utilities; using Microsoft.Build.Framework; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -117,7 +118,7 @@ protected override string GenerateCommandLineCommands () cmd.AppendSwitchIfNotNull ("--output ", ClassesOutputDirectory); using (var sw = new StreamWriter (path: inputListFile, append: false, - encoding: MonoAndroidHelper.UTF8withoutBOM)) { + encoding: Files.UTF8withoutBOM)) { // .jar files if (AlternativeJarFiles != null && AlternativeJarFiles.Any ()) { Log.LogDebugMessage (" processing AlternativeJarFiles..."); diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ComputeHash.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ComputeHash.cs index 29d909ba62f..5dcd51f53df 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ComputeHash.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ComputeHash.cs @@ -2,6 +2,7 @@ using Microsoft.Build.Utilities; using Microsoft.Build.Framework; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ConvertCustomView.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ConvertCustomView.cs index 47a6caabea4..417b782cf01 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ConvertCustomView.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ConvertCustomView.cs @@ -9,6 +9,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Monodroid; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { public class ConvertCustomView : AndroidTask { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ConvertDebuggingFiles.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ConvertDebuggingFiles.cs index 46cb79c4d76..edb79829e5c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ConvertDebuggingFiles.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ConvertDebuggingFiles.cs @@ -4,6 +4,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Pdb2Mdb; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -28,7 +29,7 @@ public override bool RunTask () continue; try { - MonoAndroidHelper.SetWriteable (pdb); + Microsoft.Android.Build.Tasks.Files.SetWriteable (pdb); Converter.Convert (Path.ChangeExtension (pdb, ".dll")); convertedFiles.Add (new TaskItem (Path.ChangeExtension (pdb, ".dll"))); } catch (Exception ex) { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ConvertResourcesCases.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ConvertResourcesCases.cs index 59f7b368a03..e9655833993 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ConvertResourcesCases.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ConvertResourcesCases.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2011 Xamarin, Inc. All rights reserved. +// Copyright (C) 2011 Xamarin, Inc. All rights reserved. using System; using System.Diagnostics; @@ -8,6 +8,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Monodroid; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -87,7 +88,7 @@ void FixupResources (ITaskItem item) continue; } Log.LogDebugMessage (" Processing: {0} {1} > {2}", file, srcmodifiedDate, lastUpdate); - MonoAndroidHelper.SetWriteable (file); + Files.SetWriteable (file); bool success = AndroidResource.UpdateXmlResource (resdir, file, resourcedirectories, (level, message) => { switch (level) { @@ -119,7 +120,7 @@ void FixupResources (ITaskItem item) // doesn't support those type of BOM (it really wants the document to start // with " 0) { var archivePath = ".net/__res_name_case_map.txt"; - aar.AddEntry (archivePath, nameCaseMap.ToString (), MonoAndroidHelper.UTF8withoutBOM); + aar.AddEntry (archivePath, nameCaseMap.ToString (), Files.UTF8withoutBOM); existingEntries.Remove (archivePath); } } @@ -92,7 +93,7 @@ public override bool RunTask () } if (NativeLibraries != null) { foreach (var lib in NativeLibraries) { - var abi = MonoAndroidHelper.GetNativeLibraryAbi (lib); + var abi = AndroidRidAbiHelper.GetNativeLibraryAbi (lib); if (string.IsNullOrWhiteSpace (abi)) { Log.LogCodedError ("XA4301", lib.ItemSpec, 0, Properties.Resources.XA4301_ABI, lib.ItemSpec); continue; diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CreateAdditionalLibraryResourceCache.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CreateAdditionalLibraryResourceCache.cs index 0015aa94006..8db9e91610f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CreateAdditionalLibraryResourceCache.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CreateAdditionalLibraryResourceCache.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.IO; @@ -7,6 +7,7 @@ using System.Text.RegularExpressions; using Microsoft.Build.Utilities; using Microsoft.Build.Framework; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -39,7 +40,7 @@ public override bool RunTask () foreach (string newPath in Directory.EnumerateFiles (src, "*", SearchOption.AllDirectories)) { var destPath = newPath.Replace (src, dest); var cachedDate = File.GetLastWriteTimeUtc (src); - MonoAndroidHelper.CopyIfChanged (newPath, destPath); + Files.CopyIfChanged (newPath, destPath); copiedResources.Add (new TaskItem (destPath)); } } diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CreateLibraryResourceArchive.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CreateLibraryResourceArchive.cs index 531f97d4e28..7ad71bb84d5 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CreateLibraryResourceArchive.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CreateLibraryResourceArchive.cs @@ -11,6 +11,7 @@ using Xamarin.Tools.Zip; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -118,7 +119,7 @@ bool CopyLibraryContent (string projdir, bool isAar) foreach (var file in Directory.GetFiles (projdir)) { string dstpath = Path.Combine (dstdir, Path.GetFileName (file)); if (!File.Exists (dstpath)) - MonoAndroidHelper.CopyIfChanged (file, dstpath); + Files.CopyIfChanged (file, dstpath); } } return true; @@ -130,15 +131,15 @@ void CopyFiles (string srcdir) if (file.EndsWith (".jar", StringComparison.OrdinalIgnoreCase)) { var dstpath = Path.Combine (OutputJarsDirectory, Path.GetFileName (file)); if (!File.Exists (dstpath)) - MonoAndroidHelper.CopyIfChanged (file, dstpath); + Files.CopyIfChanged (file, dstpath); } else if (file.EndsWith ("annotations.zip", StringComparison.OrdinalIgnoreCase)) { var dstpath = Path.Combine (OutputAnnotationsDirectory, Path.GetFileName (file)); if (!File.Exists (dstpath)) - MonoAndroidHelper.CopyIfChanged (file, dstpath); + Files.CopyIfChanged (file, dstpath); } else { var dstpath = Path.Combine (OutputDirectory, Path.GetFileName (file)); if (!File.Exists (dstpath)) - MonoAndroidHelper.CopyIfChanged (file, dstpath); + Files.CopyIfChanged (file, dstpath); } } } @@ -155,7 +156,7 @@ static void CopyDirectory (DirectoryInfo srcSubdirInfo, string dst, bool top) CopyDirectory (subsub, dstsub, false); } foreach (var file in srcSubdirInfo.GetFiles ()) - MonoAndroidHelper.CopyIfChanged (file.FullName, Path.Combine (dstsub, file.Name)); + Files.CopyIfChanged (file.FullName, Path.Combine (dstsub, file.Name)); } IEnumerable ResolveLibraryProjectReferences (IEnumerable inputs) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CreateManagedLibraryResourceArchive.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CreateManagedLibraryResourceArchive.cs index 3eab4dc21f6..9c993463cc0 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CreateManagedLibraryResourceArchive.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CreateManagedLibraryResourceArchive.cs @@ -5,6 +5,7 @@ using Microsoft.Build.Framework; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -55,7 +56,7 @@ public override bool RunTask () var compiledArchive = Path.Combine (FlatArchivesDirectory, "compiled.flata"); if (File.Exists (compiledArchive)) { Log.LogDebugMessage ($"Coping: {compiledArchive} to {outDirInfo.FullName}"); - MonoAndroidHelper.CopyIfChanged (compiledArchive, Path.Combine (outDirInfo.FullName, "compiled.flata")); + Files.CopyIfChanged (compiledArchive, Path.Combine (outDirInfo.FullName, "compiled.flata")); } if (AndroidAssets != null) { @@ -64,7 +65,7 @@ public override bool RunTask () Directory.CreateDirectory (dstsub); foreach (var item in AndroidAssets) { var path = MonoAndroidHelper.GetRelativePathForAndroidAsset (MonoAndroidAssetsPrefix, item); - MonoAndroidHelper.CopyIfChanged (item.ItemSpec, Path.Combine (dstsub, path)); + Files.CopyIfChanged (item.ItemSpec, Path.Combine (dstsub, path)); } } // resources folders are converted to the structure that aapt accepts. @@ -74,7 +75,7 @@ public override bool RunTask () Directory.CreateDirectory (dstsub); foreach (var file in Directory.GetFiles (srcsub)) { var filename = Path.GetFileName (file); - MonoAndroidHelper.CopyIfChanged (file, Path.Combine (dstsub, Path.GetFileName (file))); + Files.CopyIfChanged (file, Path.Combine (dstsub, Path.GetFileName (file))); } } if (RemovedAndroidResourceFiles != null) { @@ -89,10 +90,10 @@ public override bool RunTask () } if (AndroidJavaSources != null) foreach (var item in AndroidJavaSources) - MonoAndroidHelper.CopyIfChanged (item.ItemSpec, Path.Combine (outDirInfo.FullName, item.ItemSpec)); + Files.CopyIfChanged (item.ItemSpec, Path.Combine (outDirInfo.FullName, item.ItemSpec)); if (AndroidJavaLibraries != null) foreach (var item in AndroidJavaLibraries) - MonoAndroidHelper.CopyIfChanged (item.ItemSpec, Path.Combine (outDirInfo.FullName, item.ItemSpec)); + Files.CopyIfChanged (item.ItemSpec, Path.Combine (outDirInfo.FullName, item.ItemSpec)); var nameCaseMap = new StringWriter (); diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CreateMsymManifest.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CreateMsymManifest.cs index 8e3d4aa0e27..af80809e77a 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CreateMsymManifest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CreateMsymManifest.cs @@ -1,8 +1,9 @@ -using System; +using System; using Microsoft.Build.Utilities; using Microsoft.Build.Framework; using System.Xml.Linq; using System.IO; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CreateMultiDexMainDexClassList.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CreateMultiDexMainDexClassList.cs index d7937d24d87..b70fcc46f60 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CreateMultiDexMainDexClassList.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CreateMultiDexMainDexClassList.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2011 Xamarin, Inc. All rights reserved. +// Copyright (C) 2011 Xamarin, Inc. All rights reserved. using System; using System.Collections.Generic; @@ -10,6 +10,7 @@ using Microsoft.Build.Framework; using System.Collections.Specialized; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CreateNativeLibraryArchive.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CreateNativeLibraryArchive.cs index 598d9236704..6c89c01f0d5 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CreateNativeLibraryArchive.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CreateNativeLibraryArchive.cs @@ -5,6 +5,7 @@ using Microsoft.Build.Framework; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -34,7 +35,7 @@ public override bool RunTask () outDirInfo.Create (); foreach (var lib in EmbeddedNativeLibraries) { // seealso bug #3477 to find out why we use this method. - var abi = MonoAndroidHelper.GetNativeLibraryAbi (lib); + var abi = AndroidRidAbiHelper.GetNativeLibraryAbi (lib); if (abi == null) { Log.LogWarning ( subcategory: string.Empty, @@ -54,7 +55,7 @@ public override bool RunTask () } if (!outDirInfo.GetDirectories (abi).Any ()) outDirInfo.CreateSubdirectory (abi); - MonoAndroidHelper.CopyIfChanged (lib.ItemSpec, Path.Combine (OutputDirectory, abi, Path.GetFileName (lib.ItemSpec))); + Files.CopyIfChanged (lib.ItemSpec, Path.Combine (OutputDirectory, abi, Path.GetFileName (lib.ItemSpec))); } var outpath = Path.Combine (outDirInfo.Parent.FullName, "__AndroidNativeLibraries__.zip"); diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CreateResgenManifest.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CreateResgenManifest.cs index d6d2884904a..3efca94f6e8 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CreateResgenManifest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CreateResgenManifest.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2011 Xamarin, Inc. All rights reserved. +// Copyright (C) 2011 Xamarin, Inc. All rights reserved. using System; using System.IO; @@ -8,6 +8,7 @@ using Microsoft.Build.Utilities; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CreateTemporaryDirectory.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CreateTemporaryDirectory.cs index 58e0696a214..2e7886373f0 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CreateTemporaryDirectory.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CreateTemporaryDirectory.cs @@ -1,9 +1,10 @@ -// Copyright (C) 2011 Xamarin, Inc. All rights reserved. +// Copyright (C) 2011 Xamarin, Inc. All rights reserved. using System; using System.IO; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/D8.cs b/src/Xamarin.Android.Build.Tasks/Tasks/D8.cs index 4819e6f705a..5c3123c9a40 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/D8.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/D8.cs @@ -4,6 +4,7 @@ using System.IO; using System.Text.RegularExpressions; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/DetermineJavaLibrariesToCompile.cs b/src/Xamarin.Android.Build.Tasks/Tasks/DetermineJavaLibrariesToCompile.cs index 4d88c03be68..ea060e42bf4 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/DetermineJavaLibrariesToCompile.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/DetermineJavaLibrariesToCompile.cs @@ -1,10 +1,11 @@ -using System; +using System; using Microsoft.Build.Utilities; using System.Collections.Generic; using Microsoft.Build.Framework; using System.Linq; using System.IO; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ExtractJarsFromAar.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ExtractJarsFromAar.cs index 124b866a9fe..bb8a9601182 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ExtractJarsFromAar.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ExtractJarsFromAar.cs @@ -4,6 +4,7 @@ using Microsoft.Build.Framework; using Xamarin.Android.Tools; using Xamarin.Tools.Zip; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -70,7 +71,7 @@ static void Extract (ZipEntry entry, MemoryStream stream, string destination) { stream.SetLength (0); //Reuse the stream entry.Extract (stream); - MonoAndroidHelper.CopyIfStreamChanged (stream, destination); + Files.CopyIfStreamChanged (stream, destination); } void DeleteUnknownFiles (string directory, HashSet knownFiles) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/FilterAssemblies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/FilterAssemblies.cs index 4b9861dd60e..4034e9425f7 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/FilterAssemblies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/FilterAssemblies.cs @@ -1,10 +1,11 @@ -using Microsoft.Build.Framework; +using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using System; using System.Collections.Generic; using System.IO; using System.Reflection.Metadata; using System.Reflection.PortableExecutable; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/FindLayoutsToBind.cs b/src/Xamarin.Android.Build.Tasks/Tasks/FindLayoutsToBind.cs index 2e987e89e3b..6d9af862b0e 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/FindLayoutsToBind.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/FindLayoutsToBind.cs @@ -6,6 +6,7 @@ using Microsoft.Build.Utilities; using Microsoft.Build.Framework; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/FixupNuGetReferences.cs b/src/Xamarin.Android.Build.Tasks/Tasks/FixupNuGetReferences.cs index 7e0f423b4b0..d1cccb614a6 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/FixupNuGetReferences.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/FixupNuGetReferences.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using Microsoft.Build.Framework; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateCompressedAssembliesNativeSourceFiles.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateCompressedAssembliesNativeSourceFiles.cs index 0ee4e172520..578cae5d995 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateCompressedAssembliesNativeSourceFiles.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateCompressedAssembliesNativeSourceFiles.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using Microsoft.Build.Framework; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -81,7 +82,7 @@ void Generate (IDictionary dict) using (var sw = MemoryStreamPool.Shared.CreateStreamWriter ()) { asmgen.Write (sw); sw.Flush (); - if (MonoAndroidHelper.CopyIfStreamChanged (sw.BaseStream, asmFilePath)) { + if (Files.CopyIfStreamChanged (sw.BaseStream, asmFilePath)) { Log.LogDebugMessage ($"File {asmFilePath} was regenerated"); } } diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs index 439bae8af3a..0bc8cd00396 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2011 Xamarin, Inc. All rights reserved. +// Copyright (C) 2011 Xamarin, Inc. All rights reserved. using System; using System.Collections.Generic; @@ -18,6 +18,7 @@ using Java.Interop.Tools.TypeNameMappings; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -241,7 +242,7 @@ void Run (DirectoryAssemblyResolver res) } acw_map.Flush (); - MonoAndroidHelper.CopyIfStreamChanged (acw_map.BaseStream, AcwMapFile); + Files.CopyIfStreamChanged (acw_map.BaseStream, AcwMapFile); } foreach (var kvp in managedConflicts) { @@ -297,7 +298,7 @@ void Run (DirectoryAssemblyResolver res) foreach (var provider in additionalProviders) { var contents = providerTemplate.Replace ("MonoRuntimeProvider", provider); var real_provider = Path.Combine (OutputDirectory, "src", "mono", provider + ".java"); - MonoAndroidHelper.CopyIfStringChanged (contents, real_provider); + Files.CopyIfStringChanged (contents, real_provider); } // Create additional application java sources. @@ -339,7 +340,7 @@ bool CreateJavaSources (IEnumerable javaTypes, TypeDefinitionCac writer.Flush (); var path = jti.GetDestinationPath (outputPath); - MonoAndroidHelper.CopyIfStreamChanged (writer.BaseStream, path); + Files.CopyIfStreamChanged (writer.BaseStream, path); if (jti.HasExport && !hasExportReference) Diagnostic.Error (4210, Properties.Resources.XA4210); } catch (XamarinAndroidException xae) { @@ -411,7 +412,7 @@ void SaveResource (string resource, string filename, string destDir, Func types, TypeDefinitionCache cache) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateLayoutBindings.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateLayoutBindings.cs index 77aeed0a159..c919dc3e1eb 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateLayoutBindings.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateLayoutBindings.cs @@ -12,6 +12,7 @@ using Microsoft.Build.Framework; using Xamarin.Build; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -275,7 +276,7 @@ bool GenerateSource (BindingGenerator generator, string outputFilePath, ICollect } } if (result) - MonoAndroidHelper.CopyIfChanged (tempFile, outputFilePath); + Files.CopyIfChanged (tempFile, outputFilePath); } finally { if (File.Exists (tempFile)) File.Delete (tempFile); diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateLibraryResources.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateLibraryResources.cs index 2c1cf78c8ec..b29c6d6fc44 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateLibraryResources.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateLibraryResources.cs @@ -6,6 +6,7 @@ using System.Text; using Xamarin.Android.Tools; using Xamarin.Build; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateManagedAidlProxies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateManagedAidlProxies.cs index 641952f4b90..58ba89e5182 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateManagedAidlProxies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateManagedAidlProxies.cs @@ -10,6 +10,7 @@ using Microsoft.Build.Utilities; using Monodroid; using Xamarin.Android.Tools.Aidl; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GeneratePackageManagerJava.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GeneratePackageManagerJava.cs index a8ac964a84e..872f7c171c8 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GeneratePackageManagerJava.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GeneratePackageManagerJava.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2011 Xamarin, Inc. All rights reserved. +// Copyright (C) 2011 Xamarin, Inc. All rights reserved. using System; using System.Collections.Generic; @@ -11,6 +11,7 @@ using Java.Interop.Tools.TypeNameMappings; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -123,7 +124,7 @@ public override bool RunTask () // Only copy to the real location if the contents actually changed var dest = Path.GetFullPath (Path.Combine (OutputDirectory, "MonoPackageManager_Resources.java")); - MonoAndroidHelper.CopyIfStreamChanged (pkgmgr.BaseStream, dest); + Files.CopyIfStreamChanged (pkgmgr.BaseStream, dest); } AddEnvironment (); @@ -283,7 +284,7 @@ void AddEnvironment () using (var sw = MemoryStreamPool.Shared.CreateStreamWriter ()) { asmgen.Write (sw); sw.Flush (); - MonoAndroidHelper.CopyIfStreamChanged (sw.BaseStream, asmFilePath); + Files.CopyIfStreamChanged (sw.BaseStream, asmFilePath); } } diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesigner.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesigner.cs index 5804b4b3461..aa8da21e949 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesigner.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesigner.cs @@ -7,6 +7,7 @@ using System.Linq; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -234,7 +235,7 @@ private void WriteFile (string file, CodeTypeDeclaration resources, string langu code = o.ToString (); } - if (MonoAndroidHelper.CopyIfStringChanged (code, file)) { + if (Files.CopyIfStringChanged (code, file)) { Log.LogDebugMessage ($"Writing to: {file}"); } } diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Generator.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Generator.cs index 78ab8091c0a..f7fc458989c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Generator.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Generator.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Xml.Linq; using Microsoft.Build.Framework; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -123,7 +124,7 @@ protected override string GenerateCommandLineCommands () string responseFile = Path.Combine (OutputDirectory, "generator.rsp"); Log.LogDebugMessage ("[Generator] response file: {0}", responseFile); - using (var sw = new StreamWriter (responseFile, append: false, encoding: MonoAndroidHelper.UTF8withoutBOM)) { + using (var sw = new StreamWriter (responseFile, append: false, encoding: Files.UTF8withoutBOM)) { if (OnlyRunXmlAdjuster) WriteLine (sw, "--only-xml-adjuster"); diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetAndroidActivityName.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetAndroidActivityName.cs index b594d520c83..9c491f3f317 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetAndroidActivityName.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetAndroidActivityName.cs @@ -1,5 +1,6 @@ using Microsoft.Build.Framework; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetAndroidDefineConstants.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetAndroidDefineConstants.cs index babadef60ec..fb0059f8fd2 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetAndroidDefineConstants.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetAndroidDefineConstants.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2011 Xamarin, Inc. All rights reserved. +// Copyright (C) 2011 Xamarin, Inc. All rights reserved. using System; using System.Collections.Generic; @@ -6,6 +6,7 @@ using System.Text.RegularExpressions; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetAndroidPackageName.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetAndroidPackageName.cs index 15f0f5a28b4..ad6b8c0eb50 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetAndroidPackageName.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetAndroidPackageName.cs @@ -1,4 +1,4 @@ -// +// // GetAndroidPackageName.cs // // Author: @@ -28,6 +28,7 @@ using System.Xml; using Microsoft.Build.Framework; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetAppSettingsDirectory.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetAppSettingsDirectory.cs index 466328045e7..936e688ee7e 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetAppSettingsDirectory.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetAppSettingsDirectory.cs @@ -5,6 +5,7 @@ using System.IO; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetConvertedJavaLibraries.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetConvertedJavaLibraries.cs index cff79a0bd2a..334b17165f0 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetConvertedJavaLibraries.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetConvertedJavaLibraries.cs @@ -2,6 +2,7 @@ using System.Linq; using Microsoft.Build.Framework; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetExtraPackages.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetExtraPackages.cs index de70c2dcb0b..b0bdc493019 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetExtraPackages.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetExtraPackages.cs @@ -5,6 +5,7 @@ using System.Xml.Linq; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetFilesThatExist.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetFilesThatExist.cs index 9d7e542fd8f..549b65ddbfc 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetFilesThatExist.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetFilesThatExist.cs @@ -1,10 +1,11 @@ -// Copyright (C) 2011 Xamarin, Inc. All rights reserved. +// Copyright (C) 2011 Xamarin, Inc. All rights reserved. using System; using System.IO; using System.Linq; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetImportedLibraries.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetImportedLibraries.cs index 1bccfd79468..e3b3bd46861 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetImportedLibraries.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetImportedLibraries.cs @@ -5,6 +5,7 @@ using System.Xml.Linq; using Microsoft.Build.Utilities; using Microsoft.Build.Framework; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -44,7 +45,7 @@ public override bool RunTask () var jarFiles = new List (); foreach (var file in Directory.EnumerateFiles (TargetDirectory, "*", SearchOption.AllDirectories)) { if (file.EndsWith (".so", StringComparison.OrdinalIgnoreCase)) { - if (MonoAndroidHelper.GetNativeLibraryAbi (file) != null) + if (AndroidRidAbiHelper.GetNativeLibraryAbi (file) != null) nativeLibraries.Add (new TaskItem (file)); } else if (file.EndsWith (".jar", StringComparison.OrdinalIgnoreCase)) { jarFiles.Add (new TaskItem (file)); diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetJavaPlatformJar.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetJavaPlatformJar.cs index b0a50ebdf9a..879db6f1e49 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetJavaPlatformJar.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetJavaPlatformJar.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2011 Xamarin, Inc. All rights reserved. +// Copyright (C) 2011 Xamarin, Inc. All rights reserved. using System; using System.IO; @@ -8,6 +8,7 @@ using Microsoft.Build.Utilities; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetMonoPlatformJar.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetMonoPlatformJar.cs index 548ce1d9bd7..f5ccd593eb6 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetMonoPlatformJar.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetMonoPlatformJar.cs @@ -1,9 +1,10 @@ -// Copyright (C) 2011 Xamarin, Inc. All rights reserved. +// Copyright (C) 2011 Xamarin, Inc. All rights reserved. using System; using System.IO; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/JarToXml.cs b/src/Xamarin.Android.Build.Tasks/Tasks/JarToXml.cs index 436ea9932fe..64be3e65389 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/JarToXml.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/JarToXml.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Xamarin, Inc. All rights reserved. +// Copyright (C) 2012 Xamarin, Inc. All rights reserved. using System; using System.Linq; @@ -7,6 +7,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/JavaCompileToolTask.cs b/src/Xamarin.Android.Build.Tasks/Tasks/JavaCompileToolTask.cs index 1ac9bd4436a..27e41a9e306 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/JavaCompileToolTask.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/JavaCompileToolTask.cs @@ -8,6 +8,7 @@ using System.Text; using System.Collections.Generic; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -58,7 +59,7 @@ private void GenerateResponseFile () TemporarySourceListFile = Path.GetTempFileName (); using (var sw = new StreamWriter (path:TemporarySourceListFile, append:false, - encoding: MonoAndroidHelper.UTF8withoutBOM)) { + encoding: Files.UTF8withoutBOM)) { WriteOptionsToResponseFile (sw); // Include any user .java files diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/JavaDoc.cs b/src/Xamarin.Android.Build.Tasks/Tasks/JavaDoc.cs index a139415efed..4cdf9307339 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/JavaDoc.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/JavaDoc.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using System.IO; using Microsoft.Build.Framework; @@ -7,6 +7,7 @@ using System.Collections.Generic; using Xamarin.Android.Tools; using Xamarin.Android.Tools.Aidl; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/JavaSourceUtils.cs b/src/Xamarin.Android.Build.Tasks/Tasks/JavaSourceUtils.cs index b7a47426479..d22ba15b1e2 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/JavaSourceUtils.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/JavaSourceUtils.cs @@ -7,6 +7,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -96,7 +97,7 @@ string CreateResponseFile () { var responseFile = Path.GetTempFileName (); - using var response = new StreamWriter (responseFile, append: false, encoding: MonoAndroidHelper.UTF8withoutBOM); + using var response = new StreamWriter (responseFile, append: false, encoding: Files.UTF8withoutBOM); Log.LogDebugMessage ("[java-source-utils] response file contents: {0}", responseFile); if (BootClassPath != null && BootClassPath.Any ()) { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/JavaToolTask.cs b/src/Xamarin.Android.Build.Tasks/Tasks/JavaToolTask.cs index 86ab08ad20b..3dddd10d575 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/JavaToolTask.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/JavaToolTask.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.IO; @@ -7,7 +7,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Xamarin.Android.Tools; - +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/KeyTool.cs b/src/Xamarin.Android.Build.Tasks/Tasks/KeyTool.cs index 68ffd1dfdfd..141e54af057 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/KeyTool.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/KeyTool.cs @@ -2,6 +2,7 @@ using System.IO; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Legacy/ResolveAndroidTooling.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Legacy/ResolveAndroidTooling.cs index ba7972a4aea..119c069d041 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Legacy/ResolveAndroidTooling.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Legacy/ResolveAndroidTooling.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using Microsoft.Build.Framework; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks.Legacy { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Legacy/ValidateJavaVersion.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Legacy/ValidateJavaVersion.cs index d26907eee56..2494270e4d7 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Legacy/ValidateJavaVersion.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Legacy/ValidateJavaVersion.cs @@ -2,6 +2,7 @@ using Microsoft.Build.Utilities; using System; using System.Text.RegularExpressions; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks.Legacy { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/LinkApplicationSharedLibraries.cs b/src/Xamarin.Android.Build.Tasks/Tasks/LinkApplicationSharedLibraries.cs index 28a45b25a4e..8b8ff883a20 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/LinkApplicationSharedLibraries.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/LinkApplicationSharedLibraries.cs @@ -9,6 +9,7 @@ using Xamarin.Android.Tools; using Xamarin.Build; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssemblies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssemblies.cs index a401482ce84..b840f46397c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssemblies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssemblies.cs @@ -15,6 +15,7 @@ using Java.Interop.Tools.Cecil; using Java.Interop.Tools.Diagnostics; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs b/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs index 192e5c96274..2a5919d8868 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs @@ -6,6 +6,7 @@ using System.IO; using MTProfile = Mono.Tuner.Profile; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs index e910eab755d..b2bce439563 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using System.Text.RegularExpressions; @@ -8,6 +8,7 @@ using Xamarin.Android.Tools; using System.Collections.Generic; using System.Text; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/LogErrorsForFiles.cs b/src/Xamarin.Android.Build.Tasks/Tasks/LogErrorsForFiles.cs index e8dd511a728..a16751efdd6 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/LogErrorsForFiles.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/LogErrorsForFiles.cs @@ -1,6 +1,7 @@ -using System; +using System; using Microsoft.Build.Utilities; using Microsoft.Build.Framework; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/LogWarningsForFiles.cs b/src/Xamarin.Android.Build.Tasks/Tasks/LogWarningsForFiles.cs index 51603adc570..2a4dc3bccdb 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/LogWarningsForFiles.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/LogWarningsForFiles.cs @@ -1,6 +1,7 @@ -using System; +using System; using Microsoft.Build.Utilities; using Microsoft.Build.Framework; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/MDoc.cs b/src/Xamarin.Android.Build.Tasks/Tasks/MDoc.cs index a3fd0f349da..3ad64a005d7 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/MDoc.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/MDoc.cs @@ -5,6 +5,7 @@ using Microsoft.Build.Utilities; using Xamarin.Android.Tools; using Xamarin.Android.Tools.Aidl; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/MakeBundleNativeCodeExternal.cs b/src/Xamarin.Android.Build.Tasks/Tasks/MakeBundleNativeCodeExternal.cs index 7c52ced2d20..36cb78917ae 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/MakeBundleNativeCodeExternal.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/MakeBundleNativeCodeExternal.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; @@ -12,6 +12,7 @@ using Java.Interop.Tools.Diagnostics; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ManifestMerger.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ManifestMerger.cs index 7d55ac50316..11623fbc9bd 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ManifestMerger.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ManifestMerger.cs @@ -6,6 +6,7 @@ using System.Xml.Linq; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -44,7 +45,7 @@ public override bool Execute () var ms = MemoryStreamPool.Shared.Rent (); try { m.Save (Log, ms, removeNodes: true); - if (!MonoAndroidHelper.CopyIfStreamChanged (ms, OutputManifestFile)) { + if (!Files.CopyIfStreamChanged (ms, OutputManifestFile)) { // NOTE: We still need to update the timestamp on this file, or the target would run again File.SetLastWriteTimeUtc (OutputManifestFile, DateTime.UtcNow); } diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/MonoSymbolicate.cs b/src/Xamarin.Android.Build.Tasks/Tasks/MonoSymbolicate.cs index 189f2006505..68875b7002c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/MonoSymbolicate.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/MonoSymbolicate.cs @@ -3,6 +3,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/NdkUtils.cs b/src/Xamarin.Android.Build.Tasks/Tasks/NdkUtils.cs index e4548923d8a..cb474972230 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/NdkUtils.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/NdkUtils.cs @@ -12,6 +12,7 @@ using Java.Interop.Tools.Diagnostics; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ParseAndroidWearProjectAndManifest.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ParseAndroidWearProjectAndManifest.cs index 16be2d7e7f0..11453afa119 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ParseAndroidWearProjectAndManifest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ParseAndroidWearProjectAndManifest.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Linq; using Microsoft.Build.Utilities; @@ -7,6 +7,7 @@ using Xamarin.Android.Tools; using Xamarin.Android.Tools.Aidl; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/PrepareAbiItems.cs b/src/Xamarin.Android.Build.Tasks/Tasks/PrepareAbiItems.cs index 7d585d61832..574f01d36f6 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/PrepareAbiItems.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/PrepareAbiItems.cs @@ -4,6 +4,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/PrepareWearApplicationFiles.cs b/src/Xamarin.Android.Build.Tasks/Tasks/PrepareWearApplicationFiles.cs index 574cc9d2842..62d60299c53 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/PrepareWearApplicationFiles.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/PrepareWearApplicationFiles.cs @@ -4,6 +4,7 @@ using System.Xml.Linq; using Xamarin.Android.Tools; using System.Collections.Generic; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -51,7 +52,7 @@ public override bool RunTask () ", wearPackageName, doc.Root.Attribute (androidNs + "versionCode").Value, doc.Root.Attribute (androidNs + "versionName").Value, Path.GetFileNameWithoutExtension (rawapk)); - if (MonoAndroidHelper.CopyIfChanged (WearApplicationApkPath, intermediateApkPath)) { + if (Files.CopyIfChanged (WearApplicationApkPath, intermediateApkPath)) { Log.LogDebugMessage (" Copied APK to {0}", intermediateApkPath); modified.Add (intermediateApkPath); } diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ProcessAssemblies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ProcessAssemblies.cs index 4a3d2619376..36aebb4b47f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ProcessAssemblies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ProcessAssemblies.cs @@ -6,6 +6,7 @@ using System.Reflection.PortableExecutable; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -128,7 +129,7 @@ bool Filter (ITaskItem assembly) void SetDestinationSubDirectory (ITaskItem assembly, string fileName, ITaskItem symbol) { var rid = assembly.GetMetadata ("RuntimeIdentifier"); - var abi = MonoAndroidHelper.RuntimeIdentifierToAbi (rid); + var abi = AndroidRidAbiHelper.RuntimeIdentifierToAbi (rid); if (!string.IsNullOrEmpty (abi)) { string destination = Path.Combine (assembly.GetMetadata ("DestinationSubDirectory"), abi); assembly.SetMetadata ("DestinationSubDirectory", destination + Path.DirectorySeparatorChar); diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ProcessNativeLibraries.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ProcessNativeLibraries.cs index 67f6e95612c..0b475a1b85d 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ProcessNativeLibraries.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ProcessNativeLibraries.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using Microsoft.Build.Framework; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -32,7 +33,7 @@ public override bool RunTask () var output = new List (InputLibraries.Length); foreach (var library in InputLibraries) { - var abi = MonoAndroidHelper.GetNativeLibraryAbi (library); + var abi = AndroidRidAbiHelper.GetNativeLibraryAbi (library); if (string.IsNullOrEmpty (abi)) { var packageId = library.GetMetadata ("NuGetPackageId"); if (!string.IsNullOrEmpty (packageId)) { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs index 41dee9e71d8..8dd86522e3c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs @@ -15,6 +15,7 @@ using Xamarin.Android.Tools; using System.IO.Compression; using Xamarin.Tools.Zip; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/R8.cs b/src/Xamarin.Android.Build.Tasks/Tasks/R8.cs index 32c99ecf321..9621ecce762 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/R8.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/R8.cs @@ -1,7 +1,8 @@ -using Microsoft.Build.Framework; +using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using System.Collections.Generic; using System.IO; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ReadAndroidManifest.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ReadAndroidManifest.cs index a5a109759c2..501fcfd7dd8 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ReadAndroidManifest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ReadAndroidManifest.cs @@ -1,8 +1,9 @@ -using Microsoft.Build.Framework; +using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using System.Collections.Generic; using System.IO; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ReadImportedLibrariesCache.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ReadImportedLibrariesCache.cs index c02a179695c..d138c2c9593 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ReadImportedLibrariesCache.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ReadImportedLibrariesCache.cs @@ -1,4 +1,4 @@ -// +// // ReadImportedLibrariesCache.cs // // Author: @@ -29,6 +29,8 @@ using System.Xml.Linq; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; + namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ReadLibraryProjectImportsCache.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ReadLibraryProjectImportsCache.cs index 0aef199c030..fcc80c5733c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ReadLibraryProjectImportsCache.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ReadLibraryProjectImportsCache.cs @@ -1,4 +1,4 @@ -// +// // ReadLibraryProjectImportsCache.cs // // Author: @@ -29,6 +29,7 @@ using System.Xml.Linq; using Microsoft.Build.Utilities; using Microsoft.Build.Framework; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/RemoveDirFixed.cs b/src/Xamarin.Android.Build.Tasks/Tasks/RemoveDirFixed.cs index 491ee7e592f..c456b87eefd 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/RemoveDirFixed.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/RemoveDirFixed.cs @@ -30,6 +30,7 @@ using System.IO; using Microsoft.Build.Framework; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -55,7 +56,7 @@ public override bool RunTask () // if that fails we probably have readonly files (or locked files) // so try to make them writable and try again. try { - MonoAndroidHelper.SetDirectoryWriteable (fullPath); + Files.SetDirectoryWriteable (fullPath); Directory.Delete (fullPath, true); temporaryRemovedDirectories.Add (directory); } catch (Exception inner) { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/RemoveRegisterAttribute.cs b/src/Xamarin.Android.Build.Tasks/Tasks/RemoveRegisterAttribute.cs index 4163db2e921..ab51f9e101b 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/RemoveRegisterAttribute.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/RemoveRegisterAttribute.cs @@ -7,6 +7,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Mono.Cecil; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/RemoveUnknownFiles.cs b/src/Xamarin.Android.Build.Tasks/Tasks/RemoveUnknownFiles.cs index 1bf62463b64..c6a42050a3c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/RemoveUnknownFiles.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/RemoveUnknownFiles.cs @@ -5,6 +5,7 @@ using System.IO; using System.Collections.Generic; using System.Linq; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -48,7 +49,7 @@ public override bool RunTask () Log.LogDebugMessage ("Deleting File {0}", f); var item = new TaskItem (f.Replace (absDir, "res" + Path.DirectorySeparatorChar)); removedFiles.Add (item); - MonoAndroidHelper.SetWriteable (f); + Microsoft.Android.Build.Tasks.Files.SetWriteable (f); File.Delete (f); } @@ -60,7 +61,7 @@ public override bool RunTask () if (!knownDirs.Contains (d) && IsDirectoryEmpty (d)) { Log.LogDebugMessage ("Deleting Directory {0}", d); removedDirectories.Add (new TaskItem(d)); - MonoAndroidHelper.SetDirectoryWriteable (d); + Microsoft.Android.Build.Tasks.Files.SetDirectoryWriteable (d); System.IO.Directory.Delete (d); } } @@ -91,4 +92,4 @@ private bool IsDirectoryEmpty (string dir) return true; } } -} \ No newline at end of file +} diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAndroidTooling.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAndroidTooling.cs index 8fdc69b6592..620cae77310 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAndroidTooling.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAndroidTooling.cs @@ -6,6 +6,7 @@ using System.Text; using System.Text.RegularExpressions; using System.Globalization; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs index b35a6397f50..b8b4da760dc 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs @@ -14,6 +14,7 @@ using System.Text; using Xamarin.Android.Tools; using Xamarin.Build; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -62,7 +63,7 @@ public override System.Threading.Tasks.Task RunTaskAsync () using (var resolver = new MetadataResolver ()) { Execute (resolver); } - return Done; + return System.Threading.Tasks.Task.CompletedTask; } void Execute (MetadataResolver resolver) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveJdkJvmPath.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveJdkJvmPath.cs index 38df9f0a2d2..f4a895f6484 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveJdkJvmPath.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveJdkJvmPath.cs @@ -1,9 +1,10 @@ -using Microsoft.Build.Framework; +using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using System; using System.IO; using System.Linq; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs index 7442ebc9199..41d76c59755 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs @@ -9,6 +9,7 @@ using Xamarin.Android.Tools; using System.Reflection.Metadata; using System.Reflection.PortableExecutable; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -98,11 +99,11 @@ public override bool RunTask () .ToArray (); foreach (var directory in ResolvedResourceDirectories) { - MonoAndroidHelper.SetDirectoryWriteable (directory.ItemSpec); + Files.SetDirectoryWriteable (directory.ItemSpec); } foreach (var directory in ResolvedAssetDirectories) { - MonoAndroidHelper.SetDirectoryWriteable (directory.ItemSpec); + Files.SetDirectoryWriteable (directory.ItemSpec); } if (!string.IsNullOrEmpty (CacheFile)) { @@ -112,14 +113,14 @@ public override bool RunTask () new XElement ("Jars", Jars.Select(e => new XElement ("Jar", e))), new XElement ("ResolvedResourceDirectories", - XDocumentExtensions.ToXElements (ResolvedResourceDirectories, "ResolvedResourceDirectory", knownMetadata) + ResolvedResourceDirectories.ToXElements ("ResolvedResourceDirectory", knownMetadata) ), new XElement ("ResolvedAssetDirectories", - XDocumentExtensions.ToXElements (ResolvedAssetDirectories, "ResolvedAssetDirectory", knownMetadata)), + ResolvedAssetDirectories.ToXElements ("ResolvedAssetDirectory", knownMetadata)), new XElement ("ResolvedEnvironmentFiles", - XDocumentExtensions.ToXElements (ResolvedEnvironmentFiles, "ResolvedEnvironmentFile", knownMetadata)), + ResolvedEnvironmentFiles.ToXElements ("ResolvedEnvironmentFile", knownMetadata)), new XElement ("ResolvedResourceDirectoryStamps", - XDocumentExtensions.ToXElements (ResolvedResourceDirectoryStamps, "ResolvedResourceDirectoryStamp", knownMetadata)) + ResolvedResourceDirectoryStamps.ToXElements ("ResolvedResourceDirectoryStamp", knownMetadata)) )); document.SaveIfChanged (CacheFile); } @@ -146,7 +147,7 @@ void Extract ( // lets "upgrade" the old directory. string oldPath = Path.GetFullPath (Path.Combine (OutputImportDirectory, "..", "__library_projects__")); if (!OutputImportDirectory.Contains ("__library_projects__") && Directory.Exists (oldPath)) { - MonoAndroidHelper.SetDirectoryWriteable (Path.Combine (oldPath, "..")); + Files.SetDirectoryWriteable (Path.Combine (oldPath, "..")); Directory.Delete (oldPath, recursive: true); } var outdir = Path.GetFullPath (OutputImportDirectory); @@ -180,7 +181,7 @@ void Extract ( // Skip already-extracted resources. bool updated = false; - string assemblyHash = MonoAndroidHelper.HashFile (assemblyPath); + string assemblyHash = Files.HashFile (assemblyPath); string stamp = Path.Combine (outdir, assemblyIdentName + ".stamp"); string stampHash = File.Exists (stamp) ? File.ReadAllText (stamp) : null; if (assemblyHash == stampHash) { @@ -222,7 +223,7 @@ void Extract ( if (name.StartsWith ("__AndroidEnvironment__", StringComparison.OrdinalIgnoreCase)) { var outFile = Path.Combine (outDirForDll, name); using (var stream = pe.GetEmbeddedResourceStream (resource)) { - updated |= MonoAndroidHelper.CopyIfStreamChanged (stream, outFile); + updated |= Files.CopyIfStreamChanged (stream, outFile); } resolvedEnvironments.Add (new TaskItem (Path.GetFullPath (outFile), new Dictionary { { OriginalFile, assemblyPath } @@ -232,7 +233,7 @@ void Extract ( else if (name.EndsWith (".jar", StringComparison.InvariantCultureIgnoreCase)) { using (var stream = pe.GetEmbeddedResourceStream (resource)) { AddJar (jars, importsDir, name, assemblyPath); - updated |= MonoAndroidHelper.CopyIfStreamChanged (stream, Path.Combine (importsDir, name)); + updated |= Files.CopyIfStreamChanged (stream, Path.Combine (importsDir, name)); } } // embedded native libraries @@ -337,7 +338,7 @@ void Extract ( string assetsDir = Path.Combine (importsDir, "assets"); bool updated = false; - string aarHash = MonoAndroidHelper.HashFile (aarFile.ItemSpec); + string aarHash = Files.HashFile (aarFile.ItemSpec); string stamp = Path.Combine (outdir, aarIdentityName + ".stamp"); string stampHash = File.Exists (stamp) ? File.ReadAllText (stamp) : null; var aarFullPath = Path.GetFullPath (aarFile.ItemSpec); diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs index 9bb97632aa6..119ac921a23 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs @@ -31,6 +31,7 @@ using System; using System.IO; using System.Linq; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/RuntimeIdentifierToAbi.cs b/src/Xamarin.Android.Build.Tasks/Tasks/RuntimeIdentifierToAbi.cs index 770228bcaac..0b1d0e1fedf 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/RuntimeIdentifierToAbi.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/RuntimeIdentifierToAbi.cs @@ -1,5 +1,6 @@ using System.Linq; using Microsoft.Build.Framework; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -26,13 +27,13 @@ public override bool RunTask () } if (RuntimeIdentifiers != null && RuntimeIdentifiers.Length > 0) { SupportedAbis = string.Join (";", RuntimeIdentifiers.Select (rid => { - var abi = MonoAndroidHelper.RuntimeIdentifierToAbi (rid); + var abi = AndroidRidAbiHelper.RuntimeIdentifierToAbi (rid); if (string.IsNullOrEmpty (abi)) Log.LogCodedError ("XA0035", Properties.Resources.XA0035, rid); return abi; })); } else if (!string.IsNullOrEmpty (RuntimeIdentifier)) { - SupportedAbis = MonoAndroidHelper.RuntimeIdentifierToAbi (RuntimeIdentifier); + SupportedAbis = AndroidRidAbiHelper.RuntimeIdentifierToAbi (RuntimeIdentifier); if (string.IsNullOrEmpty (SupportedAbis)) Log.LogCodedError ("XA0035", Properties.Resources.XA0035, RuntimeIdentifier); } else if (string.IsNullOrEmpty (SupportedAbis)) { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/SetVsMonoAndroidRegistryKey.cs b/src/Xamarin.Android.Build.Tasks/Tasks/SetVsMonoAndroidRegistryKey.cs index 0d66e1b9e1d..701f5d7216c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/SetVsMonoAndroidRegistryKey.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/SetVsMonoAndroidRegistryKey.cs @@ -1,6 +1,7 @@ -using Microsoft.Build.Framework; +using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using System; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/SplitProperty.cs b/src/Xamarin.Android.Build.Tasks/Tasks/SplitProperty.cs index 45ac1f319a6..e70aa74bce2 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/SplitProperty.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/SplitProperty.cs @@ -1,6 +1,7 @@ -using Microsoft.Build.Framework; +using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using System; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Unzip.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Unzip.cs index 149fff1b51d..b14f8ab9a1b 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Unzip.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Unzip.cs @@ -1,9 +1,10 @@ -using System; +using System; using System.IO; using System.Linq; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Xamarin.Tools.Zip; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ValidateJavaVersion.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ValidateJavaVersion.cs index df9b32b842d..96ff11c975c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ValidateJavaVersion.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ValidateJavaVersion.cs @@ -4,6 +4,7 @@ using System.Text.RegularExpressions; using Microsoft.Build.Framework; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/WriteLockFile.cs b/src/Xamarin.Android.Build.Tasks/Tasks/WriteLockFile.cs index 1a6f6a57aeb..4d58f466495 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/WriteLockFile.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/WriteLockFile.cs @@ -2,6 +2,7 @@ using System.IO; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs index c00356816ea..5a15f7fac0f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs @@ -15,6 +15,7 @@ using Xamarin.Android.Tasks; using Xamarin.Android.Tools; using Xamarin.ProjectTools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Build.Tests { @@ -3292,7 +3293,7 @@ public override void OnReceive(Context context, Intent intent) { } rules.Add ("-dontwarn java.lang.invoke.LambdaMetafactory"); } //FIXME: We aren't de-BOM'ing proguard files? - var bytes = MonoAndroidHelper.UTF8withoutBOM.GetBytes (string.Join (Environment.NewLine, rules)); + var bytes = Files.UTF8withoutBOM.GetBytes (string.Join (Environment.NewLine, rules)); proj.OtherBuildItems.Add (new BuildItem ("ProguardConfiguration", "okhttp3.pro") { BinaryContent = () => bytes, }); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/DebuggingTasksTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/DebuggingTasksTests.cs new file mode 100644 index 00000000000..ba9fd7125c0 --- /dev/null +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/DebuggingTasksTests.cs @@ -0,0 +1,80 @@ +using Microsoft.Build.Framework; +using NUnit.Framework; +using System.Collections.Generic; +using System; +using System.IO; +using System.Linq; +using Xamarin.Android.Build; +using Xamarin.Android.Tasks; +using Xamarin.ProjectTools; + +namespace Xamarin.Android.Build.Tests +{ + [Category ("Node-2"), Category ("Commercial")] + [TestFixture, NonParallelizable] + public class DebuggingTasksTests : BaseTest + { + [OneTimeSetUp] + public void SetUp () + { + if (!CommercialBuildAvailable) + Assert.Ignore ("DebuggingTasksTests require Xamarin.Android.Build.Debugging.Tasks."); + } + + // https://github.com/xamarin/monodroid/blob/63bbeb076d809c74811a8001d38bf2e9e8672627/tests/msbuild/nunit/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests/ResolveXamarinAndroidToolsTests.cs + [Test] + [Repeat (10)] + public void TestResolveToolsExists () + { + List errors = new List(); + List messages = new List(); + + var path = Path.Combine ("temp", TestName); + if (Directory.Exists (Path.Combine (Root, path))) + Directory.Delete (Path.Combine (Root, path), recursive: true); + + var engine = new MockBuildEngine (TestContext.Out, errors: errors, messages: messages); + + var outPath = TestEnvironment.IsRunningOnCI ? TestEnvironment.MonoAndroidToolsDirectory + : new Uri (Path.Combine (XABuildPaths.PrefixDirectory, "lib", "xamarin.android", "xbuild", "Xamarin", "Android")).LocalPath; + var frameworksPath = TestEnvironment.IsRunningOnCI ? Path.Combine (TestEnvironment.MonoAndroidFrameworkDirectory, "v1.0") + : new Uri (Path.Combine (XABuildPaths.PrefixDirectory, "lib", "xamarin.android", "xbuild-frameworks", "MonoAndroid", "v1.0")).LocalPath; + var androidSdk = CreateFauxAndroidSdkDirectory (Path.Combine (path, "Sdk"), "24.0.1", new[] + { + new ApiInfo { Id = "23", Level = 23, Name = "Marshmallow", FrameworkVersion = "v6.0", Stable = true }, + new ApiInfo { Id = "26", Level = 26, Name = "Oreo", FrameworkVersion = "v8.0", Stable = true }, + new ApiInfo { Id = "27", Level = 27, Name = "Oreo", FrameworkVersion = "v8.1", Stable = true }, + new ApiInfo { Id = "28", Level = 28, Name = "Pie", FrameworkVersion = "v9.0", Stable = true }, + }); + //var androidNdk = CreateFauxAndroidNdkDirectory (Path.Combine (path, "Ndk")); + var javaSdk = CreateFauxJavaSdkDirectory (Path.Combine(path, "Java"), "1.8.0", out string javaExe, out string javacExe); + var task = new ResolveXamarinAndroidTools () { + BuildEngine = engine, + AndroidNdkPath = null, + AndroidSdkPath = androidSdk, + JavaSdkPath = javaSdk, + MonoAndroidToolsPath = outPath, + ReferenceAssemblyPaths = new string[] { + frameworksPath, + }, + }; + Assert.True (task.Execute (), "Task should have completed successfully."); + Assert.AreEqual (0, errors.Count, "No Errors should have been raised"); + var expected = $" Found FrameworkPath at {Path.GetFullPath (frameworksPath)}"; + var firstTaskExecMessages = messages.Select (x => x.Message)?.ToList (); + Assert.IsNotNull (firstTaskExecMessages, "First execution did not contain any messages!"); + CollectionAssert.Contains (firstTaskExecMessages, expected); + CollectionAssert.DoesNotContain (firstTaskExecMessages, " Using cached AndroidSdk values"); + CollectionAssert.DoesNotContain (firstTaskExecMessages, " Using cached MonoDroidSdk values"); + + Assert.True (task.Execute (), "Task should have completed successfully."); + Assert.AreEqual (0, errors.Count, "No Errors should have been raised"); + var secondTaskExecMessages = messages.Select (x => x.Message)?.ToList (); + Assert.IsNotNull (secondTaskExecMessages, "Second execution did not contain any messages!"); + CollectionAssert.Contains (secondTaskExecMessages, expected); + CollectionAssert.Contains (secondTaskExecMessages, " Using cached AndroidSdk values"); + CollectionAssert.Contains (secondTaskExecMessages, " Using cached MonoDroidSdk values"); + } + + } +} diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/FilesTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/FilesTests.cs deleted file mode 100644 index 4aafbf464f3..00000000000 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/FilesTests.cs +++ /dev/null @@ -1,422 +0,0 @@ -using NUnit.Framework; -using System; -using System.IO; -using System.Text; -using Xamarin.Android.Tools; -using Xamarin.Tools.Zip; - -namespace Xamarin.Android.Build.Tests -{ - [TestFixture] - [Category ("Node-2")] - public class FilesTests : BaseTest - { - static readonly Encoding encoding = Encoding.UTF8; - string tempDir; - MemoryStream stream; - - [SetUp] - public void SetUp () - { - tempDir = Path.Combine (Path.GetTempPath (), TestContext.CurrentContext.Test.Name); - stream = new MemoryStream (); - } - - [TearDown] - public void TearDown () - { - stream.Dispose (); - - var dir = Files.ToLongPath (tempDir); - if (Directory.Exists (dir)) - Directory.Delete (dir, recursive: true); - } - - void AssertFile (string path, string contents) - { - var fullPath = Path.Combine (tempDir, path); - FileAssert.Exists (fullPath); - Assert.AreEqual (contents, File.ReadAllText (fullPath), $"Contents did not match at path: {path}"); - } - - void AssertFileDoesNotExist (string path) - { - FileAssert.DoesNotExist (Path.Combine (tempDir, path)); - } - - bool ExtractAll (MemoryStream stream) - { - using (var zip = ZipArchive.Open (stream)) { - return Files.ExtractAll (zip, tempDir); - } - } - - string NewFile (string contents = null, string fileName = "") - { - if (string.IsNullOrEmpty (fileName)) { - fileName = Path.GetRandomFileName (); - } - var path = Path.Combine (tempDir, fileName); - if (!string.IsNullOrEmpty (contents)) { - Directory.CreateDirectory (Path.GetDirectoryName (path)); - if (IsWindows && path.Length >= Files.MaxPath) { - File.WriteAllText (Files.ToLongPath (path), contents); - } else { - File.WriteAllText (path, contents); - } - } - return path; - } - - Stream NewStream (string contents) => new MemoryStream (Encoding.Default.GetBytes (contents)); - - [Test] - public void CopyIfChanged_NoChanges () - { - var src = NewFile ("foo"); - var dest = NewFile ("foo"); - Assert.IsFalse (Files.CopyIfChanged (src, dest), "No change should have occurred"); - FileAssert.AreEqual (src, dest); - } - - [Test] - public void CopyIfChanged_NoExist () - { - var src = NewFile ("foo"); - var dest = NewFile (); - Assert.IsTrue (Files.CopyIfChanged (src, dest), "Changes should have occurred"); - FileAssert.AreEqual (src, dest); - } - - [Test] - public void CopyIfChanged_LongPath () - { - var src = NewFile (contents: "foo"); - var dest = NewFile (contents: "bar", fileName: "bar".PadRight (MaxFileName, 'N')); - dest = Files.ToLongPath (dest); - Assert.IsTrue (Files.CopyIfChanged (src, dest), "Changes should have occurred"); - FileAssert.AreEqual (src, dest); - } - - [Test] - public void CopyIfChanged_Changes () - { - var src = NewFile ("foo"); - var dest = NewFile ("bar"); - Assert.IsTrue (Files.CopyIfChanged (src, dest), "Changes should have occurred"); - FileAssert.AreEqual (src, dest); - } - - [Test] - public void CopyIfChanged_Readonly () - { - var src = NewFile ("foo"); - var dest = NewFile ("bar"); - File.SetAttributes (dest, FileAttributes.ReadOnly); - Assert.IsTrue (Files.CopyIfChanged (src, dest), "Changes should have occurred"); - FileAssert.AreEqual (src, dest); - } - - [Test] - public void CopyIfChanged_CasingChange () - { - var src = NewFile (contents: "foo"); - var dest = NewFile (contents: "Foo", fileName: "foo"); - dest = dest.Replace ("foo", "Foo"); - Assert.IsTrue (Files.CopyIfChanged (src, dest), "Changes should have occurred"); - FileAssert.AreEqual (src, dest); - - var files = Directory.GetFiles (Path.GetDirectoryName (dest), "Foo"); - Assert.AreEqual ("Foo", Path.GetFileName (files [0])); - } - - [Test] - public void CopyIfStringChanged_NoChanges () - { - var dest = NewFile ("foo"); - Assert.IsFalse (Files.CopyIfStringChanged ("foo", dest), "No change should have occurred"); - FileAssert.Exists (dest); - } - - [Test] - public void CopyIfStringChanged_NoExist () - { - var dest = NewFile (); - Assert.IsTrue (Files.CopyIfStringChanged ("foo", dest), "Changes should have occurred"); - FileAssert.Exists (dest); - } - - [Test] - public void CopyIfStringChanged_LongPath () - { - var dest = NewFile (fileName: "bar".PadRight (MaxFileName, 'N')); - dest = Files.ToLongPath (dest); - Assert.IsTrue (Files.CopyIfStringChanged ("foo", dest), "Changes should have occurred"); - FileAssert.Exists (dest); - } - - [Test] - public void CopyIfStringChanged_Changes () - { - var dest = NewFile ("bar"); - Assert.IsTrue (Files.CopyIfStringChanged ("foo", dest), "Changes should have occurred"); - FileAssert.Exists (dest); - } - - [Test] - public void CopyIfStringChanged_Readonly () - { - var dest = NewFile ("bar"); - File.SetAttributes (dest, FileAttributes.ReadOnly); - Assert.IsTrue (Files.CopyIfStringChanged ("foo", dest), "Changes should have occurred"); - FileAssert.Exists (dest); - } - - [Test] - public void CopyIfStringChanged_CasingChange () - { - var dest = NewFile (contents: "foo", fileName: "foo"); - dest = dest.Replace ("foo", "Foo"); - Assert.IsTrue (Files.CopyIfStringChanged ("Foo", dest), "Changes should have occurred"); - FileAssert.Exists (dest); - Assert.AreEqual ("Foo", File.ReadAllText (dest), "File contents should match"); - - var files = Directory.GetFiles (Path.GetDirectoryName (dest), "Foo"); - Assert.AreEqual ("Foo", Path.GetFileName (files [0]), "File name should match"); - } - - [Test] - public void CopyIfStreamChanged_NoChanges () - { - using (var src = NewStream ("foo")) { - var dest = NewFile ("foo"); - Assert.IsFalse (Files.CopyIfStreamChanged (src, dest), "No change should have occurred"); - FileAssert.Exists (dest); - } - } - - [Test] - public void CopyIfStreamChanged_LongPath () - { - using (var src = NewStream ("foo")) { - var dest = NewFile (fileName: "bar".PadRight (MaxFileName, 'N')); - dest = Files.ToLongPath (dest); - Assert.IsTrue (Files.CopyIfStreamChanged (src, dest), "Changes should have occurred"); - FileAssert.Exists (dest); - } - } - - [Test] - public void CopyIfStreamChanged_NoExist () - { - using (var src = NewStream ("foo")) { - var dest = NewFile (); - Assert.IsTrue (Files.CopyIfStreamChanged (src, dest), "Changes should have occurred"); - FileAssert.Exists (dest); - } - } - - [Test] - public void CopyIfStreamChanged_Changes () - { - using (var src = NewStream ("foo")) { - var dest = NewFile ("bar"); - Assert.IsTrue (Files.CopyIfStreamChanged (src, dest), "Changes should have occurred"); - FileAssert.Exists (dest); - } - } - - [Test] - public void CopyIfStreamChanged_Readonly () - { - using (var src = NewStream ("foo")) { - var dest = NewFile ("bar"); - File.SetAttributes (dest, FileAttributes.ReadOnly); - Assert.IsTrue (Files.CopyIfStreamChanged (src, dest), "Changes should have occurred"); - FileAssert.Exists (dest); - } - } - - [Test] - public void CopyIfStreamChanged_CasingChange () - { - using (var src = NewStream ("Foo")) { - var dest = NewFile (contents: "foo", fileName: "foo"); - dest = dest.Replace ("foo", "Foo"); - Assert.IsTrue (Files.CopyIfStreamChanged (src, dest), "Changes should have occurred"); - FileAssert.Exists (dest); - Assert.AreEqual ("Foo", File.ReadAllText (dest), "File contents should match"); - - var files = Directory.GetFiles (Path.GetDirectoryName (dest), "Foo"); - Assert.AreEqual ("Foo", Path.GetFileName (files [0]), "File name should match"); - } - } - - [Test] - public void ExtractAll () - { - using (var zip = ZipArchive.Create (stream)) { - zip.AddEntry ("a.txt", "a", encoding); - zip.AddEntry ("b/b.txt", "b", encoding); - } - - bool changes = ExtractAll (stream); - - Assert.IsTrue (changes, "ExtractAll should report changes."); - AssertFile ("a.txt", "a"); - AssertFile (Path.Combine ("b", "b.txt"), "b"); - } - - [Test] - public void ExtractAll_NoChanges () - { - using (var zip = ZipArchive.Create (stream)) { - zip.AddEntry ("a.txt", "a", encoding); - zip.AddEntry ("b/b.txt", "b", encoding); - } - - bool changes = ExtractAll (stream); - Assert.IsTrue (changes, "ExtractAll should report changes."); - - stream.SetLength (0); - using (var zip = ZipArchive.Open (stream)) { - zip.AddEntry ("a.txt", "a", encoding); - zip.AddEntry ("b/b.txt", "b", encoding); - } - - changes = ExtractAll (stream); - - Assert.IsFalse (changes, "ExtractAll should *not* report changes."); - AssertFile ("a.txt", "a"); - AssertFile (Path.Combine ("b", "b.txt"), "b"); - } - - [Test] - public void ExtractAll_NewFile () - { - using (var zip = ZipArchive.Create (stream)) { - zip.AddEntry ("a.txt", "a", encoding); - zip.AddEntry ("b/b.txt", "b", encoding); - } - - bool changes = ExtractAll (stream); - Assert.IsTrue (changes, "ExtractAll should report changes."); - - stream.SetLength (0); - using (var zip = ZipArchive.Open (stream)) { - zip.AddEntry ("a.txt", "a", encoding); - zip.AddEntry ("b/b.txt", "b", encoding); - zip.AddEntry ("c/c.txt", "c", encoding); - } - - changes = ExtractAll (stream); - - Assert.IsTrue (changes, "ExtractAll should report changes."); - AssertFile ("a.txt", "a"); - AssertFile (Path.Combine ("b", "b.txt"), "b"); - AssertFile (Path.Combine ("c", "c.txt"), "c"); - } - - [Test] - public void ExtractAll_FileChanged () - { - using (var zip = ZipArchive.Create (stream)) { - zip.AddEntry ("foo.txt", "foo", encoding); - } - - bool changes = ExtractAll (stream); - Assert.IsTrue (changes, "ExtractAll should report changes."); - - stream.SetLength (0); - using (var zip = ZipArchive.Create (stream)) { - zip.AddEntry ("foo.txt", "bar", encoding); - } - - changes = ExtractAll (stream); - - Assert.IsTrue (changes, "ExtractAll should report changes."); - AssertFile ("foo.txt", "bar"); - } - - [Test] - public void ExtractAll_FileDeleted () - { - using (var zip = ZipArchive.Create (stream)) { - zip.AddEntry ("a.txt", "a", encoding); - zip.AddEntry ("b/b.txt", "b", encoding); - } - - bool changes = ExtractAll (stream); - Assert.IsTrue (changes, "ExtractAll should report changes."); - - stream.SetLength (0); - using (var zip = ZipArchive.Open (stream)) { - zip.AddEntry ("a.txt", "a", encoding); - } - - changes = ExtractAll (stream); - - Assert.IsTrue (changes, "ExtractAll should report changes."); - AssertFile ("a.txt", "a"); - FileAssert.DoesNotExist (Path.Combine (tempDir, "b", "b.txt")); - } - - [Test] - public void ExtractAll_ModifyCallback () - { - using (var zip = ZipArchive.Create (stream)) { - zip.AddEntry ("foo/a.txt", "a", encoding); - zip.AddEntry ("foo/b/b.txt", "b", encoding); - } - - stream.Position = 0; - using (var zip = ZipArchive.Open (stream)) { - bool changes = Files.ExtractAll (zip, tempDir, modifyCallback: e => e.Replace ("foo/", "")); - Assert.IsTrue (changes, "ExtractAll should report changes."); - } - - AssertFile ("a.txt", "a"); - AssertFile (Path.Combine ("b", "b.txt"), "b"); - } - - [Test] - public void ExtractAll_SkipCallback () - { - using (var zip = ZipArchive.Create (stream)) { - zip.AddEntry ("a.txt", "a", encoding); - zip.AddEntry ("b/b.txt", "b", encoding); - } - - stream.Position = 0; - using (var zip = ZipArchive.Open (stream)) { - bool changes = Files.ExtractAll (zip, tempDir, skipCallback: e => e == "a.txt"); - Assert.IsTrue (changes, "ExtractAll should report changes."); - } - - AssertFileDoesNotExist ("a.txt"); - AssertFile (Path.Combine ("b", "b.txt"), "b"); - } - - [Test] - public void ExtractAll_MacOSFiles () - { - using (var zip = ZipArchive.Create (stream)) { - zip.AddEntry ("a/.DS_Store", "a", encoding); - zip.AddEntry ("b/__MACOSX/b.txt", "b", encoding); - zip.AddEntry ("c/__MACOSX", "c", encoding); - } - - bool changes = ExtractAll (stream); - Assert.IsFalse (changes, "ExtractAll should *not* report changes."); - DirectoryAssert.DoesNotExist (tempDir); - } - - [Test] - public void ToHashString () - { - var bytes = new byte [] { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF }; - var expected = BitConverter.ToString (bytes).Replace ("-", string.Empty); - Assert.AreEqual (expected, Files.ToHexString (bytes)); - } - } -} diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/IncrementalBuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/IncrementalBuildTest.cs index 8f6f42f4a2b..798f8a6d03e 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/IncrementalBuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/IncrementalBuildTest.cs @@ -8,6 +8,7 @@ using System.Text; using Xamarin.Android.Tasks; using Xamarin.ProjectTools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Build.Tests { @@ -1113,7 +1114,7 @@ public void DeterministicBuilds ([Values (true, false)] bool deterministic) Assert.IsTrue (b.Build (proj), "first build should have succeeded."); var output = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, $"{proj.ProjectName}.dll"); FileAssert.Exists (output); - string expectedHash = MonoAndroidHelper.HashFile (output); + string expectedHash = Files.HashFile (output); Guid expectedMvid; using (var assembly = AssemblyDefinition.ReadAssembly (output)) { expectedMvid = assembly.MainModule.Mvid; @@ -1125,10 +1126,10 @@ public void DeterministicBuilds ([Values (true, false)] bool deterministic) using (var assembly = AssemblyDefinition.ReadAssembly (output)) { if (deterministic) { Assert.AreEqual (expectedMvid, assembly.MainModule.Mvid, "Mvid should match"); - Assert.AreEqual (expectedHash, MonoAndroidHelper.HashFile (output), "hash should match"); + Assert.AreEqual (expectedHash, Files.HashFile (output), "hash should match"); } else { Assert.AreNotEqual (expectedMvid, assembly.MainModule.Mvid, "Mvid should *not* match"); - Assert.AreNotEqual (expectedHash, MonoAndroidHelper.HashFile (output), "hash should *not* match"); + Assert.AreNotEqual (expectedHash, Files.HashFile (output), "hash should *not* match"); } } } diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/MemoryStreamPoolTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/MemoryStreamPoolTests.cs deleted file mode 100644 index 52d78348dba..00000000000 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/MemoryStreamPoolTests.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.IO; -using NUnit.Framework; -using Xamarin.Android.Tasks; - -namespace Xamarin.Android.Build.Tests -{ - [TestFixture] - [Category ("Node-2")] - public class MemoryStreamPoolTests - { - MemoryStreamPool pool; - - [SetUp] - public void SetUp () - { - pool = new MemoryStreamPool (); - } - - [Test] - public void Reuse () - { - var expected = pool.Rent (); - expected.Write (new byte [] { 1, 2, 3 }, 0, 3); - pool.Return (expected); - var actual = pool.Rent (); - Assert.AreSame (expected, actual); - Assert.AreEqual (0, actual.Length); - } - - [Test] - public void PutDisposed () - { - var stream = new MemoryStream (); - stream.Dispose (); - Assert.Throws (() => pool.Return (stream)); - } - - [Test] - public void CreateStreamWriter () - { - var pool = new MemoryStreamPool (); - var expected = pool.Rent (); - using (var writer = MemoryStreamPool.Shared.CreateStreamWriter ()) { - writer.WriteLine ("foobar"); - } - pool.Return (expected); - - var actual = pool.Rent (); - Assert.AreSame (expected, actual); - Assert.AreEqual (0, actual.Length); - } - - [Test] - public void CreateBinaryWriter () - { - var pool = new MemoryStreamPool (); - var expected = pool.Rent (); - using (var writer = MemoryStreamPool.Shared.CreateBinaryWriter ()) { - writer.Write (42); - } - pool.Return (expected); - - var actual = pool.Rent (); - Assert.AreSame (expected, actual); - Assert.AreEqual (0, actual.Length); - } - } -} diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/MonoAndroidHelperTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/MonoAndroidHelperTests.cs deleted file mode 100644 index eb5574d3e82..00000000000 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/MonoAndroidHelperTests.cs +++ /dev/null @@ -1,237 +0,0 @@ -using System.IO; -using System.Text; -using NUnit.Framework; -using Xamarin.Android.Tasks; - -namespace Xamarin.Android.Build.Tests -{ - [TestFixture] - [Category ("Node-2")] - public class MonoAndroidHelperTests - { - string temp; - - [SetUp] - public void SetUp () - { - temp = Path.Combine (Path.GetTempPath (), TestContext.CurrentContext.Test.Name); - } - - [TearDown] - public void TearDown () - { - File.Delete (temp); - } - - [Test] - public void CopyIfStringChanged () - { - var foo = "bar"; - Assert.IsTrue (MonoAndroidHelper.CopyIfStringChanged (foo, temp), "Should write on new file."); - FileAssert.Exists (temp); - Assert.IsFalse (MonoAndroidHelper.CopyIfStringChanged (foo, temp), "Should *not* write unless changed."); - foo += "\n"; - Assert.IsTrue (MonoAndroidHelper.CopyIfStringChanged (foo, temp), "Should write when changed."); - } - - [Test] - public void CopyIfBytesChanged () - { - var foo = new byte [32]; - Assert.IsTrue (MonoAndroidHelper.CopyIfBytesChanged (foo, temp), "Should write on new file."); - FileAssert.Exists (temp); - Assert.IsFalse (MonoAndroidHelper.CopyIfBytesChanged (foo, temp), "Should *not* write unless changed."); - foo [0] = 0xFF; - Assert.IsTrue (MonoAndroidHelper.CopyIfBytesChanged (foo, temp), "Should write when changed."); - } - - [Test] - public void CopyIfStreamChanged () - { - using (var foo = new MemoryStream ()) - using (var writer = new StreamWriter (foo)) { - writer.WriteLine ("bar"); - writer.Flush (); - - Assert.IsTrue (MonoAndroidHelper.CopyIfStreamChanged (foo, temp), "Should write on new file."); - FileAssert.Exists (temp); - Assert.IsFalse (MonoAndroidHelper.CopyIfStreamChanged (foo, temp), "Should *not* write unless changed."); - writer.WriteLine (); - writer.Flush (); - Assert.IsTrue (MonoAndroidHelper.CopyIfStreamChanged (foo, temp), "Should write when changed."); - } - } - - [Test] - public void CopyIfStringChanged_NewDirectory () - { - temp = Path.Combine (temp, "foo.txt"); - - var foo = "bar"; - Assert.IsTrue (MonoAndroidHelper.CopyIfStringChanged (foo, temp), "Should write on new file."); - FileAssert.Exists (temp); - } - - [Test] - public void CopyIfBytesChanged_NewDirectory () - { - temp = Path.Combine (temp, "foo.bin"); - - var foo = new byte [32]; - Assert.IsTrue (MonoAndroidHelper.CopyIfBytesChanged (foo, temp), "Should write on new file."); - FileAssert.Exists (temp); - } - - [Test] - public void CopyIfStreamChanged_NewDirectory () - { - temp = Path.Combine (temp, "foo.txt"); - - using (var foo = new MemoryStream ()) - using (var writer = new StreamWriter (foo)) { - writer.WriteLine ("bar"); - writer.Flush (); - - Assert.IsTrue (MonoAndroidHelper.CopyIfStreamChanged (foo, temp), "Should write on new file."); - FileAssert.Exists (temp); - } - } - - [Test] - public void CopyIfStringChanged_Readonly () - { - if (File.Exists (temp)) { - File.SetAttributes (temp, FileAttributes.Normal); - } - File.WriteAllText (temp, ""); - File.SetAttributes (temp, FileAttributes.ReadOnly); - - var foo = "bar"; - Assert.IsTrue (MonoAndroidHelper.CopyIfStringChanged (foo, temp), "Should write on new file."); - FileAssert.Exists (temp); - } - - [Test] - public void CopyIfBytesChanged_Readonly () - { - if (File.Exists (temp)) { - File.SetAttributes (temp, FileAttributes.Normal); - } - File.WriteAllText (temp, ""); - File.SetAttributes (temp, FileAttributes.ReadOnly); - - var foo = new byte [32]; - Assert.IsTrue (MonoAndroidHelper.CopyIfBytesChanged (foo, temp), "Should write on new file."); - FileAssert.Exists (temp); - } - - [Test] - public void CopyIfStreamChanged_Readonly () - { - if (File.Exists (temp)) { - File.SetAttributes (temp, FileAttributes.Normal); - } - File.WriteAllText (temp, ""); - File.SetAttributes (temp, FileAttributes.ReadOnly); - - using (var foo = new MemoryStream ()) - using (var writer = new StreamWriter (foo)) { - writer.WriteLine ("bar"); - writer.Flush (); - - Assert.IsTrue (MonoAndroidHelper.CopyIfStreamChanged (foo, temp), "Should write on new file."); - FileAssert.Exists (temp); - } - } - - [Test] - public void CleanBOM_Readonly () - { - var encoding = Encoding.UTF8; - Directory.CreateDirectory (temp); - temp = Path.Combine (temp, "foo.txt"); - if (File.Exists (temp)) { - File.SetAttributes (temp, FileAttributes.Normal); - } - using (var stream = File.Create (temp)) - using (var writer = new StreamWriter (stream, encoding)) { - writer.Write ("This will have a BOM"); - } - File.SetAttributes (temp, FileAttributes.ReadOnly); - var before = File.ReadAllBytes (temp); - MonoAndroidHelper.CleanBOM (temp); - var after = File.ReadAllBytes (temp); - var preamble = encoding.GetPreamble (); - Assert.AreEqual (before.Length, after.Length + preamble.Length, "BOM should be removed!"); - } - - [Test] - public void CopyIfStreamChanged_MemoryStreamPool_StreamWriter () - { - var pool = new MemoryStreamPool (); - var expected = pool.Rent (); - pool.Return (expected); - - using (var writer = pool.CreateStreamWriter ()) { - writer.WriteLine ("bar"); - writer.Flush (); - - Assert.IsTrue (MonoAndroidHelper.CopyIfStreamChanged (writer.BaseStream, temp), "Should write on new file."); - FileAssert.Exists (temp); - } - - var actual = pool.Rent (); - Assert.AreSame (expected, actual); - Assert.AreEqual (0, actual.Length); - } - - [Test] - public void CopyIfStreamChanged_MemoryStreamPool_BinaryWriter () - { - var pool = new MemoryStreamPool (); - var expected = pool.Rent (); - pool.Return (expected); - - using (var writer = pool.CreateBinaryWriter ()) { - writer.Write (42); - writer.Flush (); - - Assert.IsTrue (MonoAndroidHelper.CopyIfStreamChanged (writer.BaseStream, temp), "Should write on new file."); - FileAssert.Exists (temp); - } - - var actual = pool.Rent (); - Assert.AreSame (expected, actual); - Assert.AreEqual (0, actual.Length); - } - - [Test] - public void SetWriteable () - { - File.WriteAllText (temp, contents: "foo"); - File.SetAttributes (temp, FileAttributes.ReadOnly); - - MonoAndroidHelper.SetWriteable (temp); - - var attributes = File.GetAttributes (temp); - Assert.AreEqual (FileAttributes.Normal, attributes); - File.WriteAllText (temp, contents: "bar"); - } - - [Test] - public void SetDirectoryWriteable () - { - Directory.CreateDirectory (temp); - try { - var directoryInfo = new DirectoryInfo (temp); - directoryInfo.Attributes |= FileAttributes.ReadOnly; - MonoAndroidHelper.SetDirectoryWriteable (temp); - - directoryInfo = new DirectoryInfo (temp); - Assert.AreEqual (FileAttributes.Directory, directoryInfo.Attributes); - } finally { - Directory.Delete (temp); - } - } - } -} diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/Aapt2Tests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/Aapt2Tests.cs index d7c01d39cd9..8e942e9b9bb 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/Aapt2Tests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/Aapt2Tests.cs @@ -8,6 +8,7 @@ using Xamarin.Android.Tasks; using Xamarin.Android.Tools; using Xamarin.ProjectTools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Build.Tests { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/AndroidComputeResPathsTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/AndroidComputeResPathsTests.cs index d8bbdfa807d..12ae51f5c3b 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/AndroidComputeResPathsTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/AndroidComputeResPathsTests.cs @@ -5,6 +5,7 @@ using Microsoft.Build.Utilities; using NUnit.Framework; using Xamarin.Android.Tasks; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Build.Tests { [TestFixture] @@ -51,7 +52,7 @@ public class AndroidComputeResPathsTests : BaseTest { [TestCaseSource (nameof (AndroidComputeResPathsChecks))] public void AndroidComputeResPathsTest (string identity, string logicalName, string expectedIntermediateFile, string expectedResultFile) { - var hash = Tools.Files.HashString (identity + logicalName + expectedIntermediateFile + expectedResultFile); + var hash = Files.HashString (identity + logicalName + expectedIntermediateFile + expectedResultFile); var projectDir = Path.Combine (Root, "temp", $"{nameof (AndroidComputeResPathsTest)}_{hash}"); TestOutputDirectories [TestContext.CurrentContext.Test.ID] = projectDir; var intermdiateDir = Path.Combine (projectDir, "assets"); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/AndroidRegExTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/AndroidRegExTests.cs index cc84a69d049..90a74c04cbb 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/AndroidRegExTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/AndroidRegExTests.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using NUnit.Framework; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Build.Tests { @@ -170,7 +171,7 @@ public IEnumerator GetEnumerator () [TestCaseSource(typeof (AndroidRegExTestsCases))] public void RegExTests(string message, bool expectedToMatch, string expectedFile, string expectedLine, string expectedLevel, string expextedMessage) { - var regex = Xamarin.Android.Tasks.AndroidRunToolTask.AndroidErrorRegex; + var regex = Microsoft.Android.Build.Tasks.AndroidRunToolTask.AndroidErrorRegex; var result = regex.Match (message); Assert.AreEqual (expectedToMatch,result.Success); Assert.AreEqual (expectedFile, result.Groups["file"].Value); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/RemoveDirTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/RemoveDirTests.cs index c3cbbfe9c4a..62037c9e439 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/RemoveDirTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/RemoveDirTests.cs @@ -6,6 +6,7 @@ using NUnit.Framework; using Xamarin.Android.Tasks; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Build.Tests { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs index 6b59664041e..9436c6b4f2c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs @@ -10,6 +10,7 @@ using System.Xml.Linq; using Xamarin.Android.Tasks; using Xamarin.ProjectTools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Build.Tests { @@ -476,8 +477,8 @@ protected bool StreamCompare (Stream stream1, Stream stream2) { Assert.IsNotNull (stream1, "stream1 of StreamCompare should not be null"); Assert.IsNotNull (stream2, "stream2 of StreamCompare should not be null"); - string hash1 = MonoAndroidHelper.HashBytes (ReadAllBytesIgnoringLineEndings (stream1)); - string hash2 = MonoAndroidHelper.HashBytes (ReadAllBytesIgnoringLineEndings (stream2)); + string hash1 = Files.HashBytes (ReadAllBytesIgnoringLineEndings (stream1)); + string hash2 = Files.HashBytes (ReadAllBytesIgnoringLineEndings (stream2)); return hash1 == hash2; } diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs index fd7c3877d80..1bfa91b8f9e 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs @@ -7,6 +7,7 @@ using Xamarin.Android.Tasks; using Xamarin.ProjectTools; using Xamarin.Tools.Zip; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Build.Tests { @@ -404,7 +405,7 @@ public void DotNetBuild (string runtimeIdentifiers, bool isRelease) apk.AssertContainsEntry (apkPath, $"assemblies/System.Linq.dll", shouldContainEntry: expectEmbeddedAssembies); apk.AssertContainsEntry (apkPath, $"assemblies/es/{proj.ProjectName}.resources.dll", shouldContainEntry: expectEmbeddedAssembies); var rids = runtimeIdentifiers.Split (';'); - foreach (var abi in rids.Select (MonoAndroidHelper.RuntimeIdentifierToAbi)) { + foreach (var abi in rids.Select (AndroidRidAbiHelper.RuntimeIdentifierToAbi)) { apk.AssertContainsEntry (apkPath, $"lib/{abi}/libmonodroid.so"); apk.AssertContainsEntry (apkPath, $"lib/{abi}/libmonosgen-2.0.so"); if (rids.Length > 1) { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj index a17bcf4e2c2..296dc18413c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj @@ -7,12 +7,15 @@ - + - ..\..\..\..\bin\$(Configuration)\lib\xamarin.android\xbuild\Xamarin\Android\Xamarin.Android.Cecil.dll + $(XAInstallPrefix)xbuild\Xamarin\Android\Xamarin.Android.Cecil.dll + + + $(XAInstallPrefix)xbuild\Xamarin\Android\Xamarin.Android.Build.Debugging.Tasks.dll @@ -23,6 +26,7 @@ + ..\Expected\GenerateDesignerFileExpected.cs diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj index e093a34f7ce..a8c3b947a9d 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj @@ -6,7 +6,7 @@ netstandard2.0 - + @@ -78,7 +78,7 @@ - nuget\NuGet.exe + ..\nuget\NuGet.exe PreserveNewest diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/Aapt2Daemon.cs b/src/Xamarin.Android.Build.Tasks/Utilities/Aapt2Daemon.cs index 3b1fd6825fa..ec6aa25a035 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/Aapt2Daemon.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/Aapt2Daemon.cs @@ -9,6 +9,7 @@ using Microsoft.Build.Framework; using TPL = System.Threading.Tasks; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -198,14 +199,14 @@ private void Aapt2DaemonStart () // otherwise aapt2 will try to interpret the BOM as an argument. // Cant use this cos its netstandard 2.1 only // and we are using netstandard 2.0 - //StandardInputEncoding = MonoAndroidHelper.UTF8withoutBOM, + //StandardInputEncoding = Files.UTF8withoutBOM, }; Process aapt2; Encoding currentEncoding = Console.InputEncoding; lock (lockObject) { try { - if (!SetProcessInputEncoding (info, MonoAndroidHelper.UTF8withoutBOM)) - SetConsoleInputEncoding (MonoAndroidHelper.UTF8withoutBOM); + if (!SetProcessInputEncoding (info, Files.UTF8withoutBOM)) + SetConsoleInputEncoding (Files.UTF8withoutBOM); aapt2 = new Process (); aapt2.StartInfo = info; aapt2.Start (); @@ -219,7 +220,7 @@ private void Aapt2DaemonStart () bool errored = false; try { // try to write Unicode UTF8 to aapt2 - using (StreamWriter writer = new StreamWriter (aapt2.StandardInput.BaseStream, MonoAndroidHelper.UTF8withoutBOM, bufferSize: 1024, leaveOpen: true)) { + using (StreamWriter writer = new StreamWriter (aapt2.StandardInput.BaseStream, Files.UTF8withoutBOM, bufferSize: 1024, leaveOpen: true)) { foreach (var arg in job.Commands) { writer.WriteLine (arg); } diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/AndroidResource.cs b/src/Xamarin.Android.Build.Tasks/Utilities/AndroidResource.cs index c773ef0d257..c207567c1b1 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/AndroidResource.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/AndroidResource.cs @@ -8,6 +8,7 @@ using System.Xml.Linq; using System.Xml.XPath; using Xamarin.Android.Tasks; +using Microsoft.Android.Build.Tasks; namespace Monodroid { static class AndroidResource { @@ -24,7 +25,7 @@ public static bool UpdateXmlResource (string res, string filename, IEnumerable - /// Creates a collection of Task with proper CancellationToken and error handling and waits via Task.WhenAll - /// - public static Task WhenAll(this AsyncTask asyncTask, IEnumerable source, Action body) - { - var tasks = new List (); - foreach (var s in source) { - tasks.Add (Task.Run (() => { - try { - body (s); - } catch (Exception exc) { - LogErrorAndCancel (asyncTask, exc); - } - }, asyncTask.CancellationToken)); - } - return Task.WhenAll (tasks); - } - - /// - /// Creates a collection of Task with proper CancellationToken and error handling and waits via Task.WhenAll - /// Passes an object the inner method can use for locking. The callback is of the form: (T item, object lockObject) - /// - public static Task WhenAllWithLock (this AsyncTask asyncTask, IEnumerable source, Action body) - { - var lockObject = new object (); - var tasks = new List (); - foreach (var s in source) { - tasks.Add (Task.Run (() => { - try { - body (s, lockObject); - } catch (Exception exc) { - LogErrorAndCancel (asyncTask, exc); - } - }, asyncTask.CancellationToken)); - } - return Task.WhenAll (tasks); - } - - /// - /// Calls Parallel.ForEach() with appropriate ParallelOptions and exception handling. - /// - public static ParallelLoopResult ParallelForEach (this AsyncTask asyncTask, IEnumerable source, Action body) - { - var options = ParallelOptions (asyncTask); - return Parallel.ForEach (source, options, s => { - try { - body (s); - } catch (Exception exc) { - LogErrorAndCancel (asyncTask, exc); - } - }); - } - - /// - /// Calls Parallel.ForEach() with appropriate ParallelOptions and exception handling. - /// Passes an object the inner method can use for locking. The callback is of the form: (T item, object lockObject) - /// - public static ParallelLoopResult ParallelForEachWithLock (this AsyncTask asyncTask, IEnumerable source, Action body) - { - var options = ParallelOptions (asyncTask); - var lockObject = new object (); - return Parallel.ForEach (source, options, s => { - try { - body (s, lockObject); - } catch (Exception exc) { - LogErrorAndCancel (asyncTask, exc); - } - }); - } - - static ParallelOptions ParallelOptions (AsyncTask asyncTask) => new ParallelOptions { - CancellationToken = asyncTask.CancellationToken, - TaskScheduler = TaskScheduler.Default, - }; - - static void LogErrorAndCancel (AsyncTask asyncTask, Exception exc) - { - asyncTask.LogCodedError ("XA0000", Properties.Resources.XA0000_Exception, exc); - asyncTask.Cancel (); - } - - /// - /// Calls Task.Run() with a proper CancellationToken. - /// - public static Task RunTask (this AsyncTask asyncTask, Action body) => - Task.Run (body, asyncTask.CancellationToken); - - - /// - /// Calls Task.Run() with a proper CancellationToken. - /// - public static Task RunTask (this AsyncTask asyncTask, Func body) => - Task.Run (body, asyncTask.CancellationToken); - } -} diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/CompressedAssembliesNativeAssemblyGenerator.cs b/src/Xamarin.Android.Build.Tasks/Utilities/CompressedAssembliesNativeAssemblyGenerator.cs index 3e5559e732b..0d7fea740f8 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/CompressedAssembliesNativeAssemblyGenerator.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/CompressedAssembliesNativeAssemblyGenerator.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.IO; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -52,7 +53,7 @@ protected override void WriteSymbols (StreamWriter output) WriteStructureSize (output, label, size); dataOutput.Flush (); - MonoAndroidHelper.CopyIfStreamChanged (dataOutput.BaseStream, dataIncludeFile); + Files.CopyIfStreamChanged (dataOutput.BaseStream, dataIncludeFile); } WriteCompressedAssembliesStructure (output, (uint)assemblies.Count, label); diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/Files.cs b/src/Xamarin.Android.Build.Tasks/Utilities/Files.cs deleted file mode 100644 index 0eb1c266940..00000000000 --- a/src/Xamarin.Android.Build.Tasks/Utilities/Files.cs +++ /dev/null @@ -1,476 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Security.Cryptography; -using System.Text; -using Java.Interop.Tools.JavaCallableWrappers; -using Xamarin.Tools.Zip; - -#if MSBUILD -using Microsoft.Build.Utilities; -using Xamarin.Android.Tasks; -#endif - -namespace Xamarin.Android.Tools -{ - - static class Files { - - /// - /// Windows has a MAX_PATH limit of 260 characters - /// See: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation - /// - public const int MaxPath = 260; - - /// - /// On Windows, we can opt into a long path with this prefix - /// - public const string LongPathPrefix = @"\\?\"; - - /// - /// Converts a full path to a \\?\ prefixed path that works on all Windows machines when over 260 characters - /// NOTE: requires a *full path*, use sparingly - /// - public static string ToLongPath (string fullPath) - { - // On non-Windows platforms, return the path unchanged - if (Path.DirectorySeparatorChar != '\\') { - return fullPath; - } - return LongPathPrefix + fullPath; - } - - public static bool Archive (string target, Action archiver) - { - string newTarget = target + ".new"; - - archiver (newTarget); - - bool changed = CopyIfChanged (newTarget, target); - - try { - File.Delete (newTarget); - } catch { - } - - return changed; - } - - public static bool ArchiveZipUpdate(string target, Action archiver) - { - var lastWrite = File.Exists (target) ? File.GetLastWriteTimeUtc (target) : DateTime.MinValue; - archiver (target); - return lastWrite < File.GetLastWriteTimeUtc (target); - } - - public static bool ArchiveZip (string target, Action archiver) - { - string newTarget = target + ".new"; - - archiver (newTarget); - - bool changed = CopyIfZipChanged (newTarget, target); - - try { - File.Delete (newTarget); - } catch { - } - - return changed; - } - - public static bool CopyIfChanged (string source, string destination) - { - if (HasFileChanged (source, destination)) { - var directory = Path.GetDirectoryName (destination); - if (!string.IsNullOrEmpty (directory)) - Directory.CreateDirectory (directory); - - if (!Directory.Exists (source)) { - if (File.Exists (destination)) { - MonoAndroidHelper.SetWriteable (destination, checkExists: false); - File.Delete (destination); - } - File.Copy (source, destination, overwrite: true); - MonoAndroidHelper.SetWriteable (destination, checkExists: false); - File.SetLastWriteTimeUtc (destination, DateTime.UtcNow); - return true; - } - } - - return false; - } - - public static bool CopyIfStringChanged (string contents, string destination) - { - //NOTE: this is not optimal since it allocates a byte[]. We can improve this down the road with Span or System.Buffers. - var bytes = Encoding.UTF8.GetBytes (contents); - return CopyIfBytesChanged (bytes, destination); - } - - public static bool CopyIfBytesChanged (byte[] bytes, string destination) - { - if (HasBytesChanged (bytes, destination)) { - var directory = Path.GetDirectoryName (destination); - if (!string.IsNullOrEmpty (directory)) - Directory.CreateDirectory (directory); - - if (File.Exists (destination)) { - MonoAndroidHelper.SetWriteable (destination, checkExists: false); - File.Delete (destination); - } - File.WriteAllBytes (destination, bytes); - return true; - } - return false; - } - - public static bool CopyIfStreamChanged (Stream stream, string destination) - { - if (HasStreamChanged (stream, destination)) { - var directory = Path.GetDirectoryName (destination); - if (!string.IsNullOrEmpty (directory)) - Directory.CreateDirectory (directory); - - if (File.Exists (destination)) { - MonoAndroidHelper.SetWriteable (destination, checkExists: false); - File.Delete (destination); - } - using (var fileStream = File.Create (destination)) { - stream.Position = 0; //HasStreamChanged read to the end - stream.CopyTo (fileStream); - } - return true; - } - return false; - } - - public static bool CopyIfZipChanged (Stream source, string destination) - { - string hash; - if (HasZipChanged (source, destination, out hash)) { - Directory.CreateDirectory (Path.GetDirectoryName (destination)); - source.Position = 0; - using (var f = File.Create (destination)) { - source.CopyTo (f); - } - File.SetLastWriteTimeUtc (destination, DateTime.UtcNow); -#if TESTCACHE - if (hash != null) - File.WriteAllText (destination + ".hash", hash); -#endif - return true; - }/* else - Console.WriteLine ("Skipping copying {0}, unchanged", Path.GetFileName (destination));*/ - - return false; - } - - public static bool CopyIfZipChanged (string source, string destination) - { - string hash; - if (HasZipChanged (source, destination, out hash)) { - Directory.CreateDirectory (Path.GetDirectoryName (destination)); - - File.Copy (source, destination, true); - File.SetLastWriteTimeUtc (destination, DateTime.UtcNow); -#if TESTCACHE - if (hash != null) - File.WriteAllText (destination + ".hash", hash); -#endif - return true; - } - - return false; - } - - public static bool HasZipChanged (Stream source, string destination, out string hash) - { - hash = null; - - string src_hash = hash = HashZip (source); - - if (!File.Exists (destination)) - return true; - - string dst_hash = HashZip (destination); - - if (src_hash == null || dst_hash == null) - return true; - - return src_hash != dst_hash; - } - - public static bool HasZipChanged (string source, string destination, out string hash) - { - hash = null; - if (!File.Exists (source)) - return true; - - string src_hash = hash = HashZip (source); - - if (!File.Exists (destination)) - return true; - - string dst_hash = HashZip (destination); - - if (src_hash == null || dst_hash == null) - return true; - - return src_hash != dst_hash; - } - - // This is for if the file contents have changed. Often we have to - // regenerate a file, but we don't want to update it if hasn't changed - // so that incremental build is as efficient as possible - public static bool HasFileChanged (string source, string destination) - { - // If either are missing, that's definitely a change - if (!File.Exists (source) || !File.Exists (destination)) - return true; - - var src_hash = HashFile (source); - var dst_hash = HashFile (destination); - - // If the hashes don't match, then the file has changed - if (src_hash != dst_hash) - return true; - - return false; - } - - public static bool HasStreamChanged (Stream source, string destination) - { - //If destination is missing, that's definitely a change - if (!File.Exists (destination)) - return true; - - var src_hash = HashStream (source); - var dst_hash = HashFile (destination); - - // If the hashes don't match, then the file has changed - if (src_hash != dst_hash) - return true; - - return false; - } - - public static bool HasBytesChanged (byte [] bytes, string destination) - { - //If destination is missing, that's definitely a change - if (!File.Exists (destination)) - return true; - - var src_hash = HashBytes (bytes); - var dst_hash = HashFile (destination); - - // If the hashes don't match, then the file has changed - if (src_hash != dst_hash) - return true; - - return false; - } - - static string HashZip (Stream stream) - { - string hashes = String.Empty; - - try { - using (var zip = ZipArchive.Open (stream)) { - foreach (var item in zip) { - hashes += String.Format ("{0}{1}", item.FullName, item.CRC); - } - } - } catch { - return null; - } - return hashes; - } - - static string HashZip (string filename) - { - string hashes = String.Empty; - - try { - // check cache - if (File.Exists (filename + ".hash")) - return File.ReadAllText (filename + ".hash"); - - using (var zip = ReadZipFile (filename)) { - foreach (var item in zip) { - hashes += String.Format ("{0}{1}", item.FullName, item.CRC); - } - } - } catch { - return null; - } - return hashes; - } - - public static ZipArchive ReadZipFile (string filename, bool strictConsistencyChecks = false) - { - return ZipArchive.Open (filename, FileMode.Open, strictConsistencyChecks: strictConsistencyChecks); - } - - public static bool ZipAny (string filename, Func filter) - { - using (var zip = ReadZipFile (filename)) { - return zip.Any (filter); - } - } - - public static bool ExtractAll (ZipArchive zip, string destination, Action progressCallback = null, Func modifyCallback = null, - Func deleteCallback = null, Func skipCallback = null) - { - int i = 0; - int total = (int)zip.EntryCount; - bool updated = false; - var files = new HashSet (); - var memoryStream = MemoryStreamPool.Shared.Rent (); - try { - foreach (var entry in zip) { - progressCallback?.Invoke (i++, total); - if (entry.IsDirectory) - continue; - if (entry.FullName.Contains ("/__MACOSX/") || - entry.FullName.EndsWith ("/__MACOSX", StringComparison.OrdinalIgnoreCase) || - string.Equals (entry.FullName, ".DS_Store", StringComparison.OrdinalIgnoreCase) || - entry.FullName.EndsWith ("/.DS_Store", StringComparison.OrdinalIgnoreCase)) - continue; - if (skipCallback != null && skipCallback (entry.FullName)) - continue; - var fullName = modifyCallback?.Invoke (entry.FullName) ?? entry.FullName; - var outfile = Path.GetFullPath (Path.Combine (destination, fullName)); - files.Add (outfile); - memoryStream.SetLength (0); //Reuse the stream - entry.Extract (memoryStream); - try { - updated |= MonoAndroidHelper.CopyIfStreamChanged (memoryStream, outfile); - } catch (PathTooLongException) { - throw new PathTooLongException ($"Could not extract \"{fullName}\" to \"{outfile}\". Path is too long."); - } - } - } finally { - MemoryStreamPool.Shared.Return (memoryStream); - } - if (Directory.Exists (destination)) { - foreach (var file in Directory.GetFiles (destination, "*", SearchOption.AllDirectories)) { - var outfile = Path.GetFullPath (file); - if (outfile.Contains ("/__MACOSX/") || - outfile.EndsWith (".flat", StringComparison.OrdinalIgnoreCase) || - outfile.EndsWith ("files.cache", StringComparison.OrdinalIgnoreCase) || - outfile.EndsWith ("__AndroidLibraryProjects__.zip", StringComparison.OrdinalIgnoreCase) || - outfile.EndsWith ("/__MACOSX", StringComparison.OrdinalIgnoreCase) || - outfile.EndsWith ("/.DS_Store", StringComparison.OrdinalIgnoreCase)) - continue; - if (!files.Contains (outfile) && (deleteCallback?.Invoke (outfile) ?? true)) { - File.Delete (outfile); - updated = true; - } - } - } - return updated; - } - - /// - /// Callback that can be used in combination with ExtractAll for extracting .aar files - /// - public static bool ShouldSkipEntryInAar (string entryFullName) - { - // AAR files may contain other jars not needed for compilation - // See: https://developer.android.com/studio/projects/android-library.html#aar-contents - if (!entryFullName.EndsWith (".jar", StringComparison.OrdinalIgnoreCase)) - return false; - if (entryFullName == "classes.jar" || - entryFullName.StartsWith ("libs/", StringComparison.OrdinalIgnoreCase) || - entryFullName.StartsWith ("libs\\", StringComparison.OrdinalIgnoreCase)) - return false; - // This could be `lint.jar` or `api.jar`, etc. - return true; - } - - public static string HashString (string s) - { - var bytes = Encoding.UTF8.GetBytes (s); - return HashBytes (bytes); - } - - public static string HashBytes (byte [] bytes) - { - using (HashAlgorithm hashAlg = new Crc64 ()) { - byte [] hash = hashAlg.ComputeHash (bytes); - return ToHexString (hash); - } - } - - public static string HashFile (string filename) - { - using (HashAlgorithm hashAlg = new Crc64 ()) { - return HashFile (filename, hashAlg); - } - } - - public static string HashFile (string filename, HashAlgorithm hashAlg) - { - using (Stream file = new FileStream (filename, FileMode.Open, FileAccess.Read)) { - byte[] hash = hashAlg.ComputeHash (file); - return ToHexString (hash); - } - } - - public static string HashStream (Stream stream) - { - stream.Position = 0; - - using (HashAlgorithm hashAlg = new Crc64 ()) { - byte[] hash = hashAlg.ComputeHash (stream); - return ToHexString (hash); - } - } - - public static string ToHexString (byte[] hash) - { - char [] array = new char [hash.Length * 2]; - for (int i = 0, j = 0; i < hash.Length; i += 1, j += 2) { - byte b = hash [i]; - array [j] = GetHexValue (b / 16); - array [j + 1] = GetHexValue (b % 16); - } - return new string (array); - } - - static char GetHexValue (int i) => (char) (i < 10 ? i + 48 : i - 10 + 65); - - public static void DeleteFile (string filename, object log) - { - try { - File.Delete (filename); - } catch (Exception ex) { -#if MSBUILD - var helper = log as TaskLoggingHelper; - helper.LogErrorFromException (ex); -#else - Console.Error.WriteLine (ex.ToString ()); -#endif - } - } - - const uint ppdb_signature = 0x424a5342; - - public static bool IsPortablePdb (string filename) - { - try { - using (var fs = new FileStream (filename, FileMode.Open, FileAccess.Read)) { - using (var br = new BinaryReader (fs)) { - return br.ReadUInt32 () == ppdb_signature; - } - } - } - catch { - return false; - } - } - } -} - diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ITaskItemExtensions.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ITaskItemExtensions.cs new file mode 100644 index 00000000000..c40a60e9bfc --- /dev/null +++ b/src/Xamarin.Android.Build.Tasks/Utilities/ITaskItemExtensions.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Xml.Linq; +using Microsoft.Build.Framework; + +namespace Xamarin.Android.Tasks +{ + public static class ITaskItemExtensions + { + public static IEnumerable ToXElements (this ICollection items, string itemName, string[] knownMetadata) + { + foreach (var item in items) { + var e = new XElement (itemName, item.ItemSpec); + foreach (var name in knownMetadata) { + var value = item.GetMetadata (name); + if (!string.IsNullOrEmpty (value)) + e.SetAttributeValue (name, value); + } + yield return e; + } + } + } +} diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/LinePreservedXmlWriter.cs b/src/Xamarin.Android.Build.Tasks/Utilities/LinePreservedXmlWriter.cs deleted file mode 100644 index 34769a8ef4a..00000000000 --- a/src/Xamarin.Android.Build.Tasks/Utilities/LinePreservedXmlWriter.cs +++ /dev/null @@ -1,144 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Xml; -using System.Xml.XPath; - -namespace Monodroid -{ - public class LinePreservedXmlWriter : XmlTextWriter - { - LinePreservedTextWriter tw; - - static LinePreservedTextWriter GetLinePreservedTextWriter (TextWriter w) - { - var tw = w as LinePreservedTextWriter; - if (tw == null) - tw = new LinePreservedTextWriter (w); - return tw; - } - - public LinePreservedXmlWriter (TextWriter w) - : this (GetLinePreservedTextWriter (w)) - { - } - - internal LinePreservedXmlWriter (LinePreservedTextWriter w) - : base (w) - { - this.tw = w; - } - - XPathNavigator nav; - - public override void WriteNode (XPathNavigator navigator, bool defattr) - { - XPathNavigator bak = nav; - this.nav = navigator; - IXmlLineInfo li = navigator as IXmlLineInfo; - if (li != null) - tw.ProceedTo (li.LineNumber, li.LinePosition); - base.WriteNode (navigator, defattr); - this.nav = bak; - } - - public override void WriteStartAttribute (string prefix, string localName, string namespaceUri) - { - if (nav != null) - Proceed (nav as IXmlLineInfo); - base.WriteStartAttribute (prefix, localName, namespaceUri); - } - - public override void WriteStartElement (string prefix, string localName, string namespaceUri) - { - if (nav != null) - Proceed (nav as IXmlLineInfo); - base.WriteStartElement (prefix, localName, namespaceUri); - } - - void Proceed (IXmlLineInfo li) - { - if (li == null || !li.HasLineInfo ()) - return; - tw.ProceedTo (li.LineNumber, li.LinePosition); - } - } - - class LinePreservedTextWriter : TextWriter - { - TextWriter w; - int line = 1; - - public LinePreservedTextWriter (TextWriter w) - { - this.w = w; - } - - public override System.Text.Encoding Encoding { - get { return Encoding.Unicode; } - } - - public void ProceedTo (int line, int column) - { - if (line <= 0) - return; - bool wrote = this.line < line; - while (this.line < line) - WriteLine (); - if (wrote) - Write (new string (' ', column)); - } - - public override void Close () - { - w.Close (); - } - - public override void Flush () - { - w.Flush (); - } - - public override void Write (char value) - { - w.Write (value); - if (value == '\n') - line++; - } - - public override void Write (char[] buffer, int index, int count) - { - w.Write (buffer, index, count); - int next = index; - while (next < index + count) { - int idx = Array.IndexOf (buffer, '\n', next, count + (index - next)); - if (idx < 0) - break; - line++; - next = idx + 1; - } - } - - public override void Write (string value) - { - w.Write (value); - int next = 0; - while (next < value.Length) { - int idx = value.IndexOf ('\n', next); - if (idx < 0) - break; - line++; - next = idx + 1; - } - } - - public override void WriteLine () - { - w.WriteLine (); - line++; - } - } -} - diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/MSBuildExtensions.cs b/src/Xamarin.Android.Build.Tasks/Utilities/MSBuildExtensions.cs deleted file mode 100644 index 6390d045d8d..00000000000 --- a/src/Xamarin.Android.Build.Tasks/Utilities/MSBuildExtensions.cs +++ /dev/null @@ -1,290 +0,0 @@ -using System; -using System.Diagnostics; -using System.Collections.Generic; -using System.IO; -using System.Xml; -using System.Text.RegularExpressions; - -using Microsoft.Build.Utilities; -using Microsoft.Build.Framework; -using Xamarin.Build; - -namespace Xamarin.Android.Tasks -{ - public static class MSBuildExtensions - { - private static bool IsRunningInsideVS { - get { - var vside = false; - return bool.TryParse(Environment.GetEnvironmentVariable("VSIDE"), out vside) && vside; - } - } - - public static void LogDebugMessage (this TaskLoggingHelper log, string message, params object[] messageArgs) - { - log.LogMessage (MessageImportance.Low, message, messageArgs); - } - - public static void LogTaskItems (this TaskLoggingHelper log, string message, ITaskItem[] items) - { - log.LogMessage (message); - - if (items == null) - return; - - foreach (var item in items) - log.LogMessage (" {0}", item.ItemSpec); - } - - public static void LogTaskItems (this TaskLoggingHelper log, string message, params string[] items) - { - log.LogMessage (message); - - if (items == null) - return; - - foreach (var item in items) - log.LogMessage (" {0}", item); - } - - public static void LogDebugTaskItems (this TaskLoggingHelper log, string message, ITaskItem[] items, bool logMetadata = false) - { - log.LogMessage (MessageImportance.Low, message); - - if (items == null) - return; - - foreach (var item in items) { - log.LogMessage (MessageImportance.Low, " {0}", item.ItemSpec); - if (!logMetadata || item.MetadataCount <= 0) - continue; - foreach (string name in item.MetadataNames) - log.LogMessage (MessageImportance.Low, $" {name} = {item.GetMetadata (name)}"); - } - } - - public static void LogDebugTaskItems (this TaskLoggingHelper log, string message, params string[] items) - { - log.LogMessage (MessageImportance.Low, message); - - if (items == null) - return; - - foreach (var item in items) - log.LogMessage (MessageImportance.Low, " {0}", item); - } - - // looking for: mandroid: warning XA9000: message... - static readonly Regex Message = new Regex ( - @"^(?[^: ]+)\s*:\s*(?warning|error) (?[^:]+): (?.*)"); - - public static void LogFromStandardError (this TaskLoggingHelper log, string defaultErrorCode, string message) - { - if (string.IsNullOrEmpty (message)) - return; - - var m = Message.Match (message); - if (!m.Success) { - if (message.IndexOf ("error:", StringComparison.InvariantCultureIgnoreCase) != -1) { - log.LogCodedError (defaultErrorCode, message); - } else { - log.LogMessage (null, defaultErrorCode, null, null, 0, 0, 0, 0, MessageImportance.Low, message); - } - return; - } - - string subcategory = m.Groups ["source"].Value; - string type = m.Groups ["type"].Value; - string code = m.Groups ["code"].Value; - string msg = m.Groups ["message"].Value; - - if (string.IsNullOrEmpty (code)) - code = defaultErrorCode; - - if (type == "warning") - log.LogWarning (subcategory, code, string.Empty, string.Empty, 0, 0, 0, 0, "{0}", msg); - else - log.LogError (subcategory, code, string.Empty, string.Empty, 0, 0, 0, 0, "{0}", msg); - } - - public static void LogDebugTaskItemsAndLogical (this TaskLoggingHelper log, string message, ITaskItem[] items) - { - log.LogMessage (MessageImportance.Low, message); - - if (items == null) - return; - - foreach (var item in items) { - log.LogMessage (MessageImportance.Low, " {0}", item.ItemSpec); - log.LogMessage (MessageImportance.Low, " [{0}]", item.GetMetadata ("LogicalName")); - } - } - - public static void LogCodedError (this TaskLoggingHelper log, string code, string message, params object[] messageArgs) - { - log.LogError (string.Empty, code, string.Empty, string.Empty, 0, 0, 0, 0, message, messageArgs); - } - - public static void LogCodedError (this TaskLoggingHelper log, string code, string file, int lineNumber, string message, params object[] messageArgs) - { - log.LogError (string.Empty, code, string.Empty, file, lineNumber, 0, 0, 0, message, messageArgs); - } - - public static void LogCodedWarning (this TaskLoggingHelper log, string code, string message, params object [] messageArgs) - { - log.LogWarning (string.Empty, code, string.Empty, string.Empty, 0, 0, 0, 0, message, messageArgs); - } - - public static void LogCodedWarning (this TaskLoggingHelper log, string code, string file, int lineNumber, string message, params object [] messageArgs) - { - log.LogWarning (string.Empty, code, string.Empty, file, lineNumber, 0, 0, 0, message, messageArgs); - } - - /// - /// Logs a coded warning from a node in an XML document - /// - /// An element that implements IXmlLineInfo - public static void LogWarningForXmlNode (this TaskLoggingHelper log, string code, string file, object node, string message, params object [] messageArgs) - { - int lineNumber = 0; - int columnNumber = 0; - var lineInfo = node as IXmlLineInfo; - if (lineInfo != null && lineInfo.HasLineInfo ()) { - lineNumber = lineInfo.LineNumber; - columnNumber = lineInfo.LinePosition; - } - log.LogWarning ( - subcategory: string.Empty, - warningCode: code, - helpKeyword: string.Empty, - file: file, - lineNumber: lineNumber, - columnNumber: columnNumber, - endLineNumber: 0, - endColumnNumber: 0, - message: message, - messageArgs: messageArgs - ); - } - - public static Action CreateTaskLogger (this Task task) - { - Action logger = (level, value) => { - switch (level) { - case TraceLevel.Error: - task.Log.LogError ("{0}", value); - break; - case TraceLevel.Warning: - task.Log.LogWarning ("{0}", value); - break; - default: - task.Log.LogDebugMessage ("{0}", value); - break; - } - }; - return logger; - } - - public static Action CreateTaskLogger (this AsyncTask task) - { - Action logger = (level, value) => { - switch (level) { - case TraceLevel.Error: - task.LogError (value); - break; - case TraceLevel.Warning: - task.LogWarning (value); - break; - default: - task.LogDebugMessage (value); - break; - } - }; - return logger; - } - - - public static IEnumerable Concat (params ITaskItem[][] values) - { - if (values == null) - yield break; - foreach (ITaskItem[] v in values) { - if (v == null) - continue; - foreach (ITaskItem t in v) - yield return t; - } - } - - public static string FixupResourceFilename (string file, string resourceDir, Dictionary resourceNameCaseMap) - { - var targetfile = file; - if (resourceDir != null && targetfile.StartsWith (resourceDir, StringComparison.InvariantCultureIgnoreCase)) { - targetfile = file.Substring (resourceDir.Length).TrimStart (Path.DirectorySeparatorChar); - if (resourceNameCaseMap.TryGetValue (targetfile, out string temp)) - targetfile = temp; - targetfile = Path.Combine ("Resources", targetfile); - } - return targetfile; - } - - public static void FixupResourceFilenameAndLogCodedError (this TaskLoggingHelper log, string code, string message, string file, string resourceDir, Dictionary resourceNameCaseMap) - { - var targetfile = FixupResourceFilename (file, resourceDir, resourceNameCaseMap); - log.LogCodedError (code, file: targetfile, lineNumber: 0, message: message); - } - - public static void FixupResourceFilenameAndLogCodedWarning (this TaskLoggingHelper log, string code, string message, string file, string resourceDir, Dictionary resourceNameCaseMap) - { - var targetfile = FixupResourceFilename (file, resourceDir, resourceNameCaseMap); - log.LogCodedWarning (code, file: targetfile, lineNumber: 0, message: message); - } - - /// - /// Sets the default value for %(DestinationSubPath) if it is not already set - /// - public static void SetDestinationSubPath (this ITaskItem assembly) - { - if (string.IsNullOrEmpty (assembly.GetMetadata ("DestinationSubPath"))) { - var directory = assembly.GetMetadata ("DestinationSubDirectory"); - var path = Path.Combine (directory, Path.GetFileName (assembly.ItemSpec)); - assembly.SetMetadata ("DestinationSubPath", path); - } - } - - static readonly string AssemblyLocation = typeof (MSBuildExtensions).Assembly.Location; - - /// - /// IBuildEngine4.RegisterTaskObject, but adds the current assembly path into the key - /// - public static void RegisterTaskObjectAssemblyLocal (this IBuildEngine4 engine, object key, object value, RegisteredTaskObjectLifetime lifetime, bool allowEarlyCollection = false) => - engine.RegisterTaskObject ((AssemblyLocation, key), value, lifetime, allowEarlyCollection); - - /// - /// IBuildEngine4.GetRegisteredTaskObject, but adds the current assembly path into the key - /// - public static object GetRegisteredTaskObjectAssemblyLocal (this IBuildEngine4 engine, object key, RegisteredTaskObjectLifetime lifetime) => - engine.GetRegisteredTaskObject ((AssemblyLocation, key), lifetime); - - /// - /// Generic version of IBuildEngine4.GetRegisteredTaskObject, but adds the current assembly path into the key - /// - public static T GetRegisteredTaskObjectAssemblyLocal (this IBuildEngine4 engine, object key, RegisteredTaskObjectLifetime lifetime) - where T : class => - engine.GetRegisteredTaskObject ((AssemblyLocation, key), lifetime) as T; - - - /// - /// IBuildEngine4.UnregisterTaskObject, but adds the current assembly path into the key - /// - public static object UnregisterTaskObjectAssemblyLocal (this IBuildEngine4 engine, object key, RegisteredTaskObjectLifetime lifetime) => - engine.UnregisterTaskObject ((AssemblyLocation, key), lifetime); - - /// - /// Generic version of IBuildEngine4.UnregisterTaskObject, but adds the current assembly path into the key - /// - public static T UnregisterTaskObjectAssemblyLocal (this IBuildEngine4 engine, object key, RegisteredTaskObjectLifetime lifetime) - where T : class => - engine.UnregisterTaskObject ((AssemblyLocation, key), lifetime) as T; - } -} diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ManagedResourceParser.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ManagedResourceParser.cs index 93756cfeb6a..3c90e7891a0 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/ManagedResourceParser.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/ManagedResourceParser.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.CodeDom; using System.Collections.Generic; using System.IO; @@ -9,6 +9,8 @@ using System.Xml.XPath; using System.Text.RegularExpressions; using System.Text; +using Microsoft.Android.Build.Tasks; + namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs index d5145102821..5fd2838ea47 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs @@ -23,6 +23,7 @@ using System.Xml; using System.Text; using Xamarin.Android.Tools; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -918,7 +919,7 @@ public bool SaveIfChanged (TaskLoggingHelper log, string filename) MemoryStream stream = MemoryStreamPool.Shared.Rent (); try { Save (log, stream); - return MonoAndroidHelper.CopyIfStreamChanged (stream, filename); + return Files.CopyIfStreamChanged (stream, filename); } finally { MemoryStreamPool.Shared.Return (stream); } @@ -929,7 +930,7 @@ public void Save (TaskLoggingHelper log, string filename) => public void Save (Action logCodedWarning, string filename) { - using (var file = new StreamWriter (filename, append: false, encoding: MonoAndroidHelper.UTF8withoutBOM)) + using (var file = new StreamWriter (filename, append: false, encoding: Files.UTF8withoutBOM)) Save (logCodedWarning, file); } @@ -938,7 +939,7 @@ public void Save (TaskLoggingHelper log, Stream stream, bool removeNodes = false public void Save (Action logCodedWarning, Stream stream, bool removeNodes = false) { - using (var file = new StreamWriter (stream, MonoAndroidHelper.UTF8withoutBOM, bufferSize: 1024, leaveOpen: true)) + using (var file = new StreamWriter (stream, Files.UTF8withoutBOM, bufferSize: 1024, leaveOpen: true)) Save (logCodedWarning, file, removeNodes: removeNodes); } diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/MemoryStreamPool.cs b/src/Xamarin.Android.Build.Tasks/Utilities/MemoryStreamPool.cs deleted file mode 100644 index cd8883416a3..00000000000 --- a/src/Xamarin.Android.Build.Tasks/Utilities/MemoryStreamPool.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System.IO; -using System.Text; - -namespace Xamarin.Android.Tasks -{ - /// - /// A class for pooling and reusing MemoryStream objects. - /// - /// Based on: - /// https://docs.microsoft.com/dotnet/standard/collections/thread-safe/how-to-create-an-object-pool - /// https://docs.microsoft.com/dotnet/api/system.buffers.arraypool-1 - /// - class MemoryStreamPool : ObjectPool - { - /// - /// Static instance across the entire process. Use this most of the time. - /// - public static readonly MemoryStreamPool Shared = new MemoryStreamPool (); - - public MemoryStreamPool () : base (() => new MemoryStream ()) { } - - public override void Return (MemoryStream stream) - { - // We want to throw here before base.Return() if it was disposed - stream.SetLength (0); - base.Return (stream); - } - - /// - /// Creates a StreamWriter that uses the underlying MemoryStreamPool. Calling Dispose() will Return() the MemoryStream. - /// By default uses MonoAndroidHelper.UTF8withoutBOM for the encoding. - /// - public StreamWriter CreateStreamWriter () => CreateStreamWriter (MonoAndroidHelper.UTF8withoutBOM); - - /// - /// Creates a StreamWriter that uses the underlying MemoryStreamPool. Calling Dispose() will Return() the MemoryStream. - /// - public StreamWriter CreateStreamWriter (Encoding encoding) => new ReturningStreamWriter (this, Rent (), encoding); - - /// - /// Creates a BinaryWriter that uses the underlying MemoryStreamPool. Calling Dispose() will Return() the MemoryStream. - /// By default uses MonoAndroidHelper.UTF8withoutBOM for the encoding. - /// - public BinaryWriter CreateBinaryWriter () => CreateBinaryWriter (MonoAndroidHelper.UTF8withoutBOM); - - /// - /// Creates a BinaryWriter that uses the underlying MemoryStreamPool. Calling Dispose() will Return() the MemoryStream. - /// - public BinaryWriter CreateBinaryWriter (Encoding encoding) => new ReturningBinaryWriter (this, Rent (), encoding); - - class ReturningStreamWriter : StreamWriter - { - readonly MemoryStreamPool pool; - readonly MemoryStream stream; - bool returned; - - public ReturningStreamWriter (MemoryStreamPool pool, MemoryStream stream, Encoding encoding) - : base (stream, encoding, bufferSize: 8 * 1024, leaveOpen: true) - { - this.pool = pool; - this.stream = stream; - } - - protected override void Dispose (bool disposing) - { - base.Dispose (disposing); - - //NOTE: Dispose() can be called multiple times - if (disposing && !returned) { - returned = true; - pool.Return (stream); - } - } - } - - class ReturningBinaryWriter : BinaryWriter - { - readonly MemoryStreamPool pool; - readonly MemoryStream stream; - bool returned; - - public ReturningBinaryWriter (MemoryStreamPool pool, MemoryStream stream, Encoding encoding) - : base (stream, encoding, leaveOpen: true) - { - this.pool = pool; - this.stream = stream; - } - - protected override void Dispose (bool disposing) - { - base.Dispose (disposing); - - //NOTE: Dispose() can be called multiple times - if (disposing && !returned) { - returned = true; - pool.Return (stream); - } - } - } - } -} diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs index 007fe83305a..2009451e793 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs @@ -9,6 +9,7 @@ using System.Text; using Xamarin.Android.Tools; using Xamarin.Tools.Zip; +using Microsoft.Android.Build.Tasks; #if MSBUILD using Microsoft.Build.Framework; @@ -26,9 +27,6 @@ public partial class MonoAndroidHelper public static AndroidVersions SupportedVersions; public static AndroidSdkInfo AndroidSdk; - public static readonly Encoding UTF8withoutBOM = new UTF8Encoding (encoderShouldEmitUTF8Identifier: false); - readonly static byte[] Utf8Preamble = Encoding.UTF8.GetPreamble (); - public static int RunProcess (string name, string args, DataReceivedEventHandler onOutput, DataReceivedEventHandler onError, Dictionary environmentVariables = null) { var psi = new ProcessStartInfo (name, args) { @@ -90,12 +88,10 @@ internal static string GetOSLibPath () } #if MSBUILD - static TaskLoggingHelper androidSdkLogger; - public static void RefreshAndroidSdk (string sdkPath, string ndkPath, string javaPath, TaskLoggingHelper logHelper = null) { Action logger = (level, value) => { - var log = logHelper ?? androidSdkLogger; + var log = logHelper; switch (level) { case TraceLevel.Error: if (log == null) @@ -197,16 +193,6 @@ public static IEnumerable DistinctFilesByContent (IEnumerable DistinctFilesByContent (IEnumerable filePaths) @@ -247,14 +233,6 @@ public static void LogWarning (object log, string msg, params object [] args) } #if MSBUILD - - static readonly string[] ValidAbis = new[]{ - "arm64-v8a", - "armeabi-v7a", - "x86", - "x86_64", - }; - static readonly Dictionary ClangAbiMap = new Dictionary (StringComparer.OrdinalIgnoreCase) { {"arm64-v8a", "aarch64"}, {"armeabi-v7a", "arm"}, @@ -269,48 +247,6 @@ public static string MapAndroidAbiToClang (string androidAbi) } return null; } - - public static string GetNativeLibraryAbi (string lib) - { - // The topmost directory the .so file is contained within - var dir = Path.GetFileName (Path.GetDirectoryName (lib)).ToLowerInvariant (); - if (dir.StartsWith ("interpreter-", StringComparison.Ordinal)) { - dir = dir.Substring (12); - } - if (ValidAbis.Contains (dir)) { - return dir; - } - return null; - } - - public static string GetNativeLibraryAbi (ITaskItem lib) - { - // If Abi is explicitly specified, simply return it. - var lib_abi = lib.GetMetadata ("Abi"); - - if (!string.IsNullOrWhiteSpace (lib_abi)) - return lib_abi; - - // Try to figure out what type of abi this is from the path - // First, try nominal "Link" path. - var link = lib.GetMetadata ("Link"); - if (!string.IsNullOrWhiteSpace (link)) { - var linkdirs = link.ToLowerInvariant ().Split ('/', '\\'); - lib_abi = ValidAbis.Where (p => linkdirs.Contains (p)).FirstOrDefault (); - } - - // Check for a RuntimeIdentifier - var rid = lib.GetMetadata ("RuntimeIdentifier"); - if (!string.IsNullOrWhiteSpace (rid)) { - lib_abi = RuntimeIdentifierToAbi (rid); - } - - if (!string.IsNullOrWhiteSpace (lib_abi)) - return lib_abi; - - // If not resolved, use ItemSpec - return GetNativeLibraryAbi (lib.ItemSpec); - } #endif public static bool IsMonoAndroidAssembly (ITaskItem assembly) @@ -360,82 +296,22 @@ public static bool IsForceRetainedAssembly (string assembly) return false; } - public static void SetWriteable (string source, bool checkExists = true) - { - if (checkExists && !File.Exists (source)) - return; - - var attributes = File.GetAttributes (source); - if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) - File.SetAttributes (source, attributes & ~FileAttributes.ReadOnly); - } - - public static void SetDirectoryWriteable (string directory) - { - if (!Directory.Exists (directory)) - return; - - var dirInfo = new DirectoryInfo (directory); - if ((dirInfo.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) - dirInfo.Attributes &= ~FileAttributes.ReadOnly; - - foreach (var dir in Directory.EnumerateDirectories (directory, "*", SearchOption.AllDirectories)) { - dirInfo = new DirectoryInfo (dir); - if ((dirInfo.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) - dirInfo.Attributes &= ~FileAttributes.ReadOnly; - } - - foreach (var file in Directory.EnumerateFiles (directory, "*", SearchOption.AllDirectories)) { - SetWriteable (Path.GetFullPath (file)); - } - } - public static bool CopyAssemblyAndSymbols (string source, string destination) { - bool changed = CopyIfChanged (source, destination); + bool changed = Files.CopyIfChanged (source, destination); var mdb = source + ".mdb"; if (File.Exists (mdb)) { var mdbDestination = destination + ".mdb"; - CopyIfChanged (mdb, mdbDestination); + Files.CopyIfChanged (mdb, mdbDestination); } var pdb = Path.ChangeExtension (source, "pdb"); if (File.Exists (pdb) && Files.IsPortablePdb (pdb)) { var pdbDestination = Path.ChangeExtension (destination, "pdb"); - CopyIfChanged (pdb, pdbDestination); + Files.CopyIfChanged (pdb, pdbDestination); } return changed; } - public static bool CopyIfChanged (string source, string destination) - { - return Files.CopyIfChanged (source, destination); - } - - public static bool CopyIfStringChanged (string contents, string destination) - { - return Files.CopyIfStringChanged (contents, destination); - } - - public static bool CopyIfBytesChanged (byte [] bytes, string destination) - { - return Files.CopyIfBytesChanged (bytes, destination); - } - - public static bool CopyIfStreamChanged (Stream source, string destination) - { - return Files.CopyIfStreamChanged (source, destination); - } - - public static bool CopyIfZipChanged (Stream source, string destination) - { - return Files.CopyIfZipChanged (source, destination); - } - - public static bool CopyIfZipChanged (string source, string destination) - { - return Files.CopyIfZipChanged (source, destination); - } - public static ZipArchive ReadZipFile (string filename) { try { @@ -445,87 +321,6 @@ public static ZipArchive ReadZipFile (string filename) } } - public static bool IsValidZip (string filename) - { - try { - using (var zip = Files.ReadZipFile (filename, strictConsistencyChecks: true)) { - } - } catch (ZipIOException) { - return false; - } - return true; - } - - public static string HashFile (string filename) - { - return Files.HashFile (filename); - } - - public static string HashFile (string filename, HashAlgorithm hashAlg) - { - return Files.HashFile (filename, hashAlg); - } - - public static string HashStream (Stream stream) - { - return Files.HashStream (stream); - } - - public static string HashBytes (byte[] bytes) - { - return Files.HashBytes (bytes); - } - - public static bool HasFileChanged (string source, string destination) - { - return Files.HasFileChanged (source, destination); - } - - /// - /// Open a file given its path and remove the 3 bytes UTF-8 BOM if there is one - /// - public static void CleanBOM (string filePath) - { - if (string.IsNullOrEmpty (filePath) || !File.Exists (filePath)) - return; - - string temp = null; - try { - using (var input = File.OpenRead (filePath)) { - // Check if the file actually has a BOM - for (int i = 0; i < Utf8Preamble.Length; i++) { - var next = input.ReadByte (); - if (next == -1) - return; - if (Utf8Preamble [i] != (byte) next) - return; - } - - temp = Path.GetTempFileName (); - using (var stream = File.OpenWrite (temp)) - input.CopyTo (stream); - } - - SetWriteable (filePath); - File.Delete (filePath); - File.Copy (temp, filePath); - } finally { - if (temp != null) { - File.Delete (temp); - } - } - } - - public static bool IsRawResourcePath (string projectPath) - { - // Extract resource type folder name - var dir = Path.GetDirectoryName (projectPath); - var name = Path.GetFileName (dir); - - return string.Equals (name, "raw", StringComparison.OrdinalIgnoreCase) - || name.StartsWith ("raw-", StringComparison.OrdinalIgnoreCase); - } - #if MSBUILD internal static IEnumerable GetFrameworkAssembliesToTreatAsUserAssemblies (ITaskItem[] resolvedAssemblies) { @@ -581,7 +376,7 @@ public static bool SaveCustomViewMapFile (IBuildEngine4 engine, string mapFile, writer.WriteLine ($"{i.Key};{v}"); } writer.Flush (); - return CopyIfStreamChanged (writer.BaseStream, mapFile); + return Files.CopyIfStreamChanged (writer.BaseStream, mapFile); } } @@ -669,38 +464,5 @@ public static string GetRelativePathForAndroidAsset (string assetsDirectory, ITa path = head.Length == path.Length ? path : path.Substring ((head.Length == 0 ? 0 : head.Length + 1) + assetsDirectory.Length).TrimStart (DirectorySeparators); return path; } - - /// - /// Converts .NET 5 RIDs to Android ABIs or an empty string if no match. - /// - /// Known RIDs: - /// "android.21-arm64" -> "arm64-v8a" - /// "android.21-arm" -> "armeabi-v7a" - /// "android.21-x86" -> "x86" - /// "android.21-x64" -> "x86_64" - /// "android-arm64" -> "arm64-v8a" - /// "android-arm" -> "armeabi-v7a" - /// "android-x86" -> "x86" - /// "android-x64" -> "x86_64" - /// - public static string RuntimeIdentifierToAbi (string runtimeIdentifier) - { - if (string.IsNullOrEmpty (runtimeIdentifier)) { - return ""; - } - if (runtimeIdentifier.EndsWith ("-arm64", StringComparison.OrdinalIgnoreCase)) { - return "arm64-v8a"; - } - if (runtimeIdentifier.EndsWith ("-arm", StringComparison.OrdinalIgnoreCase)) { - return "armeabi-v7a"; - } - if (runtimeIdentifier.EndsWith ("-x86", StringComparison.OrdinalIgnoreCase)) { - return "x86"; - } - if (runtimeIdentifier.EndsWith ("-x64", StringComparison.OrdinalIgnoreCase)) { - return "x86_64"; - } - return ""; - } } } diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ObjectPool.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ObjectPool.cs deleted file mode 100644 index 0a079145873..00000000000 --- a/src/Xamarin.Android.Build.Tasks/Utilities/ObjectPool.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Concurrent; - -namespace Xamarin.Android.Tasks -{ - /// - /// A class for pooling and reusing objects. See MemoryStreamPool. - /// - /// Based on: - /// https://docs.microsoft.com/dotnet/standard/collections/thread-safe/how-to-create-an-object-pool - /// https://docs.microsoft.com/dotnet/api/system.buffers.arraypool-1 - /// - class ObjectPool - { - readonly ConcurrentBag bag = new ConcurrentBag(); - readonly Func generator; - - public ObjectPool (Func generator) - { - if (generator == null) - throw new ArgumentNullException (nameof (generator)); - this.generator = generator; - } - - public virtual T Rent () - { - if (bag.TryTake (out T item)) - return item; - return generator (); - } - - public virtual void Return (T item) - { - bag.Add (item); - } - } -} diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ResourceDesignerImportGenerator.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ResourceDesignerImportGenerator.cs index 125ea416b65..8e7ddacfd3e 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/ResourceDesignerImportGenerator.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/ResourceDesignerImportGenerator.cs @@ -7,6 +7,7 @@ using System.Reflection.PortableExecutable; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ResourceParser.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ResourceParser.cs index 633dd925693..d85b97299e9 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/ResourceParser.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/ResourceParser.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.CodeDom; using System.CodeDom.Compiler; using System.Collections.Generic; @@ -7,6 +7,7 @@ using System.Reflection; using System.Text.RegularExpressions; using Microsoft.Build.Utilities; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/TypeMapGenerator.cs b/src/Xamarin.Android.Build.Tasks/Utilities/TypeMapGenerator.cs index 7ab407f45ee..e17bc1e481a 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/TypeMapGenerator.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/TypeMapGenerator.cs @@ -6,6 +6,7 @@ using Java.Interop.Tools.Cecil; using Mono.Cecil; +using Microsoft.Android.Build.Tasks; namespace Xamarin.Android.Tasks { @@ -112,7 +113,7 @@ public TypeMapGenerator (Action logger, string[] supportedAbis) throw new ArgumentNullException (nameof (supportedAbis)); this.supportedAbis = supportedAbis; - outputEncoding = MonoAndroidHelper.UTF8withoutBOM; + outputEncoding = Files.UTF8withoutBOM; moduleMagicString = outputEncoding.GetBytes (TypeMapMagicString); typemapIndexMagicString = outputEncoding.GetBytes (TypeMapIndexMagicString); } @@ -215,7 +216,7 @@ bool GenerateDebugFiles (bool skipJniAddNativeMethodRegistrationAttributeScan, L using (var indexWriter = MemoryStreamPool.Shared.CreateBinaryWriter ()) { OutputModules (modules, indexWriter, maxModuleFileNameWidth + 1); indexWriter.Flush (); - MonoAndroidHelper.CopyIfStreamChanged (indexWriter.BaseStream, typeMapIndexPath); + Files.CopyIfStreamChanged (indexWriter.BaseStream, typeMapIndexPath); } GeneratedBinaryTypeMaps.Add (typeMapIndexPath); @@ -479,7 +480,7 @@ void GenerateNativeAssembly (Func task.LogCodedError (code, message), prefix, ex); - } - - public static void LogUnhandledException (this TaskLoggingHelper log, string prefix, Exception ex) - { - LogUnhandledException ((code, message) => log.LogCodedError (code, message), prefix, ex); - } - - static void LogUnhandledException (Action logCodedError, string prefix, Exception ex) - { - prefix = "XA" + prefix; - - // Some ordering is necessary here to ensure exceptions are before their base exceptions - if (ex is NullReferenceException) - logCodedError (prefix + "7001", ex.ToString ()); - else if (ex is ArgumentOutOfRangeException) // ArgumentException - logCodedError (prefix + "7002", ex.ToString ()); - else if (ex is ArgumentNullException) // ArgumentException - logCodedError (prefix + "7003", ex.ToString ()); - else if (ex is ArgumentException) - logCodedError (prefix + "7004", ex.ToString ()); - else if (ex is FormatException) - logCodedError (prefix + "7005", ex.ToString ()); - else if (ex is IndexOutOfRangeException) - logCodedError (prefix + "7006", ex.ToString ()); - else if (ex is InvalidCastException) - logCodedError (prefix + "7007", ex.ToString ()); - else if (ex is ObjectDisposedException) // InvalidOperationException - logCodedError (prefix + "7008", ex.ToString ()); - else if (ex is InvalidOperationException) - logCodedError (prefix + "7009", ex.ToString ()); - else if (ex is InvalidProgramException) - logCodedError (prefix + "7010", ex.ToString ()); - else if (ex is KeyNotFoundException) - logCodedError (prefix + "7011", ex.ToString ()); - else if (ex is TaskCanceledException) // OperationCanceledException - logCodedError (prefix + "7012", ex.ToString ()); - else if (ex is OperationCanceledException) - logCodedError (prefix + "7013", ex.ToString ()); - else if (ex is OutOfMemoryException) - logCodedError (prefix + "7014", ex.ToString ()); - else if (ex is NotSupportedException) - logCodedError (prefix + "7015", ex.ToString ()); - else if (ex is StackOverflowException) - logCodedError (prefix + "7016", ex.ToString ()); - else if (ex is TimeoutException) - logCodedError (prefix + "7017", ex.ToString ()); - else if (ex is TypeInitializationException) - logCodedError (prefix + "7018", ex.ToString ()); - else if (ex is UnauthorizedAccessException) - logCodedError (prefix + "7019", ex.ToString ()); - else if (ex is ApplicationException) - logCodedError (prefix + "7020", ex.ToString ()); - else if (ex is KeyNotFoundException) - logCodedError (prefix + "7021", ex.ToString ()); - else if (ex is PathTooLongException) // IOException - logCodedError (prefix + "7022", ex.ToString ()); - else if (ex is DirectoryNotFoundException) // IOException - logCodedError (prefix + "7023", ex.ToString ()); - else if (ex is DriveNotFoundException) // IOException - logCodedError (prefix + "7025", ex.ToString ()); - else if (ex is EndOfStreamException) // IOException - logCodedError (prefix + "7026", ex.ToString ()); - else if (ex is FileLoadException) // IOException - logCodedError (prefix + "7027", ex.ToString ()); - else if (ex is FileNotFoundException) // IOException - logCodedError (prefix + "7028", ex.ToString ()); - else if (ex is IOException) - logCodedError (prefix + "7024", ex.ToString ()); - else - logCodedError (prefix + "7000", ex.ToString ()); - } - } -} diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/XDocumentExtensions.cs b/src/Xamarin.Android.Build.Tasks/Utilities/XDocumentExtensions.cs deleted file mode 100644 index 1d28c458df8..00000000000 --- a/src/Xamarin.Android.Build.Tasks/Utilities/XDocumentExtensions.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Xml.XPath; -using System.Xml.Linq; -using Microsoft.Build.Framework; -using Microsoft.Build.Utilities; - -namespace Xamarin.Android.Tasks -{ - public static class XDocumentExtensions - { - const string PathsElementName = "Paths"; - - public static ITaskItem[] GetPathsAsTaskItems (this XDocument doc, params string[] paths) - { - var e = doc.Elements (PathsElementName); - foreach (var p in paths) - e = e.Elements (p); - return e.Select (ToTaskItem).ToArray (); - } - - static ITaskItem ToTaskItem (XElement element) - { - var taskItem = new TaskItem (element.Value); - foreach (var attribute in element.Attributes ()) { - taskItem.SetMetadata (attribute.Name.LocalName, attribute.Value); - } - return taskItem; - } - - public static IEnumerable ToXElements (ICollection items, string itemName, string[] knownMetadata) - { - foreach (var item in items) { - var e = new XElement (itemName, item.ItemSpec); - foreach (var name in knownMetadata) { - var value = item.GetMetadata (name); - if (!string.IsNullOrEmpty (value)) - e.SetAttributeValue (name, value); - } - yield return e; - } - } - - public static string[] GetPaths (this XDocument doc, params string[] paths) - { - var e = doc.Elements (PathsElementName); - foreach (var p in paths) - e = e.Elements (p); - return e.Select (p => p.Value).ToArray (); - } - - public static string ToFullString (this XElement element) - { - return element.ToString (SaveOptions.DisableFormatting); - } - - public static bool SaveIfChanged (this XDocument document, string fileName) - { - using (var sw = MemoryStreamPool.Shared.CreateStreamWriter ()) - using (var xw = new Monodroid.LinePreservedXmlWriter (sw)) { - xw.WriteNode (document.CreateNavigator (), false); - xw.Flush (); - return MonoAndroidHelper.CopyIfStreamChanged (sw.BaseStream, fileName); - } - } - } -} - diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj index 872db509c50..a381162ec94 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj @@ -4,7 +4,7 @@ - + @@ -55,7 +55,6 @@ - @@ -447,6 +446,7 @@ False + diff --git a/tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj b/tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj index f696cfcf399..02917b93625 100644 --- a/tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj +++ b/tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj @@ -8,7 +8,7 @@ - +