private PackageInProject XmlToPackage(XElement el, PackagePath path)
        {
            var id      = el.Attribute("id")?.Value;
            var version = el.Attribute("version")?.Value;

            return(_packageInProjectReader.Read(id, version, path, null));
        }
Beispiel #2
0
        private PackageInProject XmlToPackage(XElement el, PackagePath path, XNamespace ns)
        {
            try
            {
                var id      = el.Attribute("Include")?.Value;
                var version = el.Attribute("Version")?.Value ?? el.Element(ns + "Version")?.Value;

                if (string.IsNullOrWhiteSpace(version))
                {
                    _logger.Normal($"Skipping package '{id}' with no version specified.");
                    return(null);
                }

                var versionParseSuccess = NuGetVersion.TryParse(version, out var nugetVersion);
                if (!versionParseSuccess)
                {
                    _logger.Normal($"Skipping package '{id}' with version '{version}' that could not be parsed.");
                    return(null);
                }

                return(new PackageInProject(new PackageIdentity(id, nugetVersion), path));
            }
            catch (Exception ex)
            {
                _logger.Error($"Could not read package from {el} in file {path.FullName}", ex);
                return(null);
            }
        }
Beispiel #3
0
 public PackageInProject(PackageVersionRange packageVersionRange,
                         PackagePath path,
                         IEnumerable <string> projectReferences = null)
 {
     PackageVersionRange = packageVersionRange;
     Path = path;
     ProjectReferences = projectReferences?.ToList() ?? new List <string>();
 }
Beispiel #4
0
 public PackageInProject(PackageIdentity identity,
                         PackagePath path,
                         IEnumerable <string> projectReferences)
 {
     Identity          = identity;
     Path              = path;
     ProjectReferences = projectReferences?.ToList() ?? new List <string>();
 }
        private PackageInProject XmlToPackage(XNamespace ns, XElement el,
                                              PackagePath path, IEnumerable <string> projectReferences)
        {
            var id      = el.Attribute("Include")?.Value;
            var version = el.Attribute("Version")?.Value ?? el.Element(ns + "Version")?.Value;

            return(_packageInProjectReader.Read(id, version, path, projectReferences));
        }
        public IEnumerable <PackageInProject> ReadFile(string baseDirectory, string relativePath)
        {
            var packagePath = new PackagePath(baseDirectory, relativePath, PackageReferenceType.PackagesConfig);

            using (var fileContents = File.OpenRead(packagePath.FullName))
            {
                return(Read(fileContents, packagePath));
            }
        }
Beispiel #7
0
        private PackageInProject XmlToPackage(XElement el, PackagePath path)
        {
            var id = el.Attribute("Include")?.Value;

            if (id == null)
            {
                id = el.Attribute("Update")?.Value;
            }
            var version = el.Attribute("Version")?.Value ?? el.Element("Version")?.Value;

            return(_packageInProjectReader.Read(id, version, path, null));
        }
Beispiel #8
0
        private PackageInProject XmlToPackage(XElement el, PackagePath path)
        {
            try
            {
                var id      = el.Attribute("id")?.Value;
                var version = el.Attribute("version")?.Value;

                return(new PackageInProject(id, version, path));
            }
            catch (Exception ex)
            {
                _logger.Error($"Could not read package from {el} in file {path.FullName}", ex);
                return(null);
            }
        }
 public IReadOnlyCollection<PackageInProject> ReadFile(string baseDirectory, string relativePath)
 {
     var packagePath = new PackagePath(baseDirectory, relativePath, PackageReferenceType.DirectoryBuildTargets);
     try
     {
         using (var fileContents = File.OpenRead(packagePath.FullName))
         {
             return Read(fileContents, packagePath);
         }
     }
     catch (Exception ex)
     {
         throw new NuKeeperException($"Unable to parse file {packagePath.FullName}", ex);
     }
 }
