示例#1
0
        private string DetectNodeVersion(dynamic packageJson)
        {
            var nodeVersionRange = packageJson?.engines?.node?.Value as string;

            if (nodeVersionRange == null)
            {
                nodeVersionRange = _nodeScriptGeneratorOptions.NodeJsDefaultVersion;
            }

            string nodeVersion = null;

            if (!string.IsNullOrWhiteSpace(nodeVersionRange))
            {
                nodeVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(
                    nodeVersionRange,
                    _versionProvider.SupportedNodeVersions);

                if (string.IsNullOrWhiteSpace(nodeVersion))
                {
                    var exc = new UnsupportedVersionException(
                        NodeConstants.NodeJsName,
                        nodeVersionRange,
                        _versionProvider.SupportedNodeVersions);
                    _logger.LogError(exc, $"Exception caught, the version '{nodeVersionRange}' is not supported for the node platform.");
                    throw exc;
                }
            }

            return(nodeVersion);
        }
        private string VerifyAndResolveVersion(string version)
        {
            if (string.IsNullOrEmpty(version))
            {
                return(_scriptGeneratorOptions.DefaultVersion);
            }
            else
            {
                var maxSatisfyingVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(
                    version,
                    _versionProvider.SupportedDotNetCoreVersions);

                if (string.IsNullOrEmpty(maxSatisfyingVersion))
                {
                    var exc = new UnsupportedVersionException(
                        DotNetCoreConstants.LanguageName,
                        version,
                        _versionProvider.SupportedDotNetCoreVersions);
                    _logger.LogError(exc, "Exception caught");
                    throw exc;
                }

                return(maxSatisfyingVersion);
            }
        }
示例#3
0
        private string VerifyAndResolveVersion(string version)
        {
            // Get the versions either from disk or on the web
            var versionInfo = _versionProvider.GetVersionInfo();

            // Get the default version. This could be having just the major or major.minor version.
            // So try getting the latest version of the default version.
            if (string.IsNullOrEmpty(version))
            {
                version = versionInfo.DefaultVersion;
            }

            var maxSatisfyingVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(
                version,
                versionInfo.SupportedVersions);

            if (string.IsNullOrEmpty(maxSatisfyingVersion))
            {
                var exc = new UnsupportedVersionException(
                    PythonConstants.PythonName,
                    version,
                    versionInfo.SupportedVersions);
                _logger.LogError(
                    exc,
                    $"Exception caught, the version '{version}' is not supported for the Python platform.");
                throw exc;
            }

            return(maxSatisfyingVersion);
        }
示例#4
0
        private string DetectNodeVersion(dynamic packageJson)
        {
            var nodeVersionRange = packageJson?.engines?.node?.Value as string;

            // Get the default version. This could be having just the major or major.minor version.
            // So try getting the maximum satisfying version of the default version.
            var versionInfo = _versionProvider.GetVersionInfo();

            if (string.IsNullOrEmpty(nodeVersionRange))
            {
                nodeVersionRange = versionInfo.DefaultVersion;
            }

            var maxSatisfyingVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(
                nodeVersionRange,
                versionInfo.SupportedVersions);

            if (string.IsNullOrEmpty(maxSatisfyingVersion))
            {
                var exception = new UnsupportedVersionException(
                    NodeConstants.NodeJsName,
                    nodeVersionRange,
                    versionInfo.SupportedVersions);
                _logger.LogError(
                    exception,
                    $"Exception caught, the version '{nodeVersionRange}' is not supported for the Node platform.");
                throw exception;
            }

            return(maxSatisfyingVersion);
        }
示例#5
0
        private string GetNpmVersion(dynamic packageJson)
        {
            string npmVersionRange = packageJson?.engines?.npm?.Value;

            if (npmVersionRange == null)
            {
                npmVersionRange = _nodeScriptGeneratorOptions.NpmDefaultVersion;
            }

            string npmVersion = null;

            if (!string.IsNullOrWhiteSpace(npmVersionRange))
            {
                var supportedNpmVersions = _nodeVersionProvider.SupportedNpmVersions;
                npmVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(
                    npmVersionRange,
                    supportedNpmVersions);
                if (string.IsNullOrWhiteSpace(npmVersion))
                {
                    _logger.LogWarning("User requested npm version {npmVersion} but it wasn't resolved", npmVersionRange);
                    return(null);
                }
            }

            return(npmVersion);
        }
