public InMemoryEnvironment()
 {
     UserRepository = new InMemoryRepository();
     RemoteRepository = new InMemoryRepository();
     RemoteRepositories = new List<InMemoryRepository> { RemoteRepository };
     Descriptor = new WrapDescriptor();
 }
 public void Parsing_description_sets_Description_property()
 {
     var parser = new DescriptionParser();
     var wrapDescriptor = new WrapDescriptor();
     parser.Parse("description: test message", wrapDescriptor);
     wrapDescriptor.Description.ShouldBe("test message");
 }
 public void Parse(string line, WrapDescriptor descriptor)
 {
     var match = _regex.Match(line);
     if (!match.Success)
         return;
     ParseContent(match.Groups["content"].Value, descriptor);
 }
 public void Parsing_description_trims_whitespace()
 {
     var parser = new DescriptionParser();
     var wrapDescriptor = new WrapDescriptor();
     parser.Parse("description : \t test message   \t", wrapDescriptor);
     wrapDescriptor.Description.ShouldBe("test message");
 }
 public void Parsing_whitespace_description_sets_Description_to_empty_string()
 {
     var parser = new DescriptionParser();
     var wrapDescriptor = new WrapDescriptor();
     parser.Parse("description : ", wrapDescriptor);
     wrapDescriptor.Description.ShouldBe("");
 }
 public IEnumerable<IAssemblyReferenceExportItem> GetAssemblyReferences(WrapDescriptor descriptor, IPackageRepository repository, IWrapAssemblyClient client)
 {
     return (from dependency in descriptor.Dependencies
             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 };
     Descriptor = new WrapDescriptor() { File = CurrentDirectory.GetFile("descriptor.wrapdesc").MustExist()};
     ConfigurationDirectory = configDirectory;
 }
        public override void ParseContent(string content, WrapDescriptor descriptor)
        {
            var arguments = content.Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            // TODO: Should this throw, or just return?
            // Perhaps we need a way to record parse errors for better error reporting?
            if (arguments.Length != 2) throw new Exception("Parse error in \"override\" declaration. Expected format: \"override {old-package} {new-package}.\". Actual line: \"" + content + "\"");

            var oldPackage = arguments[0];
            var newPackage = arguments[1];
            descriptor.Overrides.Add(new WrapOverride(oldPackage, newPackage));
        }
Exemple #9
0
        public DependencyResolutionResult TryResolveDependencies(WrapDescriptor wrapDescriptor, IPackageRepository projectRepository, IPackageRepository userRepository, IEnumerable<IPackageRepository> remoteRepositories)
        {
            var repositories = new[] { projectRepository, userRepository }.Concat(remoteRepositories);

            var packageOverrides = GetOverrides(wrapDescriptor);
            var allDependencies = ResolveAllDependencies(wrapDescriptor.Dependencies, packageOverrides, repositories);

            if (allDependencies.Any(x => x.Package == null))
                return SomeDependenciesNotFound(allDependencies);
            if (HasDependenciesConflict(allDependencies))
                allDependencies = OverrideDependenciesWithLocalDeclarations(allDependencies, wrapDescriptor.Dependencies);
            if (HasDependenciesConflict(allDependencies))
                return ConflictingDependencies(allDependencies);

            return Successful(allDependencies);
        }
        public WrapDescriptor ParseFile(string filePath, Stream content)
        {
            var stringReader = new StreamReader(content, true);
            string[] lines = SplitAndFold(stringReader.ReadToEnd());

            var descriptor = new WrapDescriptor
            {
                Name = WrapNameUtility.GetName(Path.GetFileNameWithoutExtension(filePath)),
                Version = WrapNameUtility.GetVersion(Path.GetFileNameWithoutExtension(filePath)),
                Path = filePath
            };
            foreach (var line in lines)
                foreach (var parser in _lineParsers)
                    parser.Parse(line, descriptor);
            return descriptor;
        }
Exemple #11
0
 public override void ParseContent(string content, WrapDescriptor descriptor)
 {
     descriptor.IsAnchored = string.Compare(content.Trim(), "true", StringComparison.OrdinalIgnoreCase) == 0;
 }
 public override void ParseContent(string content, WrapDescriptor descriptor)
 {
     descriptor.Description = content.Trim();
 }
 public virtual void ParseContent(string content, WrapDescriptor descriptor)
 {
 }
 public void Parse(string line, WrapDescriptor descriptor)
 {
     var dependency = ParseDependency(line);
     if (dependency != null)
         descriptor.Dependencies.Add(dependency);
 }
