Example #1
0
        private void ResolveVersionsUsingHierarchicalRules(RubyPlatformDetectorResult detectorResult)
        {
            var rubyVersion = resolveRubyVersion(detectorResult.PlatformVersion);

            rubyVersion = GetMaxSatisfyingRubyVersionAndVerify(rubyVersion);

            detectorResult.PlatformVersion = rubyVersion;

            string resolveRubyVersion(string detectedVersion)
            {
                // Explicitly specified version by user wins over detected version
                if (!string.IsNullOrEmpty(_rubyScriptGeneratorOptions.RubyVersion))
                {
                    return(_rubyScriptGeneratorOptions.RubyVersion);
                }

                // If a version was detected, then use it.
                if (detectedVersion != null)
                {
                    return(detectedVersion);
                }

                // Fallback to default version
                var versionInfo = _rubyVersionProvider.GetVersionInfo();

                return(versionInfo.DefaultVersion);
            }
        }
Example #2
0
        public void DoesNotHaveRubyInstallScript_IfDynamicInstallNotEnabled_AndRubyVersionIsNotAlreadyInstalled()
        {
            // Arrange
            var installationScript = "test-script";
            var commonOptions      = new BuildScriptGeneratorOptions();

            commonOptions.EnableDynamicInstall = false;
            var rubyPlatform = CreateRubyPlatform(
                commonOptions: commonOptions,
                isRubyVersionAlreadyInstalled: false,
                rubyInstallationScript: installationScript);
            var repo = new MemorySourceRepo();

            repo.AddFile("{}", RubyConstants.GemFileName);
            var context        = CreateContext(repo);
            var detectedResult = new RubyPlatformDetectorResult
            {
                Platform        = RubyConstants.PlatformName,
                PlatformVersion = "2.7.1",
            };

            // Act
            var actualScriptSnippet = rubyPlatform.GetInstallerScriptSnippet(context, detectedResult);

            // Assert
            Assert.Null(actualScriptSnippet);
        }
Example #3
0
        public void GeneratedBuildSnippet_DoesNotContainsJekyllCommand_WhenOnlyGemFileExists_ForStaticWebApp()
        {
            // Arrange
            var commonOptions = new BuildScriptGeneratorOptions();

            commonOptions.AppType = Constants.StaticSiteApplications;
            var rubyPlatform = CreateRubyPlatform(
                commonOptions: commonOptions,
                isRubyVersionAlreadyInstalled: false);
            var repo = new MemorySourceRepo();

            repo.AddFile(string.Empty, RubyConstants.GemFileName);
            var context        = CreateContext(repo);
            var detectorResult = new RubyPlatformDetectorResult
            {
                Platform        = RubyConstants.PlatformName,
                PlatformVersion = "2.6.6",
                GemfileExists   = true,
            };

            // Act
            var buildScriptSnippet = rubyPlatform.GenerateBashBuildScriptSnippet(context, detectorResult);

            // Assert
            Assert.NotNull(buildScriptSnippet);
            Assert.DoesNotContain("gem install jekyll", buildScriptSnippet.BashBuildScriptSnippet);
            Assert.DoesNotContain("jekyll build", buildScriptSnippet.BashBuildScriptSnippet);
            Assert.Contains("bundle install", buildScriptSnippet.BashBuildScriptSnippet);
        }
Example #4
0
        private static PlatformDetectorResult GetPlatformDetectorResult(string name, string version)
        {
            var result = new PlatformDetectorResult();

            switch (name)
            {
            case DotNetCoreConstants.PlatformName:
                result = new DotNetCorePlatformDetectorResult();
                break;

            case NodeConstants.PlatformName:
                result = new NodePlatformDetectorResult();
                break;

            case PythonConstants.PlatformName:
                result = new PythonPlatformDetectorResult();
                break;

            case HugoConstants.PlatformName:
                result = new PlatformDetectorResult();
                break;

            case PhpConstants.PlatformName:
                result = new PhpPlatformDetectorResult();
                break;

            case JavaConstants.PlatformName:
                result = new JavaPlatformDetectorResult();
                break;

            case RubyConstants.PlatformName:
                result = new RubyPlatformDetectorResult();
                break;
            }

            result.Platform        = name;
            result.PlatformVersion = version;

            return(result);
        }