public void Parse(string line, PackageDescriptor descriptor)
 {
     var match = _regex.Match(line);
     if (!match.Success)
         return;
     ParseContent(match.Groups["content"].Value, descriptor);
 }
        IEnumerable<ICommandOutput> Build()
        {
            var packageName = Name ?? Environment.Descriptor.Name;
            var destinationPath = _destinationPath ?? Environment.CurrentDirectory;

            var packageDescriptorForEmbedding = new PackageDescriptor(GetCurrentPackageDescriptor());

            var generatedVersion = GetPackageVersion(_buildResults, packageDescriptorForEmbedding);

            if (generatedVersion == null)
                yield return new Error("Could not build package, no version found.");

            packageDescriptorForEmbedding.Version = generatedVersion;
            packageDescriptorForEmbedding.Name = packageName;

            foreach (var file in _buildResults)
                yield return new GenericMessage(string.Format("Copying: {0} - {1}", file.ExportName, file.Path));

            var packageFilePath = destinationPath.GetFile(
                PackageNameUtility.PacakgeFileName(packageName, generatedVersion.ToString()));

            var packageContent = GeneratePackageContent(_buildResults).Concat(
                                    GenerateVersionFile(generatedVersion),
                                    GenerateDescriptorFile(packageDescriptorForEmbedding)
                                 );

            PackageBuilder.NewFromFiles(packageFilePath, packageContent);
            yield return new GenericMessage(string.Format("Package built at '{0}'.", packageFilePath));
        }
Example #3
0
        public IEnumerable<ICommandOutput> Execute()
        {
            var currentDirectory = Environment.CurrentDirectory;
            var packagePath = Target;
            var projectDirectory = currentDirectory.GetDirectory(packagePath);
            var packageName = Target == "." ? Environment.CurrentDirectory.Name : Target;

            var packageDescriptorFile = projectDirectory.GetFile(packageName + ".wrapdesc");

            var items = new List<IFileSystemItem> { packageDescriptorFile };

            var packageDescriptor = new PackageDescriptor();
            if (Meta)
            {
                packageDescriptor.BuildCommand = "$meta";
            }
            else
            {
                AddOpenWrapDependency(packageDescriptor);
                AddPackageFolders(projectDirectory, items);

                foreach(var m in CopyOpenWrap(projectDirectory)) yield return m;
            }
            WriteVersionFile(projectDirectory);
            WriteDescriptor(packageDescriptorFile, packageDescriptor);
            yield return new GenericMessage("Package '{0}' initialized. Start adding packages by using the 'add-wrap' command.", packageName);
        }
