Exemple #1
0
        /// <summary>
        ///     Analyze a package by downloading it first.
        /// </summary>
        /// <param name="purl"> The package-url of the package to analyze. </param>
        /// <returns> List of tags identified </returns>
        public async Task <Dictionary <string, AnalyzeResult?> > AnalyzePackage(Options options, PackageURL purl,
                                                                                string?targetDirectoryName,
                                                                                bool doCaching = false)
        {
            Logger.Trace("AnalyzePackage({0})", purl.ToString());

            Dictionary <string, AnalyzeResult?>?analysisResults = new Dictionary <string, AnalyzeResult?>();

            PackageDownloader?packageDownloader = new PackageDownloader(purl, ProjectManagerFactory, targetDirectoryName, doCaching);
            // ensure that the cache directory has the required package, download it otherwise
            List <string>?directoryNames = await packageDownloader.DownloadPackageLocalCopy(purl,
                                                                                            false,
                                                                                            true);

            if (directoryNames.Count > 0)
            {
                foreach (string?directoryName in directoryNames)
                {
                    AnalyzeResult?singleResult = await AnalyzeDirectory(options, directoryName);

                    analysisResults[directoryName] = singleResult;
                }
            }
            else
            {
                Logger.Warn("Error downloading {0}.", purl.ToString());
            }
            packageDownloader.ClearPackageLocalCopyIfNoCaching();
            return(analysisResults);
        }
Exemple #2
0
        /// <summary>
        ///     Analyze a package by downloading it first.
        /// </summary>
        /// <param name="purl"> The package-url of the package to analyze. </param>
        /// <returns> List of tags identified </returns>
        public async Task <List <IssueRecord> > AnalyzePackage(PackageURL purl, string?targetDirectoryName, bool doCaching)
        {
            Logger.Trace("AnalyzePackage({0})", purl.ToString());

            var packageDownloader = new PackageDownloader(purl, targetDirectoryName, doCaching);
            var directoryNames    = await packageDownloader.DownloadPackageLocalCopy(purl, false, true);

            directoryNames = directoryNames.Distinct().ToList <string>();

            var analysisResults = new List <IssueRecord>();

            if (directoryNames.Count > 0)
            {
                foreach (var directoryName in directoryNames)
                {
                    Logger.Trace("Analyzing directory {0}", directoryName);
                    var singleResult = await AnalyzeDirectory(directoryName);

                    if (singleResult != null)
                    {
                        analysisResults.AddRange(singleResult);
                    }

                    Logger.Trace("Removing {0}", directoryName);
                    try
                    {
                        if (Directory.Exists(directoryName))
                        {
                            Directory.Delete(directoryName, true);
                        }
                        else if (File.Exists(directoryName))
                        {
                            File.Delete(directoryName);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Warn("Error removing {0}: {1}", directoryName, ex.Message);
                    }
                }
            }
            else
            {
                Logger.Warn("Error downloading {0}.", purl.ToString());
            }
            packageDownloader.ClearPackageLocalCopyIfNoCaching();

            return(analysisResults.ToList());
        }