Beispiel #10
0
        public IEnumerable <PackageInProject> ReadFile(string baseDirectory, string relativePath)
        {
            var packagePath = new PackagePath(baseDirectory, relativePath, PackageReferenceType.Nuspec);

            try
            {
                using (var fileContents = File.OpenRead(packagePath.FullName))
                {
                    return(Read(fileContents, packagePath));
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException($"Unable to parse file {packagePath.FullName}", ex);
            }
        }
Beispiel #11
0
        private PackageInProject XmlToPackage(XNamespace ns, XElement el,
                                              PackagePath path, IEnumerable <string> projectReferences)
        {
            try
            {
                var id      = el.Attribute("Include")?.Value;
                var version = el.Attribute("Version")?.Value ?? el.Element(ns + "Version")?.Value;

                return(_packageInProjectReader.Read(id, version, path, projectReferences));
            }
            catch (Exception ex)
            {
                _logger.Error($"Could not read package from {el} in file {path.FullName}", ex);
                return(null);
            }
        }
Beispiel #12
0
        public IReadOnlyCollection <PackageInProject> Read(Stream fileContents, PackagePath path)
        {
            var xml = XDocument.Load(fileContents);

            var packagesNode = xml.Element("Project")?.Elements("ItemGroup");

            if (packagesNode == null)
            {
                return(Array.Empty <PackageInProject>());
            }

            var packageNodeList = packagesNode.Elements("PackageReference");

            return(packageNodeList
                   .Select(el => XmlToPackage(el, path))
                   .Where(el => el != null)
                   .ToList());
        }
Beispiel #13
0
        public IReadOnlyCollection <PackageInProject> Read(Stream fileContents, PackagePath path)
        {
            var xml = XDocument.Load(fileContents);

            var packagesNode = xml.Element("package")?.Element("metadata")?.Element("dependencies");

            if (packagesNode == null)
            {
                return(Array.Empty <PackageInProject>());
            }

            var packageNodeList = packagesNode.Elements()
                                  .Where(x => x.Name == "dependency");

            return(packageNodeList
                   .Select(el => XmlToPackage(el, path))
                   .Where(el => el != null)
                   .ToList());
        }
        private PackageInProject XmlToPackage(XElement el, PackagePath path)
        {
            try
            {
                var id = el.Attribute("Include")?.Value;
                if (id == null)
                {
                    id = el.Attribute("Update")?.Value;
                }
                var version = el.Attribute("Version")?.Value;

                return(_packageInProjectReader.Read(id, version, path, null));
            }
            catch (Exception ex)
            {
                _logger.Error($"Could not read package from {el} in file {path.FullName}", ex);
                return(null);
            }
        }
Beispiel #15
0
        public IEnumerable <PackageInProject> Read(Stream fileContents, PackagePath path)
        {
            var xml = XDocument.Load(fileContents);

            var packagesNode = xml.Element("packages");

            if (packagesNode == null)
            {
                return(Enumerable.Empty <PackageInProject>());
            }

            var packageNodeList = packagesNode.Elements()
                                  .Where(x => x.Name == "package");

            return(packageNodeList
                   .Select(el => XmlToPackage(el, path))
                   .Where(el => el != null)
                   .ToList());
        }
        public PackageInProject Read(
            string id, string version,
            PackagePath path,
            IEnumerable <string> projectReferences)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (string.IsNullOrWhiteSpace(id))
            {
                _logger.Normal($"Skipping package with no id specified in file '{path.FullName}'.");
                return(null);
            }

            if (string.IsNullOrWhiteSpace(version))
            {
                _logger.Normal($"Skipping package '{id}' with no version specified in file '{path.FullName}'.");
                return(null);
            }

            var packageVersionRange = PackageVersionRange.Parse(id, version);

            if (packageVersionRange == null)
            {
                _logger.Normal($"Skipping package '{id}' with version '{version}' that could not be parsed in file '{path.FullName}'.");
                return(null);
            }

            var pip = new PackageInProject(packageVersionRange, path, projectReferences);

            var singleVersion = pip.Identity;

            if (singleVersion == null)
            {
                _logger.Normal($"Skipping package '{id}' with version range '{version}' that is not a single version in file '{path.FullName}'.");
                return(null);
            }

            return(pip);
        }
        public PackageInProject Read(
            string id, string version,
            PackagePath path,
            IEnumerable <string> projectReferences)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                _logger.Normal($"Skipping package with no id specified in file '{path.FullName}'.");
                return(null);
            }

            if (string.IsNullOrWhiteSpace(version))
            {
                // TODO this is very spammy when using MSBuild Directory.build.props or .targets files for versioning NuGets. Should find a better way for this.
                _logger.Detailed($"Skipping package '{id}' with no version specified in file '{path.FullName}'.");
                return(null);
            }

            var packageVersionRange = PackageVersionRange.Parse(id, version);

            if (packageVersionRange == null)
            {
                _logger.Normal($"Skipping package '{id}' with version '{version}' that could not be parsed in file '{path.FullName}'.");
                return(null);
            }

            var pip = new PackageInProject(packageVersionRange, path, projectReferences);

            var singleVersion = pip.Identity;

            if (singleVersion == null)
            {
                _logger.Normal($"Skipping package '{id}' with version range '{version}' that is not a single version in file '{path.FullName}'.");
                return(null);
            }

            return(pip);
        }
Beispiel #18
0
 public PackageInProject(PackageIdentity identity, PackagePath path)
 {
     Identity = identity;
     Path     = path;
 }
Beispiel #19
0
 public PackageInProject(string id, string version, PackagePath path) :
     this(new PackageIdentity(id, new NuGetVersion(version)), path)
 {
 }
Beispiel #20
0
 public PackageInProject(string id, string versionRange, PackagePath path) :
     this(new PackageVersionRange(id, VersionRange.Parse(versionRange)), path, null)
 {
 }