Inheritance: IVersionSpec
コード例 #1
0
        public static IVersionSpec GetUpgradeVersionSpec(SemanticVersion version, PackageUpdateMode updateMode)
        {
            var spec = new VersionSpec
            {
                IsMinInclusive = false,
                IsMaxInclusive = false,
                MinVersion     = version,
            };

            switch (updateMode)
            {
            case PackageUpdateMode.Minor:
                spec.MaxVersion = new SemanticVersion(new Version(version.Version.Major + 1, 0));
                break;

            case PackageUpdateMode.Safe:
                spec.MaxVersion = new SemanticVersion(new Version(version.Version.Major, version.Version.Minor + 1));
                break;

            case PackageUpdateMode.Newest:
                spec.IsMaxInclusive = true;
                break;

            default:
                // TODO: resx
                throw new ArgumentException("Unsupported PackageUpdateMode " + updateMode, "updateMode");
            }

            return(spec);
        }
コード例 #2
0
        public static IVersionSpec GetSafeRange(SemanticVersion version)
        {
            VersionSpec spec1 = new VersionSpec();

            spec1.IsMinInclusive = true;
            spec1.MinVersion     = version;
            spec1.MaxVersion     = new SemanticVersion(new Version(version.Version.Major, version.Version.Minor + 1));
            return(spec1);
        }
コード例 #3
0
 public bool Equals(VersionSpec other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.MinVersion, MinVersion) && other.IsMinInclusive.Equals(IsMinInclusive) && Equals(other.MaxVersion, MaxVersion) && other.IsMaxInclusive.Equals(IsMaxInclusive));
 }
コード例 #4
0
ファイル: NugetFeed.cs プロジェクト: ventaur/ripple
        protected override IRemoteNuget find(Dependency query)
        {
            SemanticVersion version;
            if (!SemanticVersion.TryParse(query.Version, out version))
            {
                RippleLog.Debug("Could not find exact for " + query);
                return null;
            }

            var versionSpec = new VersionSpec(version);
            var package = _repository.FindPackages(query.Name, versionSpec, query.DetermineStability(_stability) == NugetStability.Anything, true).SingleOrDefault();

            if (package == null)
            {
                return null;
            }

            return new RemoteNuget(package);
        }
        public override void Context()
        {
            var minVersionSpec = new VersionSpec
            {
                MinVersion = new SemanticVersion("1.0.0"),
                IsMinInclusive = true
            };
            packageDependencyWithMinVersion = new PackageDependency("fiddler", minVersionSpec);

            var minAndMaxVersionSpec = new VersionSpec
            {
                MinVersion = new SemanticVersion("1.0.0"),
                MaxVersion = new SemanticVersion("2.0.0"),
                IsMinInclusive = true
            };
            packageDependencyWithMaxVersion = new PackageDependency("dude", minAndMaxVersionSpec);

            guideline = new DependencyWithNoVersionGuideline();
        }
コード例 #6
0
        public IVersionSpec ToVersionSpec()
        {
            var version = new VersionSpec
            {
                IsMaxInclusive = this.IsMaxInclusive,
                IsMinInclusive = this.IsMinInclusive,

            };

            if (this.IsMaxInclusive)
            {
                version.MaxVersion = new SemanticVersion(new Version(this.MaxVersionVersion), this.MaxVersionSpecial);
            }

            if (this.IsMinInclusive)
            {
                version.MinVersion = new SemanticVersion(new Version(this.MinVersionVersion), this.MinVersionSpecial);
            }

            return version;
        }