Example #4
0
        public DependencyResolutionResult TryResolveDependencies(
            PackageDescriptor packageDescriptor,
            IEnumerable<IPackageRepository> repositoriesToQuery)
        {
            var packageSelection = new PackageSelectionContext();

            for (int i = 0; i < MAX_RETRIES; i++)
            {
                var exclusionList = packageSelection.IncompatiblePackageVersions.Select(x => x.Key);

                var visitor = new DependencyVisitor(repositoriesToQuery, packageSelection, packageDescriptor.Dependencies, packageDescriptor.Overrides);
                var resolutionSucceeded = visitor
                        .VisitDependencies(packageDescriptor.Dependencies);

                if (resolutionSucceeded == false)
                {
                    var newExclusionList = packageSelection.IncompatiblePackageVersions.Select(x => x.Key);
                    if (newExclusionList.Except(exclusionList).Any())
                    {
                        packageSelection = new PackageSelectionContext(packageSelection.IncompatiblePackageVersions);

                        continue;
                    }
                }
                return Result(packageSelection, repositoriesToQuery, visitor.NotFound);
            }
            throw new InvalidOperationException(string.Format("OpenWrap tried {0} times to resolve the tree of dependencies and gave up.", MAX_RETRIES));
        }
 public void Parsing_whitespace_description_sets_Description_to_empty_string()
 {
     var parser = new DescriptionParser();
     var wrapDescriptor = new PackageDescriptor();
     parser.Parse("description : ", wrapDescriptor);
     wrapDescriptor.Description.ShouldBe("");
 }
 public void Parsing_description_trims_whitespace()
 {
     var parser = new DescriptionParser();
     var wrapDescriptor = new PackageDescriptor();
     parser.Parse("description : \t test message   \t", wrapDescriptor);
     wrapDescriptor.Description.ShouldBe("test message");
 }
 public void Parsing_description_sets_Description_property()
 {
     var parser = new DescriptionParser();
     var wrapDescriptor = new PackageDescriptor();
     parser.Parse("description: test message", wrapDescriptor);
     wrapDescriptor.Description.ShouldBe("test message");
 }
 public DefaultPackageInfo(string packageFileName, Version versionFileContent, PackageDescriptor descriptor)
 {
     _descriptor = descriptor;
     _packageVersion = versionFileContent
         ?? descriptor.Version
         ?? PackageNameUtility.GetVersion(packageFileName);
     _packageName = PackageNameUtility.GetName(packageFileName);
 }
        public IEnumerable<PackageOperationResult> CleanProjectPackages(PackageDescriptor packages, IPackageRepository projectRepository, string name)
        {
            if (packages == null) throw new ArgumentNullException("packages");
            if (projectRepository == null) throw new ArgumentNullException("projectRepository");

            var repoForClean = projectRepository as ISupportCleaning;
            if (repoForClean == null) throw new ArgumentException("projectRepository must implement ISupportCleaning");
            return CleanProjectPackagesCore(packages, repoForClean, x => name.EqualsNoCase(x));
        }
 public IEnumerable<IAssemblyReferenceExportItem> GetAssemblyReferences(PackageDescriptor descriptor, IPackageRepository repository, IWrapAssemblyClient client)
 {
     return (from dependency in descriptor.Dependencies
             where dependency.ContentOnly == false
             let package = repository.Find(dependency)
             where package != null
             let items = package.Load().GetExport("bin", client.Environment).Items.OfType<IAssemblyReferenceExportItem>()
             select items).SelectMany(x => x);
 }
 public InMemoryEnvironment(IDirectory currentDirectory, IDirectory configDirectory)
 {
     CurrentDirectory = currentDirectory;
     SystemRepository = new InMemoryRepository("System repository");
     RemoteRepository = new InMemoryRepository("Remote repository");
     CurrentDirectoryRepository = new InMemoryRepository("Current directory repository");
     RemoteRepositories = new List<InMemoryRepository> { RemoteRepository };
     DescriptorFile = CurrentDirectory.GetFile("descriptor.wrapdesc");
     Descriptor = new PackageDescriptor();
     ConfigurationDirectory = configDirectory;
 }
 public PackageDescriptor(PackageDescriptor copy)
 {
     Dependencies = copy.Dependencies.Select(x => new PackageDependency(x)).ToList();
     Overrides = new List<PackageNameOverride>(copy.Overrides);
     Description = copy.Description;
     UseProjectRepository = copy.UseProjectRepository;
     Name = copy.Name;
     Version = copy.Version;
     Anchored = copy.Anchored;
     BuildCommand = copy.BuildCommand;
     CreationTime = copy.CreationTime;
 }
        public IEnumerable<PackageOperationResult> AddProjectPackage(PackageRequest packageToAdd,
            IEnumerable<IPackageRepository> sourceRepositories,
            PackageDescriptor projectDescriptor,
            IPackageRepository projectRepository,
            PackageAddOptions options = PackageAddOptions.Default)
        {
            Check.NotNull(packageToAdd, "packageToAdd");
            Check.NoNullElements(sourceRepositories, "sourceRepositories");
            Check.NotNull(projectDescriptor, "projectDescriptor");
            Check.NotNull(projectRepository, "projectRepository");

            return AddProjectPackageCore(packageToAdd, sourceRepositories, projectDescriptor, projectRepository, options);
        }
 protected abstract void ParseContent(string content, PackageDescriptor descriptor);
 protected abstract IEnumerable<string> WriteContent(PackageDescriptor descriptor);
        public IEnumerable<PackageOperationResult> RemoveProjectPackage(PackageRequest packageToRemove,
            PackageDescriptor packageDescriptor,
            IPackageRepository projectRepository,
            PackageRemoveOptions options = PackageRemoveOptions.Default)
        {
            if (packageToRemove == null) throw new ArgumentNullException("packageToRemove");
            if (packageDescriptor == null) throw new ArgumentNullException("packageDescriptor");
            if (projectRepository == null) throw new ArgumentNullException("projectRepository");

            return (packageToRemove.ExactVersion == null && !packageToRemove.LastVersion)
                           ? RemoveFromDescriptor(packageToRemove, packageDescriptor, projectRepository, options)
                           : RemovePackageFilesFromProjectRepo(packageToRemove, projectRepository);
        }
 public IEnumerable<string> Write(PackageDescriptor descriptor)
 {
     var content = WriteContent(descriptor).ToList();
     if (content.Count == 0) return content;
     return content.Select(x => Header + ": " + x);
 }
