/// <inheritdoc/>
        public override bool UpgradeAfterAssetsLoaded(PackageSession session, ILogger log, Package dependentPackage, PackageDependency dependency, Package dependencyPackage, PackageVersionRange dependencyVersionBeforeUpdate)
        {
            if (dependencyVersionBeforeUpdate.MinVersion < new PackageVersion("1.3.0-alpha02"))
            {
                // Add everything as root assets (since we don't know what the project was doing in the code before)
                foreach (var assetItem in dependentPackage.Assets)
                {
                    if (!AssetRegistry.IsAssetTypeAlwaysMarkAsRoot(assetItem.Asset.GetType()))
                        dependentPackage.RootAssets.Add(new AssetReference<Asset>(assetItem.Id, assetItem.Location));
                }
            }

            return true;
        }
示例#2
0
        public static Func <T, bool> ToFilter <T>(this PackageVersionRange versionInfo, Func <T, PackageVersion> extractor)
        {
            if (versionInfo == null)
            {
                throw new ArgumentNullException("versionInfo");
            }
            if (extractor == null)
            {
                throw new ArgumentNullException("extractor");
            }

            return(p =>
            {
                PackageVersion version = extractor(p);
                bool condition = true;
                if (versionInfo.MinVersion != null)
                {
                    if (versionInfo.IsMinInclusive)
                    {
                        condition = version >= versionInfo.MinVersion;
                    }
                    else
                    {
                        condition = version > versionInfo.MinVersion;
                    }
                }

                if (versionInfo.MaxVersion != null)
                {
                    if (versionInfo.IsMaxInclusive)
                    {
                        condition = condition && version <= versionInfo.MaxVersion;
                    }
                    else
                    {
                        condition = condition && version < versionInfo.MaxVersion;
                    }
                }

                return condition;
            });
        }
示例#3
0
 /// <summary>
 /// Performs the second step of package migration, after assets have been loaded.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <param name="log">The log.</param>
 /// <param name="dependentPackage">The source package.</param>
 /// <param name="dependency">The dependency.</param>
 /// <param name="dependencyPackage">The dependency package.</param>
 /// <param name="dependencyVersionBeforeUpdate">The version before the update.</param>
 /// <returns></returns>
 public virtual bool UpgradeAfterAssetsLoaded(PackageSession session, ILogger log, Package dependentPackage, PackageDependency dependency, Package dependencyPackage, PackageVersionRange dependencyVersionBeforeUpdate)
 {
     return true;
 }
 public PackageUpgraderAttribute(string packageName, string packageMinimumVersion, string packageUpdatedVersionRange)
 {
     PackageName = packageName;
     PackageMinimumVersion = new PackageVersion(packageMinimumVersion);
     PackageVersionRange.TryParse(packageUpdatedVersionRange, out this.updatedVersionRange);
 }
示例#5
0
        private UDirectory GetPackageDirectory(string packageName, PackageVersionRange versionRange, IPackageConstraintProvider constraintProvider = null, bool allowPreleaseVersion = false, bool allowUnlisted = false)
        {
            if (packageName == null) throw new ArgumentNullException("packageName");

            if (store != null)
            {
                var versionSpec = versionRange.ToVersionSpec();
                var package = store.Manager.LocalRepository.FindPackage(packageName, versionSpec, constraintProvider ?? NullConstraintProvider.Instance, allowPreleaseVersion, allowUnlisted);

                // If package was not found, 
                if (package != null)
                {
                    var directory = store.PathResolver.GetPackageDirectory(package);
                    if (directory != null)
                    {
                        return directory;
                    }
                }
            }

            // TODO: Check version for default package
            if (packageName == DefaultPackageName)
            {
                if (versionRange == null || versionRange.Contains(DefaultPackageVersion))
                {
                    return defaultPackageDirectory;
                }
            }

            return null;
        }