示例#6
0
        private string DetectNodeVersion(dynamic packageJson)
        {
            var nodeVersionRange = packageJson?.engines?.node?.Value as string;

            if (nodeVersionRange == null)
            {
                nodeVersionRange = _nodeScriptGeneratorOptions.NodeJsDefaultVersion;
            }

            string nodeVersion = null;

            if (!string.IsNullOrWhiteSpace(nodeVersionRange))
            {
                nodeVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(
                    nodeVersionRange,
                    _nodeVersionProvider.SupportedNodeVersions);

                if (string.IsNullOrWhiteSpace(nodeVersion))
                {
                    var exc = new UnsupportedVersionException(
                        $"Target Node.js version '{nodeVersionRange}' is unsupported. " +
                        $"Supported versions are: {string.Join(", ", _nodeVersionProvider.SupportedNodeVersions)}");
                    _logger.LogError(exc, "Exception caught");
                    throw exc;
                }
            }

            return(nodeVersion);
        }
示例#7
0
        public void MinimumVersionSpecified()
        {
            // Arrange
            var supportedVersions = new[] { "1.2.3", "1.2.4" };

            // Act
            var returnedVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(">=1.2.3", supportedVersions);

            // Assert;
            Assert.Equal("1.2.4", returnedVersion);
        }
示例#8
0
        public void MajorVersionProvided_MatchesMajorAndLatestMinorAndPatchVersion(string providedVersion)
        {
            // Arrange
            var expectedVersion   = "1.3.4";
            var supportedVersions = new[] { "1.2.2", "1.2.4", "1.3.0", "1.3.4", "2.0.0", "2.3.0" };

            // Act
            var returnedVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(providedVersion, supportedVersions);

            // Assert;
            Assert.Equal(expectedVersion, returnedVersion);
        }
示例#9
0
        public void MajorMinorAndPatchVersionsProvided_DoesNotMatch_IfExactVersionNotAvailable()
        {
            // Arrange
            var providedVersion   = "1.2.3";
            var supportedVersions = new[] { "1.2.2", "1.2.4", "1.3.0", "2.0.0", "2.3.0" };

            // Act
            var returnedVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(providedVersion, supportedVersions);

            // Assert;
            Assert.Null(returnedVersion);
        }
示例#10
0
        public void MajorMinorAndPatchVersionsProvided_MatchesExactVersionIfAvailable()
        {
            // Arrange
            var expectedVersion   = "1.2.3";
            var supportedVersions = new[] { "1.2.3", "1.2.4", "1.3.0", "2.0.0", "2.3.0" };

            // Act
            var returnedVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(expectedVersion, supportedVersions);

            // Assert;
            Assert.Equal(expectedVersion, returnedVersion);
        }
示例#11
0
        [InlineData("~1.2.3", "1.2.5")] // get latest patch
        public void GetMaxSatisfyingVersion_UnderstandComplexRangeSyntaxes(string providedRange, string expectedVersion)
        {
            // Arrange
            var supportedVersions = new[] { "1.2.3", "1.2.4", "1.2.5", "1.3.0", "1.3.5", "2.0.0", "2.3.0" };

            // Act
            var returnedVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(
                providedRange,
                supportedVersions);

            // Assert;
            Assert.Equal(expectedVersion, returnedVersion);
        }
示例#12
0
        private string GetMaxSatisfyingVersionAndVerify(string runtimeVersion)
        {
            var versionMap = _versionProvider.GetSupportedVersions();

            // Since our semantic versioning library does not work with .NET Core preview version format, here
            // we do some trivial way of finding the latest version which matches a given runtime version
            // Runtime versions are usually like: 1.0, 2.1, 3.1, 5.0 etc.
            // (these are constructed from netcoreapp21, netcoreapp31 etc.)
            // Preview version of sdks also have preview versions of runtime versions and hence they
            // have '-' in their names.
            var nonPreviewRuntimeVersions = versionMap.Keys.Where(version => version.IndexOf("-") < 0);
            var maxSatisfyingVersion      = SemanticVersionResolver.GetMaxSatisfyingVersion(
                runtimeVersion,
                nonPreviewRuntimeVersions);

            // Check if a preview version is available
            if (string.IsNullOrEmpty(maxSatisfyingVersion))
            {
                // NOTE:
                // Preview versions: 5.0.0-preview.3.20214.6, 5.0.0-preview.2.20160.6, 5.0.0-preview.1.20120.5
                var previewRuntimeVersions = versionMap.Keys
                                             .Where(version => version.IndexOf("-") >= 0)
                                             .Where(version => version.StartsWith(runtimeVersion))
                                             .OrderByDescending(version => version);
                if (previewRuntimeVersions.Any())
                {
                    maxSatisfyingVersion = previewRuntimeVersions.First();
                }
            }

            if (string.IsNullOrEmpty(maxSatisfyingVersion))
            {
                var exception = new UnsupportedVersionException(
                    DotNetCoreConstants.PlatformName,
                    runtimeVersion,
                    versionMap.Keys);
                _logger.LogError(
                    exception,
                    $"Exception caught, the version '{runtimeVersion}' is not supported for the .NET Core platform.");
                throw exception;
            }

            return(maxSatisfyingVersion);
        }