Example #18
0
        Version GetPackageVersion(IList<FileBuildResult> buildFiles, PackageDescriptor packageDescriptorForEmbedding)
        {
            // gets the package version from (in this order):
            // 1. 'version' file generated by the build
            // 2. 'version' file living alongside the .wrapdesc file
            // 3. 'version:' header in wrap descriptor

            return new DefaultPackageInfo(string.Empty, GetVersionFromVersionFiles(buildFiles), packageDescriptorForEmbedding).Version;
        }
        public IEnumerable<PackageOperationResult> UpdateProjectPackages(IEnumerable<IPackageRepository> sourceRepositories,
            IPackageRepository projectRepository,
            PackageDescriptor projectDescriptor,
            string packageName)
        {
            if (sourceRepositories == null) throw new ArgumentNullException("sourceRepositories");
            if (projectRepository == null) throw new ArgumentNullException("projectRepository");
            if (projectDescriptor == null) throw new ArgumentNullException("projectDescriptor");
            if (sourceRepositories.Any(x => x == null)) throw new ArgumentException("Some repositories are null.", "sourceRepositories");

            return CopyPackageCore(sourceRepositories, new[] { projectRepository }, projectDescriptor, x => x.EqualsNoCase(packageName));
        }
Example #20
0
 IEnumerable<ICommandOutput> VerifyPackageCache(PackageDescriptor packageDescriptor)
 {
     return PackageResolver.VerifyPackageCache(Environment, packageDescriptor);
 }
Example #21
0
 PackageContent GenerateDescriptorFile(PackageDescriptor descriptor)
 {
     var descriptorStream = new MemoryStream();
     new PackageDescriptorReaderWriter().Write(descriptor, descriptorStream);
     return new PackageContent
     {
         FileName = descriptor.Name + ".wrapdesc",
         RelativePath = ".",
         Stream = descriptorStream.ResetOnRead(),
         Size = descriptorStream.Length
     };
 }
Example #22
0
        static PackageContent ConvertSpecification(ZipFile file, ZipEntry entry)
        {
            var nuspec = new XmlDocument();
            var ns = new XmlNamespaceManager(nuspec.NameTable);
            ns.AddNamespace("nuspec", NuSpecSchema);
            nuspec.Load(file.GetInputStream(entry));

            var descriptor = new PackageDescriptor
            {
                Name = nuspec.Element(XPaths.PackageName, ns),
                Version = nuspec.Element(XPaths.PackageVersion, ns).ToVersion(),
                Description = nuspec.Element(XPaths.PacakgeDescrition, ns),
                Dependencies = nuspec.Elements(XPaths.PackageDependencies, ns).Select(x=>CreateDependency(x)).ToList()
            };
            var memoryStream = new MemoryStream();
            new PackageDescriptorReaderWriter().Write(descriptor, memoryStream);
            memoryStream.Position = 0;
            return new PackageContent
            {
                FileName = Path.GetFileNameWithoutExtension(entry.Name) + ".wrapdesc",
                RelativePath = ".",
                Size = memoryStream.Length,
                Stream = () =>
                {
                    memoryStream.Position = 0;
                    return memoryStream;
                }
            };
        }
