Exemplo n.º 1
0
 VersionChange ISemanticVersioning.Calculate(IEnumerable<string> targets, IEnumerable<string> published)
 {
     var result = new VersionChange();
     var diff = GetDifferences(targets, published);
     var update = GetVersionUpdate(diff);
     return new VersionChange() { Change = update, Differences = diff };
 }
Exemplo n.º 2
0
        VersionChange IRunner.Execute()
        {
            var repo = _nugetFactory.GetPackageRepository();
            var manifest = _nugetFactory.GetTargetManifest();

            var targetPackage = repo.FindPackage(manifest.Metadata.Id, new SemanticVersion(manifest.Metadata.Version));
            var publishedPackage = repo.FindPackage(manifest.Metadata.Id);

            if (targetPackage == null || publishedPackage == null)
                throw new InvalidOperationException("Can not read package " + manifest.Metadata.Id);

            var targetDeffinition = GetPackageDefinition(targetPackage, true);
            var publishedDeffinition = GetPackageDefinition(publishedPackage, false);

            //TODO: read product id and version to store and update
            var productFile = targetPackage
                .GetFiles()
                .Where(f => Path.GetExtension(f.Path).Equals(".nuprod", StringComparison.InvariantCultureIgnoreCase))
                .FirstOrDefault();

            var newVersion = default(SemanticVersion);
            var change = default(VersionChange);
            if (productFile != null)
            {
                var packageDir = _nugetFactory.GetPackageManager().PathResolver.GetPackageDirectory(targetPackage);
                var path = Path.Combine(_arguments.GetInstallationDirectory(), packageDir, productFile.Path);
                var serializer = new XmlSerializer(typeof(Product));
                var product = default(Product);
                using (var stream = File.OpenRead(path))
                {
                    product = (Product)serializer.Deserialize(stream);
                }

                using (var zip = ZipFile.Read(product.CopyVersionFrom))
                {
                    var entry = zip.Where(e => Path.GetExtension(e.FileName).Equals(".nuspec")).FirstOrDefault();
                    var m = Manifest.ReadFrom(entry.OpenReader(), true);
                    change = new VersionChange() { Change = new Version(m.Metadata.Version) };
                    newVersion = new SemanticVersion(change.Change);
                }
            }
            else
            {
                change = _versioning.Calculate(targetDeffinition, publishedDeffinition);
                var major = publishedPackage.Version.Version.Major + change.Change.Major;
                var minor = publishedPackage.Version.Version.Minor + change.Change.Minor;
                var patch = publishedPackage.Version.Version.Build + change.Change.Build;
                newVersion = new SemanticVersion(major, minor, patch, string.Empty);
            }

            _nugetFactory.UpdateTargetManifest(newVersion.ToString());

            _nugetFactory.GetPackageManager().UninstallPackage(targetPackage, true, true);
            _nugetFactory.GetPackageManager().UninstallPackage(publishedPackage, true, true);

            return change;
        }