コード例 #7
0
ファイル: BuildContext.cs プロジェクト: adwardliu/dnx
        public void PopulateDependencies(PackageBuilder packageBuilder)
        {
            var dependencies = new List<PackageDependency>();
            var project = _libraryManager.GetLibraryDescription(_project.Name);

            foreach (var dependency in project.Dependencies)
            {
                if (!dependency.HasFlag(LibraryDependencyTypeFlag.BecomesNupkgDependency))
                {
                    continue;
                }

                var dependencyDescription = _libraryManager.GetLibraryDescription(dependency.Name);

                // REVIEW: Can we get this far with unresolved dependencies
                if (dependencyDescription == null || !dependencyDescription.Resolved)
                {
                    continue;
                }

                if (dependencyDescription.Type == LibraryTypes.Project &&
                    ((ProjectDescription)dependencyDescription).Project.EmbedInteropTypes)
                {
                    continue;
                }

                if (dependency.LibraryRange.IsGacOrFrameworkReference)
                {
                    packageBuilder.FrameworkReferences.Add(new FrameworkAssemblyReference(dependency.LibraryRange.GetReferenceAssemblyName(), new[] { _targetFramework }));
                }
                else
                {
                    IVersionSpec dependencyVersion = null;

                    if (dependency.LibraryRange.VersionRange == null ||
                        dependency.LibraryRange.VersionRange.VersionFloatBehavior != SemanticVersionFloatBehavior.None)
                    {
                        dependencyVersion = new VersionSpec
                        {
                            IsMinInclusive = true,
                            MinVersion = dependencyDescription.Identity.Version
                        };
                    }
                    else
                    {
                        var versionRange = dependency.LibraryRange.VersionRange;

                        dependencyVersion = new VersionSpec
                        {
                            IsMinInclusive = true,
                            MinVersion = versionRange.MinVersion,
                            MaxVersion = versionRange.MaxVersion,
                            IsMaxInclusive = versionRange.IsMaxInclusive
                        };
                    }

                    dependencies.Add(new PackageDependency(dependency.Name, dependencyVersion));
                }
            }

            packageBuilder.DependencySets.Add(new PackageDependencySet(_targetFramework, dependencies));
        }