示例#6
0
 /// <summary>
 /// Gets the filename to the specific package.
 /// </summary>
 /// <param name="packageName">Name of the package.</param>
 /// <param name="versionRange">The version range.</param>
 /// <param name="constraintProvider">The package constraint provider.</param>
 /// <param name="allowPreleaseVersion">if set to <c>true</c> [allow prelease version].</param>
 /// <param name="allowUnlisted">if set to <c>true</c> [allow unlisted].</param>
 /// <returns>A location on the disk to the specified package or null if not found.</returns>
 /// <exception cref="System.ArgumentNullException">packageName</exception>
 public UFile GetPackageFileName(string packageName, PackageVersionRange versionRange = null, IPackageConstraintProvider constraintProvider = null, bool allowPreleaseVersion = true, bool allowUnlisted = false)
 {
     if (packageName == null) throw new ArgumentNullException("packageName");
     var directory = GetPackageDirectory(packageName, versionRange, constraintProvider, allowPreleaseVersion, allowUnlisted);
     return directory != null ? UPath.Combine(UPath.Combine(UPath.Combine(InstallationPath, (UDirectory)store.RepositoryPath), directory), new UFile(packageName + Package.PackageFileExtension)) : null;
 }
示例#7
0
 public PendingPackageUpgrade(PackageUpgrader packageUpgrader, PackageDependency dependency, Package dependencyPackage)
 {
     PackageUpgrader = packageUpgrader;
     Dependency = dependency;
     DependencyPackage = dependencyPackage;
     DependencyVersionBeforeUpgrade = Dependency.Version;
 }
示例#8
0
        private UDirectory GetPackageDirectory(string packageName, PackageVersionRange versionRange, bool allowPreleaseVersion = false, bool allowUnlisted = false)
        {
            if (packageName == null) throw new ArgumentNullException("packageName");

            if (store != null)
            {
                var versionSpec = versionRange.ToVersionSpec();
                var package = store.Manager.LocalRepository.FindPackage(packageName, versionSpec, allowPreleaseVersion, allowUnlisted);

                // If package was not found, 
                if (package != null)
                {
                    var directory = store.PathResolver.GetPackageDirectory(package);
                    if (directory != null)
                    {
                        return directory;
                    }
                }
            }

            // TODO: Check version for default package
            return DefaultPackageName == packageName ? defaultPackageDirectory : null;
        }
示例#9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PackageDependency"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="version">The version.</param>
 public PackageDependency(string name, PackageVersionRange version)
 {
     Name    = name;
     Version = version;
 }
示例#10
0
        /// <summary>
        /// Tries to parse a version dependency.
        /// </summary>
        /// <param name="value">The version dependency as a string.</param>
        /// <param name="result">The parsed result.</param>
        /// <returns><c>true</c> if successfuly parsed, <c>false</c> otherwise.</returns>
        /// <exception cref="System.ArgumentNullException">value</exception>
        public static bool TryParse(string value, out PackageVersionRange result)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var versionSpec = new PackageVersionRange();
            value = value.Trim();

            // First, try to parse it as a plain version string
            PackageVersion version;
            if (PackageVersion.TryParse(value, out version))
            {
                // A plain version is treated as an inclusive minimum range
                result = new PackageVersionRange
                    {
                        MinVersion = version,
                        IsMinInclusive = true
                    };

                return true;
            }

            // It's not a plain version, so it must be using the bracket arithmetic range syntax

            result = null;

            // Fail early if the string is too short to be valid
            if (value.Length < 3)
            {
                return false;
            }

            // The first character must be [ ot (
            switch (value.First())
            {
                case '[':
                    versionSpec.IsMinInclusive = true;
                    break;
                case '(':
                    versionSpec.IsMinInclusive = false;
                    break;
                default:
                    return false;
            }

            // The last character must be ] ot )
            switch (value.Last())
            {
                case ']':
                    versionSpec.IsMaxInclusive = true;
                    break;
                case ')':
                    versionSpec.IsMaxInclusive = false;
                    break;
                default:
                    return false;
            }

            // Get rid of the two brackets
            value = value.Substring(1, value.Length - 2);

            // Split by comma, and make sure we don't get more than two pieces
            string[] parts = value.Split(',');
            if (parts.Length > 2)
            {
                return false;
            }
            if (parts.All(string.IsNullOrEmpty))
            {
                // If all parts are empty, then neither of upper or lower bounds were specified. Version spec is of the format (,]
                return false;
            }

            // If there is only one piece, we use it for both min and max
            string minVersionString = parts[0];
            string maxVersionString = (parts.Length == 2) ? parts[1] : parts[0];

            // Only parse the min version if it's non-empty
            if (!string.IsNullOrWhiteSpace(minVersionString))
            {
                if (!PackageVersion.TryParse(minVersionString, out version))
                {
                    return false;
                }
                versionSpec.MinVersion = version;
            }

            // Same deal for max
            if (!string.IsNullOrWhiteSpace(maxVersionString))
            {
                if (!PackageVersion.TryParse(maxVersionString, out version))
                {
                    return false;
                }
                versionSpec.MaxVersion = version;
            }

            // Successful parse!
            result = versionSpec;
            return true;
        }
