Exemple #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);

                foreach (var deps in doc.SelectTokens("$..dependencies").Concat(doc.SelectTokens("$.tools")).OfType <JObject>())
                {
                    foreach (var dep in deps.Properties())
                    {
                        JToken valueElement = dep;
                        var    packageName  = dep.Name;
                        string version;
                        if (dep.Value.Type == JTokenType.String)
                        {
                            version = dep.Value.Value <string>();
                        }
                        else if (dep.Value.Type == JTokenType.Object)
                        {
                            var token = dep.Value.SelectToken("$.version");
                            if (token == null)
                            {
                                continue;
                            }

                            version      = token.Value <string>();
                            valueElement = token;
                        }
                        else
                        {
                            continue;
                        }


                        await context.ReportDependency(new Dependency(packageName, version, DependencyType.NuGet, new JsonLocation(context.FullPath, LineInfo.FromJToken(dep), valueElement.Path))).ConfigureAwait(false);
                    }
                }
            }
            catch (JsonException)
            {
            }
        }
Exemple #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);
            }
        }
        private static async ValueTask ScanDependenciesAsync(ScanFileContext context, JObject deps)
        {
            foreach (var dep in deps.Properties())
            {
                if (dep.Value is null)
                {
                    continue;
                }

                var    packageName = dep.Name;
                string?version     = null;
                if (dep.Value.Type == JTokenType.String)
                {
                    if (dep.Value != null)
                    {
                        version = dep.Value.Value <string>();
                    }
                }
                else if (dep.Value.Type == JTokenType.Object)
                {
                    if (dep.Value != null)
                    {
                        var token = dep.Value.SelectToken("$.version");
                        if (token != null)
                        {
                            version = token.Value <string>();
                        }
                    }
                }
                else
                {
                    continue;
                }

                if (version is null)
                {
                    continue;
                }

                if (dep.Value != null)
                {
                    var dependency = new Dependency(packageName, version, DependencyType.Npm, new JsonLocation(context.FullPath, LineInfo.FromJToken(dep), dep.Value.Path));
                    await context.ReportDependency(dependency).ConfigureAwait(false);
                }
            }
        }
Exemple #4
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);
                    }
                }
            }
        }
Exemple #5
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)
            {
            }
        }