public void UseLatestAndroidSdk(string buildtools, string jdk, ApiInfo[] apis, bool useLatestAndroidSdk, string targetFrameworkVersion, bool expectedTaskResult, string expectedTargetFramework, string expectedError = "", string expectedErrorMessage = "")
        {
            var          path           = Path.Combine("temp", "UseLatestAndroidSdk_" + Guid.NewGuid());
            var          androidSdkPath = CreateFauxAndroidSdkDirectory(Path.Combine(path, "android-sdk"), buildtools, apis);
            var          androidNdkPath = CreateFauxAndroidNdkDirectory(Path.Combine(path, "android-ndk"));
            string       javaExe        = string.Empty;
            string       javacExe;
            var          javaPath      = CreateFauxJavaSdkDirectory(Path.Combine(path, "jdk"), jdk, out javaExe, out javacExe);
            var          referencePath = CreateFauxReferencesDirectory(Path.Combine(path, "references"), apis);
            var          errors        = new List <BuildErrorEventArgs> ();
            IBuildEngine engine        = new MockBuildEngine(TestContext.Out, errors);
            var          resolveSdks   = new ResolveSdks {
                BuildEngine    = engine,
                AndroidSdkPath = androidSdkPath,
                AndroidNdkPath = androidNdkPath,
                JavaSdkPath    = javaPath,
                MinimumSupportedJavaVersion = MinimumSupportedJavaVersion,
                LatestSupportedJavaVersion  = LatestSupportedJavaVersion,
                ReferenceAssemblyPaths      = new [] {
                    Path.Combine(referencePath, "MonoAndroid"),
                },
            };
            var validateJavaVersion = new ValidateJavaVersion {
                BuildEngine                 = engine,
                TargetFrameworkVersion      = targetFrameworkVersion,
                AndroidSdkBuildToolsVersion = buildtools,
                JavaSdkPath                 = javaPath,
                JavaToolExe                 = javaExe,
                JavacToolExe                = javacExe,
                LatestSupportedJavaVersion  = "1.8.0",
                MinimumSupportedJavaVersion = "1.7.0",
            };
            var androidTooling = new ResolveAndroidTooling {
                BuildEngine                 = engine,
                AndroidSdkPath              = androidSdkPath,
                TargetFrameworkVersion      = targetFrameworkVersion,
                AndroidSdkBuildToolsVersion = buildtools,
                UseLatestAndroidPlatformSdk = useLatestAndroidSdk,
                AotAssemblies               = false,
                SequencePointsMode          = "None",
                AndroidApplication          = true,
            };

            Assert.AreEqual(expectedTaskResult, resolveSdks.Execute() && validateJavaVersion.Execute() && androidTooling.Execute(), $"Tasks should have {(expectedTaskResult ? "succeeded" : "failed" )}.");
            Assert.AreEqual(expectedTargetFramework, androidTooling.TargetFrameworkVersion, $"TargetFrameworkVersion should be {expectedTargetFramework} but was {androidTooling.TargetFrameworkVersion}");
            if (!string.IsNullOrWhiteSpace(expectedError))
            {
                Assert.AreEqual(1, errors.Count(), "An error should have been raised.");
                Assert.AreEqual(expectedError, errors [0].Code, $"Expected error code {expectedError} but found {errors [0].Code}");
                Assert.AreEqual(expectedErrorMessage, errors [0].Message, $"Expected error code {expectedErrorMessage} but found {errors [0].Message}");
            }
            Directory.Delete(Path.Combine(Root, path), recursive: true);
        }
Пример #2
0
        public void CacheInvalidates()
        {
            var javaPath            = CreateFauxJavaSdkDirectory(Path.Combine(path, "jdk-1"), "1.8.0", out string javaExe, out string javacExe);
            var validateJavaVersion = new ValidateJavaVersion {
                BuildEngine  = engine,
                JavaSdkPath  = javaPath,
                JavaToolExe  = javaExe,
                JavacToolExe = javacExe,
                LatestSupportedJavaVersion  = "1.8.0",
                MinimumSupportedJavaVersion = "1.7.0",
            };

            Assert.IsTrue(validateJavaVersion.Execute(), "first Execute should succeed!");

            messages.Clear();

            javaPath = CreateFauxJavaSdkDirectory(Path.Combine(path, "jdk-2"), "1.8.0", out javaExe, out javacExe);
            validateJavaVersion.JavaSdkPath = javaPath;

            Assert.IsTrue(validateJavaVersion.Execute(), "second Execute should succeed!");
            Assert.IsFalse(messages.Any(m => m.Message.StartsWith("Using cached value for")), "`java -version` should *not* be cached!");
        }