コード例 #8
0
        private void InnerCreatePackage(KeyValuePair<Tuple<SemanticVersion, string>, DllReference> mainAssembly, bool logToSlack)
        {
            try
            {
                var metadata = new ManifestMetadata()
                {
                    Authors = _author,
                    Version = mainAssembly.Key.Item1.ToString(),
                    Id = mainAssembly.Key.Item2,
                    Description = "automatically created package using nuget-converter for " + mainAssembly.Key.Item2,
                    Owners = _owner,
                    RequireLicenseAcceptance = false
                };

                var builder = new PackageBuilder();
                var dependencies = new List<PackageDependency>();

                //Common Dependancies
                var asmReferencies = mainAssembly.Value;
                Trace.TraceInformation($"Resolving Cached Dependencies for {asmReferencies.Id.Item2}-{asmReferencies.Id.Item1}...");
                foreach (var dependency in asmReferencies.AssemblyReferences)
                {
                    Trace.TraceInformation($"Resolving Dependency {dependency.Item2}-{dependency.Item1}...");
                    //CIRCULAR REFERENCE STEP 1 : This dependency reference the current package, let's avoid referencing it.
                    if (IsDependencyCircular(mainAssembly, dependency))
                        continue;
                    
                    var packageId = _dependenciesResolverService.GetDependencyFromCacheOrResolve(mainAssembly.Value, dependency);
                    if (packageId == null)
                        throw new VersionNotFoundException($"{dependency.Item2}-{dependency.Item1} was not found on official repository/assemblies directory and none of nugetconverter.ini files on assemblies directory provide custom mapping to help me.");

                    //Package is already added or it reference it self we can ignore it 
                    if (!dependencies.Any(_ => _.Id.Equals(packageId.Item2))
                            // Package already referenced We can ignore it
                             && (packageId.Item2 != mainAssembly.Key.Item2 || packageId.Item1 != mainAssembly.Key.Item1))
                    {
                        var semanticVersion = new VersionSpec {MinVersion = packageId.Item1, IsMinInclusive = true};
                        dependencies.Add(new PackageDependency(packageId.Item2, semanticVersion));

                        //CIRCULAR REFERENCE STEP 2 :
                        //We removed the circular dependency previously
                        //to be sure everything is still working we add it again at an upper level.
                        // LibA
                        //   |_jaxen
                        //     |_jdom
                        //       |_jaxen
                        //         |_jdom
                        //         ...
                        //Into
                        //// LibA
                        //   |_jaxen
                        //   |_jdom
                        //     |_jaxen
                        var circularDependency = _configurationService.Get().CircularMapping.FirstOrDefault(__ => packageId.Item2 == __.Item1 && dependencies.All(_ => _.Id != __.Item2.Item1));
                        if(circularDependency!=null)
                                dependencies.Add(new PackageDependency(circularDependency.Item2.Item1, new VersionSpec(circularDependency.Item2.Item2)));
                    }
                }

                var manifestFileDll = new PhysicalPackageFile();
                manifestFileDll.SourcePath = asmReferencies.Path;
                manifestFileDll.TargetPath = @"lib\" + asmReferencies.FrameworkVersion + @"\" + Path.GetFileName(asmReferencies.Path);
                builder.Files.Add(manifestFileDll);

                var pdb = asmReferencies.Path.Replace(".dll", ".pdb");
                if (File.Exists(pdb))
                {
                    var manifestFilePdb = new PhysicalPackageFile();
                    manifestFilePdb.SourcePath = pdb;
                    manifestFilePdb.TargetPath = @"lib\" + asmReferencies.FrameworkVersion + @"\" + Path.GetFileNameWithoutExtension(asmReferencies.Path) + ".pdb";
                    builder.Files.Add(manifestFilePdb);
                }

                var xml = asmReferencies.Path.Replace(".dll", ".xml");
                if (File.Exists(xml))
                {
                    var manifestFileXml = new PhysicalPackageFile();
                    manifestFileXml.SourcePath = xml;
                    manifestFileXml.TargetPath = @"lib\" + asmReferencies.FrameworkVersion + @"\" + Path.GetFileNameWithoutExtension(asmReferencies.Path) + ".xml";
                    builder.Files.Add(manifestFileXml);
                }

                builder.DependencySets.Add(new PackageDependencySet(VersionUtility.ParseFrameworkName(asmReferencies.FrameworkVersion), dependencies));

                WritePackage(builder, metadata);

                // We absolutly need to generate extra package and keep the original
                // one in order to check cyclic dependancies
                var configuration = _configurationService.Get();
                foreach (var packageMapping in configuration.PackageMapping)
                {
                    var packageMappingMatching = packageMapping.Item2.Match(mainAssembly.Key.Item2);
                    if (packageMappingMatching.Success)
                    {
                        var group = packageMappingMatching.Groups[packageMapping.Item1];
                        if (group.Success)
                        {
                            metadata.Id = mainAssembly.Key.Item2.Replace(group.Value, packageMapping.Item1);
                            Trace.TraceWarning($"nugetconverter.ini asked to generate an extra {metadata.Id} package");
                            WritePackage(builder, metadata);
                        }
                    }

                }
            }
            catch (Exception exception)
            {
                var package = NugetRepository + mainAssembly.Key.Item2 + NugetSeparator + mainAssembly.Key.Item1 + ".nupkg";
                SendError(logToSlack, package, exception.Message);

                if (File.Exists(package))
                    File.Delete(package);
            }
        }
コード例 #9
0
		bool ParseExactVersion (string versionText)
		{
			SemanticVersion version = null;
			if (SemanticVersion.TryParse (versionText, out version)) {
				VersionSpec = new VersionSpec (version);
				return true;
			}
			return false;
		}
コード例 #10
0
        public override void Execute()
        {
            var package = Package;
            var packageRepositories = _moduleCatalog.GetAllPackageRepositories(true).ToList();

            var versionSpec = new VersionSpec
            {
                IsMinInclusive = true,
                MinVersion = package.Version,
                IsMaxInclusive = true,
                MaxVersion = package.Version
            };

            var packagesToDownload = ResolveDependencies(package.Id, versionSpec, packageRepositories);

            foreach (var packageToDownload in packagesToDownload)
            {
                Log.Debug("Installing package '{0}' from source '{1}'", packageToDownload.Package.Id, packageToDownload.PackageRepository.Source);

                var packageManager = new PackageManager(packageToDownload.PackageRepository, OutputDirectory);
                
                lock (_syncObj)
                {
                    packageManager.InstallPackage(packageToDownload.Package, IgnoreDependencies, AllowPrereleaseVersions);
                }
            }
        }