Exemple #15
0
 Dictionary<string, string> GetOverrides(WrapDescriptor descriptor)
 {
     return new Dictionary<string, string>();
 }
Exemple #16
0
 // TODO: once zip OpenFileSystem support has been implemented, replace the WrapDescriptorParser to be able to parse the directory name, version and version header in the correct precedence order, for use in other repositories.
 void LoadDescriptor()
 {
     using(var zipStream = _wrapFile.OpenRead())
     using (var zip = new ZipFile(zipStream))
     {
         var entries = zip.Cast<ZipEntry>();
         var descriptor = entries.FirstOrDefault(x => x.Name.EndsWith(".wrapdesc"));
         if (descriptor == null)
             throw new InvalidOperationException(string.Format("The package '{0}' doesn't contain a valid .wrapdesc file.", _wrapFile.Name));
         using (var stream = zip.GetInputStream(descriptor))
             Descriptor = new WrapDescriptorParser().ParseFile(new ZipWrapperFile(zip, descriptor), stream);
         if (Descriptor.Version == null)
         {
             var versionFile = entries.SingleOrDefault(x => string.Compare(x.Name, "version", StringComparison.OrdinalIgnoreCase) == 0);
             if (versionFile == null)
             {
                 Descriptor.Version = WrapNameUtility.GetVersion(this._wrapFile.NameWithoutExtension);
             }
             else
             {
                 using (var versionStream = zip.GetInputStream(versionFile))
                     Descriptor.Version = new Version(versionStream.ReadString(Encoding.UTF8));
             }
         }
         if (Descriptor.Version == null)
             throw new InvalidOperationException("The pacakge '{0}' doesn't have a valid version, looked in the 'wrapdesc' file, in 'version' and in the package file-name.");
     }
 }
Exemple #17
0
        IEnumerable<ICommandResult> UpdateUserPackages()
        {
            var installedPackages = Environment.UserRepository.PackagesByName.Select(x => x.Key);

            var packagesToSearch = new WrapDescriptor
            {
                Dependencies = (from package in installedPackages
                               let maxVersion = Environment.UserRepository.PackagesByName[package]
                                .OrderByDescending(x=>x.Version)
                                .Select(x=>x.Version)
                                .First()
                                select new WrapDependency
                {
                    Name = package,
                    VersionVertices = { new GreaterThenVersionVertice(maxVersion) }
                }).ToList()
            };
            yield return new Result("Searching for updated packages");
            var resolveResult = PackageManager.TryResolveDependencies(packagesToSearch, null, null, Environment.RemoteRepositories);

            foreach(var packageToUpdate in resolveResult.Dependencies)
            {
                yield return new Result("Copying {0} to user repository.", packageToUpdate.Package.FullName);
                using (var stream = packageToUpdate.Package.Load().OpenStream())
                    Environment.UserRepository.Publish(packageToUpdate.Package.FullName, stream);
            }
        }
        public WrapDescriptor ParseFile(IFile filePath, Stream content)
        {
            var stringReader = new StreamReader(content, true);
            var lines = stringReader.ReadToEnd().GetUnfoldedLines();
            IFile versionFile;
            if (filePath.Parent != null && (versionFile = filePath.Parent.GetFile("version")).Exists)
            {
                using(var versionStream = versionFile.OpenRead())
                lines.Concat(new[] { "version: " } + versionStream.ReadString(Encoding.UTF8));
            }
            var descriptor = new WrapDescriptor
            {
                Name = WrapNameUtility.GetName(filePath.NameWithoutExtension),
                Version = WrapNameUtility.GetVersion(filePath.NameWithoutExtension),
                File = filePath
            };
            foreach (var line in lines)
                foreach (var parser in _lineParsers)
                    parser.Parse(line, descriptor);

            return descriptor;
        }
 public static WrapDescriptor ParseDependsInstruction(string line)
 {
     WrapDescriptor descriptor = new WrapDescriptor();
     new DependsParser().Parse(line, descriptor);
     return descriptor;
 }
 public override void ParseContent(string content, WrapDescriptor descriptor)
 {
     var dependency = ParseDependency(content);
     if (dependency != null)
         descriptor.Dependencies.Add(dependency);
 }
 public override void ParseContent(string content, WrapDescriptor descriptor)
 {
     descriptor.Version = new Version(content);
 }