Пример #3
0
        public void CacheWorks()
        {
            var javaPath            = CreateFauxJavaSdkDirectory(Path.Combine(path, "jdk"), "1.8.0", out string javaExe, out string javacExe);
            var validateJavaVersion = new ValidateJavaVersion {
                BuildEngine  = engine,
                JavaSdkPath  = javaPath,
                JavaToolExe  = javaExe,
                JavacToolExe = javacExe,
                LatestSupportedJavaVersion  = "1.8.0",
                MinimumSupportedJavaVersion = "1.7.0",
            };

            Assert.IsTrue(validateJavaVersion.Execute(), "first Execute should succeed!");

            messages.Clear();

            Assert.IsTrue(validateJavaVersion.Execute(), "second Execute should succeed!");
            var javaFullPath  = Path.Combine(javaPath, "bin", javaExe);
            var javacFullPath = Path.Combine(javaPath, "bin", javacExe);

            Assert.IsTrue(messages.Any(m => m.Message == $"Using cached value for `{javaFullPath} -version`: 1.8.0"), "`java -version` should be cached!");
            Assert.IsTrue(messages.Any(m => m.Message == $"Using cached value for `{javacFullPath} -version`: 1.8.0"), "`javac -version` should be cached!");
        }
Пример #4
0
        public void BuildTools27_Requires_1_8_0()
        {
            var javaPath            = CreateFauxJavaSdkDirectory(Path.Combine(path, "jdk"), "1.7.0", out string javaExe, out string javacExe);
            var validateJavaVersion = new ValidateJavaVersion {
                BuildEngine = engine,
                AndroidSdkBuildToolsVersion = "27.0.0",
                JavaSdkPath  = javaPath,
                JavaToolExe  = javaExe,
                JavacToolExe = javacExe,
                LatestSupportedJavaVersion  = "1.8.0",
                MinimumSupportedJavaVersion = "1.7.0",
            };

            Assert.False(validateJavaVersion.Execute(), "Execute should *not* succeed!");
            Assert.IsTrue(errors.Any(e => e.Message == $"Java SDK 1.8 or above is required when using Android SDK Build-Tools {validateJavaVersion.AndroidSdkBuildToolsVersion}."), "Should get error about build-tools=27.0.0");
        }
Пример #5
0
        public void TargetFramework8_1_Requires_1_8_0()
        {
            var javaPath            = CreateFauxJavaSdkDirectory(Path.Combine(path, "jdk"), "1.7.0", out string javaExe, out string javacExe);
            var validateJavaVersion = new ValidateJavaVersion {
                BuildEngine                 = engine,
                TargetFrameworkVersion      = "v8.1",
                JavaSdkPath                 = javaPath,
                JavaToolExe                 = javaExe,
                JavacToolExe                = javacExe,
                LatestSupportedJavaVersion  = "1.8.0",
                MinimumSupportedJavaVersion = "1.7.0",
            };

            Assert.False(validateJavaVersion.Execute(), "Execute should *not* succeed!");
            Assert.IsTrue(errors.Any(e => e.Message == $"Java SDK 1.8 or above is required when using $(TargetFrameworkVersion) {validateJavaVersion.TargetFrameworkVersion}."), "Should get error about TargetFrameworkVersion=v8.1");
        }