コード例 #11
0
        public void ReadPackages_TwoPackagesInSourceRepositoryAndTwoNewerPackageVersionAvailableAndProjectHasConstraint_NewerPackageVersionThatMeetsConstraintIsDisplayed()
        {
            CreateViewModel();
            var versionSpec = new VersionSpec();
            versionSpec.MinVersion = new SemanticVersion("1.0");
            versionSpec.IsMinInclusive = true;
            versionSpec.MaxVersion = new SemanticVersion("2.0");
            versionSpec.IsMaxInclusive = true;
            var constraintProvider = new DefaultConstraintProvider();
            constraintProvider.AddConstraint("Test", versionSpec);
            solution.FakeProjectToReturnFromGetProject.ConstraintProvider = constraintProvider;
            AddPackageToLocalRepository("Test", "1.0.0.0");
            AddPackageToActiveRepository("Test", "1.0.0.0");
            FakePackage expectedPackage = AddPackageToActiveRepository("Test", "2.0.0.0");
            AddPackageToActiveRepository("Test", "3.0.0.0");

            viewModel.ReadPackages();
            CompleteReadPackagesTask();

            var expectedPackages = new FakePackage[] {
                expectedPackage
            };

            PackageCollectionAssert.AreEqual(expectedPackages, viewModel.PackageViewModels);
        }
コード例 #12
0
 public void matches_dependencies_with_version_spec_with_no_max_version()
 {
     var spec = new VersionSpec {MinVersion = new SemanticVersion("1.1.0.0")};
     theFinder.Matches(new Dependency("Test", spec)).ShouldBeTrue();
 }
コード例 #13
0
ファイル: VersionSpec.cs プロジェクト: themotleyfool/NuGet
 public bool Equals(VersionSpec other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.MinVersion, MinVersion) && other.IsMinInclusive.Equals(IsMinInclusive) && Equals(other.MaxVersion, MaxVersion) && other.IsMaxInclusive.Equals(IsMaxInclusive);
 }
コード例 #14
0
        public void GetUpdatedPackages_OnePackageReferencedWithConstraintAndUpdatesAvailable_LatestVersionReturnedBasedOnConstraint()
        {
            CreateProject();
            project.FakePackages.Add(new FakePackage("Test", "1.0"));
            var sourceRepository = new FakePackageRepository();
            FakePackage packageVersion2 = sourceRepository.AddFakePackageWithVersion("Test", "2.0");
            FakePackage [] expectedPackages = new [] {
                packageVersion2
            };
            sourceRepository.AddFakePackageWithVersion("Test", "3.0");
            var versionSpec = new VersionSpec();
            versionSpec.MinVersion = new SemanticVersion("1.0");
            versionSpec.IsMinInclusive = true;
            versionSpec.MaxVersion = new SemanticVersion("2.0");
            versionSpec.IsMaxInclusive = true;
            var constraintProvider = new DefaultConstraintProvider();
            constraintProvider.AddConstraint("Test", versionSpec);
            project.ConstraintProvider = constraintProvider;
            CreateUpdatedPackages(sourceRepository);

            IEnumerable<IPackage> packages = updatedPackages.GetUpdatedPackages();

            PackageCollectionAssert.AreEqual(expectedPackages, packages);
        }
コード例 #15
0
		public void AddDependency (string id, SemanticVersion minVersion, SemanticVersion maxVersion)
		{
			var versionSpec = new VersionSpec ();
			versionSpec.MinVersion = minVersion;
			versionSpec.MaxVersion = maxVersion;
			var dependency = new PackageDependency (id, versionSpec);
			DependenciesList.Add (dependency);
		}