示例#11
0
 /// <summary>
 /// Performs the second step of package migration, after assets have been loaded.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <param name="log">The log.</param>
 /// <param name="dependentPackage">The source package.</param>
 /// <param name="dependency">The dependency.</param>
 /// <param name="dependencyPackage">The dependency package.</param>
 /// <param name="dependencyVersionBeforeUpdate">The version before the update.</param>
 /// <returns></returns>
 public virtual bool UpgradeAfterAssetsLoaded(PackageSession session, ILogger log, Package dependentPackage, PackageDependency dependency, Package dependencyPackage, PackageVersionRange dependencyVersionBeforeUpdate)
 {
     return(true);
 }
示例#12
0
        /// <summary>
        /// Tries to parse a version dependency.
        /// </summary>
        /// <param name="value">The version dependency as a string.</param>
        /// <param name="result">The parsed result.</param>
        /// <returns><c>true</c> if successfuly parsed, <c>false</c> otherwise.</returns>
        /// <exception cref="System.ArgumentNullException">value</exception>
        public static bool TryParse(string value, out PackageVersionRange result)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var versionSpec = new PackageVersionRange();

            value = value.Trim();

            // First, try to parse it as a plain version string
            PackageVersion version;

            if (PackageVersion.TryParse(value, out version))
            {
                // A plain version is treated as an inclusive minimum range
                result = new PackageVersionRange
                {
                    MinVersion     = version,
                    IsMinInclusive = true
                };

                return(true);
            }

            // It's not a plain version, so it must be using the bracket arithmetic range syntax

            result = null;

            // Fail early if the string is too short to be valid
            if (value.Length < 3)
            {
                return(false);
            }

            // The first character must be [ ot (
            switch (value.First())
            {
            case '[':
                versionSpec.IsMinInclusive = true;
                break;

            case '(':
                versionSpec.IsMinInclusive = false;
                break;

            default:
                return(false);
            }

            // The last character must be ] ot )
            switch (value.Last())
            {
            case ']':
                versionSpec.IsMaxInclusive = true;
                break;

            case ')':
                versionSpec.IsMaxInclusive = false;
                break;

            default:
                return(false);
            }

            // Get rid of the two brackets
            value = value.Substring(1, value.Length - 2);

            // Split by comma, and make sure we don't get more than two pieces
            string[] parts = value.Split(',');
            if (parts.Length > 2)
            {
                return(false);
            }
            if (parts.All(string.IsNullOrEmpty))
            {
                // If all parts are empty, then neither of upper or lower bounds were specified. Version spec is of the format (,]
                return(false);
            }

            // If there is only one piece, we use it for both min and max
            string minVersionString = parts[0];
            string maxVersionString = (parts.Length == 2) ? parts[1] : parts[0];

            // Only parse the min version if it's non-empty
            if (!string.IsNullOrWhiteSpace(minVersionString))
            {
                if (!PackageVersion.TryParse(minVersionString, out version))
                {
                    return(false);
                }
                versionSpec.MinVersion = version;
            }

            // Same deal for max
            if (!string.IsNullOrWhiteSpace(maxVersionString))
            {
                if (!PackageVersion.TryParse(maxVersionString, out version))
                {
                    return(false);
                }
                versionSpec.MaxVersion = version;
            }

            // Successful parse!
            result = versionSpec;
            return(true);
        }