示例#13
0
        private string VerifyAndResolveVersion(string version)
        {
            if (string.IsNullOrEmpty(version))
            {
                return(_opts.PhpDefaultVersion);
            }

            var maxSatisfyingVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(version, _versionProvider.SupportedPhpVersions);

            if (string.IsNullOrEmpty(maxSatisfyingVersion))
            {
                var exc = new UnsupportedVersionException($"Target PHP version '{version}' is unsupported. " +
                                                          $"Supported versions are: {string.Join(", ", _versionProvider.SupportedPhpVersions)}");
                _logger.LogError(exc, "Exception caught");
                throw exc;
            }

            return(maxSatisfyingVersion);
        }
        private string GetMaxSatisfyingVersionAndVerify(string runtimeVersion)
        {
            var versionMap           = _versionProvider.GetSupportedVersions();
            var maxSatisfyingVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(
                runtimeVersion,
                versionMap.Keys);

            if (string.IsNullOrEmpty(maxSatisfyingVersion))
            {
                var exception = new UnsupportedVersionException(
                    DotNetCoreConstants.LanguageName,
                    runtimeVersion,
                    versionMap.Keys);
                _logger.LogError(
                    exception,
                    $"Exception caught, the version '{runtimeVersion}' is not supported for the .NET Core platform.");
                throw exception;
            }

            return(maxSatisfyingVersion);
        }
示例#15
0
        public string GetMaxSatisfyingPhpComposerVersionAndVerify(string version)
        {
            var versionInfo          = this.phpComposerVersionProvider.GetVersionInfo();
            var maxSatisfyingVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(
                version,
                versionInfo.SupportedVersions);

            if (string.IsNullOrEmpty(maxSatisfyingVersion))
            {
                var exception = new UnsupportedVersionException(
                    PhpConstants.PhpComposerName,
                    version,
                    versionInfo.SupportedVersions);
                this.logger.LogError(
                    exception,
                    $"Exception caught, the version '{version}' is not supported for the Node platform.");
                throw exception;
            }

            return(maxSatisfyingVersion);
        }
示例#16
0
        private string GetMaxSatisfyingVersionAndVerify(string version)
        {
            var versionInfo          = _versionProvider.GetVersionInfo();
            var maxSatisfyingVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(
                version,
                versionInfo.SupportedVersions);

            if (string.IsNullOrEmpty(maxSatisfyingVersion))
            {
                var exc = new UnsupportedVersionException(
                    PhpConstants.PlatformName,
                    version,
                    versionInfo.SupportedVersions);
                _logger.LogError(
                    exc,
                    $"Exception caught, the version '{version}' is not supported for the PHP platform.");
                throw exc;
            }

            return(maxSatisfyingVersion);
        }
示例#17
0
        private string GetMaxSatisfyingMavenVersionAndVerify(string version)
        {
            var versionInfo          = _mavenVersionProvider.GetVersionInfo();
            var maxSatisfyingVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(
                version,
                versionInfo.SupportedVersions);

            if (string.IsNullOrEmpty(maxSatisfyingVersion))
            {
                var exception = new UnsupportedVersionException(
                    "maven",
                    version,
                    versionInfo.SupportedVersions);
                _logger.LogError(
                    exception,
                    $"Exception caught, the version '{version}' is not supported for Maven.");
                throw exception;
            }

            return(maxSatisfyingVersion);
        }
