Beispiel #1
0
        public override async ValueTask ScanAsync(ScanFileContext context)
        {
            try
            {
                using var sr = await StreamUtilities.CreateReaderAsync(context.Content, context.CancellationToken).ConfigureAwait(false);

                using var jsonReader = new JsonTextReader(sr);
                var doc = await JToken.ReadFromAsync(jsonReader, context.CancellationToken).ConfigureAwait(false);

                var token = doc.SelectToken("$.sdk.version");
                if (token?.Value <string>() is string version)
                {
                    await context.ReportDependency(new Dependency(".NET SDK", version, DependencyType.DotNetSdk, new JsonLocation(context.FullPath, LineInfo.FromJToken(token), token.Path))).ConfigureAwait(false);
                }

                var sdksToken = doc.SelectToken("$.msbuild-sdks");
                if (sdksToken is JObject sdks)
                {
                    foreach (var sdk in sdks.Properties())
                    {
                        version = sdk.Value.Value <string>();
                        if (version != null)
                        {
                            await context.ReportDependency(new Dependency(sdk.Name, version, DependencyType.NuGet, new JsonLocation(context.FullPath, LineInfo.FromJToken(sdk.Value), sdk.Value.Path))).ConfigureAwait(false);
                        }
                    }
                }
            }
            catch (JsonException)
            {
            }
        }
Beispiel #2
0
        private static async Task ExtractSdk(ScanFileContext context, JToken doc)
        {
            var token = doc.SelectToken("$.sdk.version");

            if (token?.Value <string>() is string version)
            {
                await context.ReportDependency(new Dependency(".NET SDK", version, DependencyType.DotNetSdk, new JsonLocation(context.FullPath, LineInfo.FromJToken(token), token.Path))).ConfigureAwait(false);
            }
        }
Beispiel #3
0
        private static async Task ExtractMsBuildSdks(ScanFileContext context, JToken doc)
        {
            var sdksToken = doc.SelectToken("$.msbuild-sdks");

            if (sdksToken is JObject sdks)
            {
                foreach (var sdk in sdks.Properties())
                {
                    var sdkVersion = sdk.Value.Value <string>();
                    if (sdkVersion != null)
                    {
                        await context.ReportDependency(new Dependency(sdk.Name, sdkVersion, DependencyType.NuGet, new JsonLocation(context.FullPath, LineInfo.FromJToken(sdk.Value), sdk.Value.Path))).ConfigureAwait(false);
                    }
                }
            }
        }
Beispiel #4
0
        public override async ValueTask ScanAsync(ScanFileContext context)
        {
            if (RegexPattern == null)
            {
                return;
            }

            using var sr = new StreamReader(context.Content);
            var text = await sr.ReadToEndAsync().ConfigureAwait(false);

            foreach (Match match in Regex.Matches(text, RegexPattern, RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(10)))
            {
                Debug.Assert(match.Success);

                var name         = match.Groups[NameGroupName].Value;
                var versionGroup = match.Groups[VersionGroupName];
                var version      = versionGroup.Value;
                if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(version))
                {
                    var location = TextLocation.FromIndex(context.FullPath, text, versionGroup.Index, versionGroup.Length);
                    await context.ReportDependency(new Dependency(name, version, DependencyType, location)).ConfigureAwait(false);
                }
            }
        }
Beispiel #5
0
 public override ValueTask ScanAsync(ScanFileContext context)
 {
     return(context.ReportDependency(new Dependency("", "", DependencyType.Unknown, new TextLocation(context.FullPath, 1, 1, 1))));
 }