コード例 #16
0
		public void Execute_PackageHasConstraint_LatestPackageIsNotUpdatedButPackageWithHighestVersionThatMatchesConstraint ()
		{
			CreateSolution ();
			var constraintProvider = new DefaultConstraintProvider ();
			var versionSpec = new VersionSpec ();
			versionSpec.MinVersion = new SemanticVersion ("1.0");
			versionSpec.IsMinInclusive = true;
			versionSpec.IsMaxInclusive = true;
			versionSpec.MaxVersion = new SemanticVersion ("2.0");
			constraintProvider.AddConstraint ("MyPackage", versionSpec);
			fakeProject.ConstraintProvider = constraintProvider;
			fakeProject.AddFakePackageToSourceRepository ("MyPackage", "1.0");
			FakePackage packageVersion2 = fakeProject.AddFakePackageToSourceRepository ("MyPackage", "2.0");
			fakeProject.AddFakePackageToSourceRepository ("MyPackage", "3.0");
			fakeProject.FakePackages.Add (new FakePackage ("MyPackage", "1.0"));
			action.PackageId = "MyPackage";

			action.Execute ();

			Assert.AreEqual (packageVersion2, fakeProject.PackagePassedToUpdatePackage);
		}
コード例 #17
0
ファイル: GenerateNuSpec.cs プロジェクト: kovalikp/nuproj
        private static void SetMaxVersion(VersionSpec target, IVersionSpec source)
        {
            if (source == null || source.MaxVersion == null)
            {
                return;
            }

            if (target.MaxVersion == null)
            {
                target.MaxVersion = source.MaxVersion;
                target.IsMaxInclusive = source.IsMaxInclusive;
            }

            if (target.MaxVersion > source.MaxVersion)
            {
                target.MaxVersion = source.MaxVersion;
                target.IsMaxInclusive = source.IsMaxInclusive;
            }

            if (target.MaxVersion == source.MaxVersion)
            {
                target.IsMaxInclusive = target.IsMaxInclusive && source.IsMaxInclusive;
            }
        }
コード例 #18
0
ファイル: GenerateNuSpec.cs プロジェクト: kovalikp/nuproj
        private static IVersionSpec AggregateVersions(IVersionSpec aggregate, IVersionSpec next)
        {
            var versionSpec = new VersionSpec();
            SetMinVersion(versionSpec, aggregate);
            SetMinVersion(versionSpec, next);
            SetMaxVersion(versionSpec, aggregate);
            SetMaxVersion(versionSpec, next);

            if (versionSpec.MinVersion == null && versionSpec.MaxVersion == null)
            {
                versionSpec = null;
            }

            return versionSpec;
        }
コード例 #19
0
            public InstalledPackInfo([NotNull] InternalPackageManager.CacheEntry cacheEntry,
                [NotNull] IPackageRepository repository)
            {
                if (cacheEntry == null) throw new ArgumentNullException(nameof(cacheEntry));
                if (repository == null) throw new ArgumentNullException(nameof(repository));

                var versionSpec = new VersionSpec(cacheEntry.SemanticVersion);
                var package = MachineCache.FindPackage(cacheEntry.Name, versionSpec, true, true)
                           ?? repository.FindPackage(cacheEntry.Name, versionSpec, true, true);

                CanUnInstall = true;

                _name = cacheEntry.Name;
                Name = package.Title;
                Description = package.Description;
                Version = package.Version.Version;
            }