Пример #6
0
        public void ResolveSdkTiming()
        {
            var    path           = Path.Combine("temp", TestName);
            var    androidSdkPath = CreateFauxAndroidSdkDirectory(Path.Combine(path, "android-sdk"), "26.0.3");
            var    androidNdkPath = CreateFauxAndroidNdkDirectory(Path.Combine(path, "android-ndk"));
            string javaExe        = string.Empty;
            string javacExe;
            var    javaPath      = CreateFauxJavaSdkDirectory(Path.Combine(path, "jdk"), "1.8.0", out javaExe, out javacExe);
            var    referencePath = CreateFauxReferencesDirectory(Path.Combine(path, "references"), new ApiInfo [] {
                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
                },
            });
            IBuildEngine engine      = new MockBuildEngine(TestContext.Out);
            var          resolveSdks = new ResolveSdks {
                BuildEngine            = engine,
                AndroidSdkPath         = androidSdkPath,
                AndroidNdkPath         = androidNdkPath,
                JavaSdkPath            = javaPath,
                ReferenceAssemblyPaths = new [] {
                    Path.Combine(referencePath, "MonoAndroid"),
                },
            };
            var validateJavaVersion = new ValidateJavaVersion {
                BuildEngine                 = engine,
                TargetFrameworkVersion      = "v8.0",
                AndroidSdkBuildToolsVersion = "26.0.3",
                JavaSdkPath                 = javaPath,
                JavaToolExe                 = javaExe,
                JavacToolExe                = javacExe,
                LatestSupportedJavaVersion  = "1.8.0",
                MinimumSupportedJavaVersion = "1.7.0",
            };
            var androidTooling = new ResolveAndroidTooling {
                BuildEngine                 = engine,
                AndroidSdkPath              = androidSdkPath,
                TargetFrameworkVersion      = "v8.0",
                AndroidSdkBuildToolsVersion = "26.0.3",
                UseLatestAndroidPlatformSdk = false,
                AotAssemblies               = false,
                SequencePointsMode          = "None",
                AndroidApplication          = true,
            };
            var start = DateTime.UtcNow;

            Assert.IsTrue(resolveSdks.Execute(), "ResolveSdks should succeed!");
            Assert.IsTrue(validateJavaVersion.Execute(), "ValidateJavaVersion should succeed!");
            Assert.IsTrue(androidTooling.Execute(), "ResolveAndroidTooling should succeed!");
            var executionTime = DateTime.UtcNow - start;

            Assert.LessOrEqual(executionTime, TimeSpan.FromSeconds(2), "Task should not take more than 2 seconds to run.");
            Assert.AreEqual(androidTooling.AndroidApiLevel, "26", "AndroidApiLevel should be 26");
            Assert.AreEqual(androidTooling.TargetFrameworkVersion, "v8.0", "TargetFrameworkVersion should be v8.0");
            Assert.AreEqual(androidTooling.AndroidApiLevelName, "26", "AndroidApiLevelName should be 26");
            Assert.NotNull(resolveSdks.ReferenceAssemblyPaths, "ReferenceAssemblyPaths should not be null.");
            Assert.AreEqual(resolveSdks.ReferenceAssemblyPaths.Length, 1, "ReferenceAssemblyPaths should have 1 entry.");
            Assert.AreEqual(resolveSdks.ReferenceAssemblyPaths[0], Path.Combine(referencePath, "MonoAndroid"), $"ReferenceAssemblyPaths should be {Path.Combine (referencePath, "MonoAndroid")}.");
            var expected = Path.Combine(Root);

            Assert.AreEqual(resolveSdks.MonoAndroidToolsPath, expected, $"MonoAndroidToolsPath should be {expected}");
            expected += Path.DirectorySeparatorChar;
            if (resolveSdks.MonoAndroidBinPath != expected)
            {
                //For non-Windows platforms, remove a directory such as "Darwin", MonoAndroidBinPath also has a trailing /
                var binPath = Path.GetDirectoryName(Path.GetDirectoryName(resolveSdks.MonoAndroidBinPath)) + Path.DirectorySeparatorChar;
                Assert.AreEqual(binPath, expected, $"MonoAndroidBinPath should be {expected}");
            }
            Assert.AreEqual(resolveSdks.AndroidSdkPath, androidSdkPath, $"AndroidSdkPath should be {androidSdkPath}");
            Assert.AreEqual(resolveSdks.AndroidNdkPath, androidNdkPath, $"AndroidNdkPath should be {androidNdkPath}");
            Assert.AreEqual(resolveSdks.JavaSdkPath, javaPath, $"JavaSdkPath should be {javaPath}");
            expected = Path.Combine(androidSdkPath, "build-tools", "26.0.3");
            Assert.AreEqual(androidTooling.AndroidSdkBuildToolsPath, expected, $"AndroidSdkBuildToolsPath should be {expected}");
            Assert.AreEqual(androidTooling.AndroidSdkBuildToolsBinPath, expected, "AndroidSdkBuildToolsBinPath should be {expected}");
            Assert.AreEqual(androidTooling.ZipAlignPath, expected, "ZipAlignPath should be {expected}");
            Assert.AreEqual(androidTooling.AndroidSequencePointsMode, "None", "AndroidSequencePointsMode should be None");
            expected = Path.Combine(androidSdkPath, "tools");
            Assert.AreEqual(androidTooling.LintToolPath, expected, $"LintToolPath should be {expected}");
            expected = Path.Combine(androidSdkPath, "build-tools", "26.0.3", "lib", "apksigner.jar");
            Assert.AreEqual(androidTooling.ApkSignerJar, expected, $"ApkSignerJar should be {expected}");
            Assert.AreEqual(androidTooling.AndroidUseApkSigner, false, "AndroidUseApkSigner should be false");
            Assert.AreEqual(validateJavaVersion.JdkVersion, "1.8.0", "JdkVersion should be 1.8.0");
            Assert.AreEqual(validateJavaVersion.MinimumRequiredJdkVersion, "1.8", "MinimumRequiredJdkVersion should be 1.8");
            Directory.Delete(Path.Combine(Root, path), recursive: true);
        }