示例#18
0
        private string GetMaxSatisfyingVersionAndVerify(string version)
        {
            var supportedVersions = SupportedVersions;

            // Since our semantic versioning library does not work with Python preview version format, here
            // we do some trivial way of finding the latest version which matches a given runtime version.
            // Preview version of sdks have alphabet letter in the version name. Such as '3.8.0b3', '3.9.0b1',etc.
            var nonPreviewRuntimeVersions = supportedVersions.Where(v => !v.Any(c => char.IsLetter(c)));
            var maxSatisfyingVersion      = SemanticVersionResolver.GetMaxSatisfyingVersion(
                version,
                nonPreviewRuntimeVersions);

            // Check if a preview version is available
            if (string.IsNullOrEmpty(maxSatisfyingVersion))
            {
                // Preview versions: '3.8.0b3', '3.9.0b1', etc
                var previewRuntimeVersions = supportedVersions
                                             .Where(v => v.Any(c => char.IsLetter(c)))
                                             .Where(v => v.StartsWith(version))
                                             .OrderByDescending(v => v);
                if (previewRuntimeVersions.Any())
                {
                    maxSatisfyingVersion = previewRuntimeVersions.First();
                }
            }

            if (string.IsNullOrEmpty(maxSatisfyingVersion))
            {
                var exc = new UnsupportedVersionException(
                    PythonConstants.PlatformName,
                    version,
                    supportedVersions);
                _logger.LogError(
                    exc,
                    $"Exception caught, the version '{version}' is not supported for the Python platform.");
                throw exc;
            }

            return(maxSatisfyingVersion);
        }
示例#19
0
        private string VerifyAndResolveVersion(string version)
        {
            if (string.IsNullOrEmpty(version))
            {
                return(_pythonScriptGeneratorOptions.PythonDefaultVersion);
            }

            var maxSatisfyingVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(
                version,
                _versionProvider.SupportedPythonVersions);

            if (string.IsNullOrEmpty(maxSatisfyingVersion))
            {
                var exc = new UnsupportedVersionException(
                    PythonConstants.PythonName,
                    version,
                    _versionProvider.SupportedPythonVersions);
                _logger.LogError(exc, $"Exception caught, the version '{version}' is not supported for the Python platform.");
                throw exc;
            }

            return(maxSatisfyingVersion);
        }
示例#20
0
        private string VerifyAndResolveVersion(string version)
        {
            if (string.IsNullOrEmpty(version))
            {
                return(_opts.PhpDefaultVersion);
            }

            var maxSatisfyingVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(
                version,
                _versionProvider.SupportedPhpVersions);

            if (string.IsNullOrEmpty(maxSatisfyingVersion))
            {
                var exc = new UnsupportedVersionException(
                    PhpConstants.PhpName,
                    version,
                    _versionProvider.SupportedPhpVersions);
                _logger.LogError(exc, "Exception caught");
                throw exc;
            }

            return(maxSatisfyingVersion);
        }
示例#21
0
        private string GetMaxSatisfyingVersionAndVerify(string version)
        {
            var supportedVersions         = SupportedVersions;
            var nonPreviewRuntimeVersions = supportedVersions.Where(v => !v.Any(c => char.IsLetter(c)));
            var maxSatisfyingVersion      = SemanticVersionResolver.GetMaxSatisfyingVersion(
                version,
                nonPreviewRuntimeVersions);

            // Check if a preview version is available
            if (string.IsNullOrEmpty(maxSatisfyingVersion))
            {
                // Preview versions: '7.4.0RC4', '7.4.0beta2', etc
                var previewRuntimeVersions = supportedVersions
                                             .Where(v => v.Any(c => char.IsLetter(c)))
                                             .Where(v => v.StartsWith(version))
                                             .OrderByDescending(v => v);
                if (previewRuntimeVersions.Any())
                {
                    maxSatisfyingVersion = previewRuntimeVersions.First();
                }
            }

            if (string.IsNullOrEmpty(maxSatisfyingVersion))
            {
                var exc = new UnsupportedVersionException(
                    PhpConstants.PlatformName,
                    version,
                    supportedVersions);
                _logger.LogError(
                    exc,
                    $"Exception caught, the version '{version}' is not supported for the PHP platform.");
                throw exc;
            }

            return(maxSatisfyingVersion);
        }
        private string VerifyAndResolveVersion(string version)
        {
            if (string.IsNullOrEmpty(version))
            {
                return(_scriptGeneratorOptions.DefaultVersion);
            }
            else
            {
                var maxSatisfyingVersion = SemanticVersionResolver.GetMaxSatisfyingVersion(
                    version,
                    _versionProvider.SupportedDotNetCoreVersions);

                if (string.IsNullOrEmpty(maxSatisfyingVersion))
                {
                    var exc = new UnsupportedVersionException(
                        $"Target .NET Core version '{version}' is unsupported. Supported versions are:" +
                        $" {string.Join(", ", _versionProvider.SupportedDotNetCoreVersions)}");
                    _logger.LogError(exc, "Exception caught");
                    throw exc;
                }

                return(maxSatisfyingVersion);
            }
        }