Example #23
0
        IEnumerable<ICommandOutput> UpdateProjectPackages()
        {
            if (!Project)
                yield break;

            var sourceRepos = Environment.RemoteRepositories
                    .Concat(Environment.SystemRepository,
                            Environment.CurrentDirectoryRepository);

            var updateDescriptor = new PackageDescriptor(Environment.Descriptor);
            if (!string.IsNullOrEmpty(Name))
                updateDescriptor.Dependencies = updateDescriptor.Dependencies.Where(x => x.Name.Equals(Name, StringComparison.OrdinalIgnoreCase)).ToList();

            var resolvedPackages = PackageResolver.TryResolveDependencies(
                updateDescriptor,
                sourceRepos);

            if (!resolvedPackages.IsSuccess)

            {
                foreach (var m in FailedUpdate(resolvedPackages, sourceRepos)) yield return m;
                yield break;
            }

            foreach (var m in resolvedPackages.GacConflicts(Environment.ExecutionEnvironment))
                yield return m;

            var copyResult = PackageResolver.CopyPackagesToRepositories(
                resolvedPackages,
                Environment.ProjectRepository
                );
            foreach (var m in copyResult) yield return m;

            foreach (var m in PackageResolver.VerifyPackageCache(Environment, updateDescriptor)) yield return m;
        }
        IEnumerable<PackageOperationResult> AddProjectPackageCore(PackageRequest packageToAdd, IEnumerable<IPackageRepository> sourceRepositories, PackageDescriptor projectDescriptor, IPackageRepository projectRepository, PackageAddOptions options)
        {
            var finalDescriptor = (options & PackageAddOptions.UpdateDescriptor) == PackageAddOptions.UpdateDescriptor
                                          ? projectDescriptor
                                          : new PackageDescriptor(projectDescriptor);
            var existingEntries = finalDescriptor.Dependencies.Where(x => x.Name.EqualsNoCase(packageToAdd.Name)).ToList();
            if (existingEntries.Count > 0)
            {
                finalDescriptor.Dependencies.RemoveRange(existingEntries);
                yield return new PackageDescriptorUpdateResult(PackageDescriptorDependencyUpdate.Updated);
            }
            else
            {
                yield return new PackageDescriptorUpdateResult(PackageDescriptorDependencyUpdate.Added);
            }

            finalDescriptor.Dependencies.Add(ToDependency(packageToAdd, options));

            foreach (var m in CopyPackageCore(sourceRepositories, new[] { projectRepository }, finalDescriptor, x => true))
                yield return m;
        }
 public PackageCleanCannotDo(PackageDescriptor projectDescriptor)
 {
 }
        IEnumerable<PackageOperationResult> CleanProjectPackagesCore(PackageDescriptor projectDescriptor, ISupportCleaning projectRepository, Func<string, bool> packageName)
        {
            var resolvedPackages = _resolver.TryResolveDependencies(projectDescriptor, new[] { projectRepository });
            if(resolvedPackages.SuccessfulPackages.Any() == false)
            {
                yield return new PackageCleanCannotDo(projectDescriptor);
                yield break;
            }
            var projectPackagesInUse = from successfulPackageStack in resolvedPackages.SuccessfulPackages
                                       from package in successfulPackageStack.Packages
                                       where packageName(package.Identifier.Name)
                                       select package;

            var otherPackages = from packagesByName in projectRepository.PackagesByName
                                where !packageName(packagesByName.Key)
                                from package in packagesByName
                                select package;
            var packagesInUse = projectPackagesInUse.Concat(otherPackages).ToList();

            foreach (var cleanedPackage in projectRepository.Clean(packagesInUse))
                yield return cleanedPackage;
            foreach (var anchored in AnchorPackages(resolvedPackages, new[] { projectRepository }))
                yield return anchored;
        }
Example #27
0
 protected override void ParseContent(string content, PackageDescriptor descriptor)
 {
     descriptor.Version = new Version(content);
 }
        IEnumerable<PackageOperationResult> CopyPackageCore(IEnumerable<IPackageRepository> sourceRepositories,
            IEnumerable<IPackageRepository> destinationRepositories,
            PackageDescriptor descriptor,
            Func<string, bool> nameSelector)
        {
            var updateDescriptor = new PackageDescriptor(descriptor);
            updateDescriptor.Dependencies.Clear();
            updateDescriptor.Dependencies.AddRange(descriptor.Dependencies.Where(x => nameSelector(x.Name)));

            var resolvedPackages = _resolver.TryResolveDependencies(
                    updateDescriptor,
                    sourceRepositories);

            if (!resolvedPackages.IsSuccess)
            {
                foreach (var packageResolution in ReturnError(resolvedPackages))
                    yield return packageResolution;
                yield break;
            }

            var packagesForGacDetection = resolvedPackages.SuccessfulPackages.Select(x => x.Packages.First()).ToList();

            foreach (var conflict in from errors in GacResolver.InGac(packagesForGacDetection)
                                     select new PackageGacConflictResult(errors.Key, errors))
                yield return conflict;

            foreach (var m in CopyPackagesToRepositories(sourceRepositories, resolvedPackages, destinationRepositories))
                yield return m;

            foreach (var repo in destinationRepositories)
                repo.RefreshPackages();

            // need to refresh the resolve with the newly copied packages
            resolvedPackages = _resolver.TryResolveDependencies(
                    updateDescriptor,
                    destinationRepositories);

            foreach(var anchor in AnchorPackages(resolvedPackages, destinationRepositories))
                yield return anchor;
        }
Example #29
0
 protected override IEnumerable<string> WriteContent(PackageDescriptor descriptor)
 {
     if (descriptor.Version != null)
         yield return descriptor.Version.ToString();
 }
 IEnumerable<PackageOperationResult> RemoveFromDescriptor(PackageRequest packageToRemove, PackageDescriptor packageDescriptor, IPackageRepository projectRepository, PackageRemoveOptions options)
 {
     var dependency = packageDescriptor.Dependencies.FirstOrDefault(x => x.Name.EqualsNoCase(packageToRemove.Name));
     if (dependency == null)
     {
         yield return new PackageDescriptorUpdateResult(PackageDescriptorDependencyUpdate.DependencyNotFound);
         yield break;
     }
     packageDescriptor.Dependencies.Remove(dependency);
     if ((options & PackageRemoveOptions.Clean) == PackageRemoveOptions.Clean)
         foreach (var cleaned in CleanProjectPackages(packageDescriptor, projectRepository, packageToRemove.Name))
             yield return cleaned;
 }