コード例 #20
0
        private void BuildPackage(Project project, string assemblyPath, PackageBuilder builder, FrameworkName targetFramework)
        {
            var framework = targetFramework;
            var dependencies = new List<PackageDependency>();

            var frameworkReferences = new HashSet<string>(_resolver.GetFrameworkReferences(framework), StringComparer.OrdinalIgnoreCase);
            var frameworkAssemblies = new List<string>();

            if (project.Dependencies.Count > 0)
            {
                foreach (var dependency in project.Dependencies)
                {
                    if (frameworkReferences.Contains(dependency.Name))
                    {
                        frameworkAssemblies.Add(dependency.Name);
                    }
                    else
                    {
                        var dependencyVersion = new VersionSpec()
                        {
                            IsMinInclusive = true,
                            MinVersion = dependency.Version
                        };
                        if (dependencyVersion.MinVersion == null || dependencyVersion.MinVersion.IsSnapshot)
                        {
                            var actual = _packages
                                .Where(pkg => string.Equals(pkg.Identity.Name, project.Name, StringComparison.OrdinalIgnoreCase))
                                .SelectMany(pkg => pkg.Dependencies)
                                .SingleOrDefault(dep => string.Equals(dep.Name, dependency.Name, StringComparison.OrdinalIgnoreCase));
                            if (actual != null)
                            {
                                dependencyVersion.MinVersion = actual.Version;
                            }
                        }

                        dependencies.Add(new PackageDependency(dependency.Name, dependencyVersion));
                    }
                }

                if (dependencies.Count > 0)
                {
                    builder.DependencySets.Add(new PackageDependencySet(framework, dependencies));
                }
            }

            // Only do this on full desktop
            if (targetFramework.Identifier == VersionUtility.DefaultTargetFramework.Identifier)
            {
                foreach (var a in frameworkAssemblies)
                {
                    builder.FrameworkReferences.Add(new FrameworkAssemblyReference(a));
                }
            }

            var file = new PhysicalPackageFile();
            file.SourcePath = assemblyPath;
            var folder = VersionUtility.GetShortFrameworkName(framework);
            file.TargetPath = String.Format(@"lib\{0}\{1}.dll", folder, project.Name);
            builder.Files.Add(file);
        }
コード例 #21
0
        public static bool TryParseVersionSpec(string value, out IVersionSpec result)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var versionSpec = new VersionSpec();

            value = value.Trim();

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

            if (SemanticVersion.TryParse(value, out version))
            {
                // A plain version is treated as an inclusive minimum range
                result = new VersionSpec
                {
                    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);
            }
            else 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 (!TryParseVersion(minVersionString, out version))
                {
                    return(false);
                }
                versionSpec.MinVersion = version;
            }

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

            // Successful parse!
            result = versionSpec;
            return(true);
        }
コード例 #22
0
ファイル: StubPackage.cs プロジェクト: bobpace/ripple
            public DependencyExpression Min(string version)
            {
                var spec = _dependency.VersionSpec as VersionSpec;
                if (spec != null)
                {
                    spec.MinVersion = new SemanticVersion(version);
                    spec.MaxVersion = null;
                    return this;
                }

                spec = new VersionSpec(new SemanticVersion(version)) { MaxVersion = null };
                _dependencies.Remove(_dependency);

                var dependency = new PackageDependency(_dependency.Id, spec);
                _dependencies.Fill(dependency);

                return new DependencyExpression(dependency, _dependencies);
            }
コード例 #23
0
        public static bool TryParseVersionSpec(string value, out IVersionSpec result)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

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

            // First, try to parse it as a plain version string
            SemanticVersion version;
            if (SemanticVersion.TryParse(value, out version))
            {
                // A plain version is treated as an inclusive minimum range
                result = new VersionSpec
                         {
                             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;
            }
            else 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 (!TryParseVersion(minVersionString, out version))
                {
                    return false;
                }
                versionSpec.MinVersion = version;
            }

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

            // Successful parse!
            result = versionSpec;
            return true;
        }
コード例 #24
0
    private static IVersionSpec StripPatchLevel(IVersionSpec dependencyVersionSpec)
    {
      // Given a curatedFeedVersion of 8.0, make [8.0.1] work. Semver says the patch
      // level should be backwards compatible, so this should be safe
      var spec = new VersionSpec
      {
        IsMinInclusive = true,
        MinVersion =
          new SemanticVersion(dependencyVersionSpec.MinVersion.Version.Major,
            dependencyVersionSpec.MinVersion.Version.Minor, 0, 0),
        IsMaxInclusive = dependencyVersionSpec.IsMaxInclusive,
        MaxVersion = dependencyVersionSpec.MaxVersion
      };

      return spec;
    }
コード例 #25
0
        public static bool TryParseVersionSpec(string value, out IVersionSpec result)
        {
            SemanticVersion version;

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            VersionSpec spec = new VersionSpec();

            value = value.Trim();
            if (SemanticVersion.TryParse(value, out version))
            {
                VersionSpec spec1 = new VersionSpec();
                spec1.MinVersion     = version;
                spec1.IsMinInclusive = true;
                result = spec1;
                return(true);
            }
            result = null;
            if (value.Length < 3)
            {
                return(false);
            }
            char ch = value.First <char>();

            if (ch == '(')
            {
                spec.IsMinInclusive = false;
            }
            else
            {
                if (ch != '[')
                {
                    return(false);
                }
                spec.IsMinInclusive = true;
            }
            ch = value.Last <char>();
            if (ch == ')')
            {
                spec.IsMaxInclusive = false;
            }
            else
            {
                if (ch != ']')
                {
                    return(false);
                }
                spec.IsMaxInclusive = true;
            }
            value = value.Substring(1, value.Length - 2);
            char[]   separator = new char[] { ',' };
            string[] strArray  = value.Split(separator);
            if (strArray.Length > 2)
            {
                return(false);
            }
            if (Enumerable.All <string>(strArray, new Func <string, bool>(string.IsNullOrEmpty)))
            {
                return(false);
            }
            string str  = strArray[0];
            string str2 = (strArray.Length == 2) ? strArray[1] : strArray[0];

            if (!string.IsNullOrWhiteSpace(str))
            {
                if (!TryParseVersion(str, out version))
                {
                    return(false);
                }
                spec.MinVersion = version;
            }
            if (!string.IsNullOrWhiteSpace(str2))
            {
                if (!TryParseVersion(str2, out version))
                {
                    return(false);
                }
                spec.MaxVersion = version;
            }
            result = spec;
            return(true);
        }
コード例 #26
0
ファイル: BuildContext.cs プロジェクト: noahfalk/dnx
        public void PopulateDependencies(PackageBuilder packageBuilder)
        {
            var dependencies = new List<PackageDependency>();
            var projectReferenceByName = _applicationHostContext.ProjectDepencyProvider
                                                                .Dependencies
                                                                .ToDictionary(r => r.Identity.Name);

            LibraryDescription description;
            if (!projectReferenceByName.TryGetValue(_project.Name, out description))
            {
                return;
            }

            foreach (var dependency in description.Dependencies)
            {
                if (!dependency.HasFlag(LibraryDependencyTypeFlag.BecomesNupkgDependency))
                {
                    continue;
                }

                Runtime.Project dependencyProject;
                if (projectReferenceByName.ContainsKey(dependency.Name) &&
                    _applicationHostContext.ProjectResolver.TryResolveProject(dependency.Name, out dependencyProject) &&
                    dependencyProject.EmbedInteropTypes)
                {
                    continue;
                }

                if (dependency.LibraryRange.IsGacOrFrameworkReference)
                {
                    packageBuilder.FrameworkReferences.Add(new FrameworkAssemblyReference(dependency.LibraryRange.GetReferenceAssemblyName(), new[] { _targetFramework }));
                }
                else
                {
                    IVersionSpec dependencyVersion = null;

                    if (dependency.LibraryRange.VersionRange == null ||
                        dependency.LibraryRange.VersionRange.VersionFloatBehavior != SemanticVersionFloatBehavior.None)
                    {
                        var actual = _applicationHostContext.DependencyWalker.Libraries
                            .Where(pkg => string.Equals(pkg.Identity.Name, _project.Name, StringComparison.OrdinalIgnoreCase))
                            .SelectMany(pkg => pkg.Dependencies)
                            .SingleOrDefault(dep => string.Equals(dep.Name, dependency.Name, StringComparison.OrdinalIgnoreCase));

                        if (actual != null)
                        {
                            dependencyVersion = new VersionSpec
                            {
                                IsMinInclusive = true,
                                MinVersion = actual.Library.Version
                            };
                        }
                    }
                    else
                    {
                        var versionRange = dependency.LibraryRange.VersionRange;

                        dependencyVersion = new VersionSpec
                        {
                            IsMinInclusive = true,
                            MinVersion = versionRange.MinVersion,
                            MaxVersion = versionRange.MaxVersion,
                            IsMaxInclusive = versionRange.IsMaxInclusive
                        };
                    }

                    dependencies.Add(new PackageDependency(dependency.Name, dependencyVersion));
                }
            }

            packageBuilder.DependencySets.Add(new PackageDependencySet(_targetFramework, dependencies));
        }