Exemplo n.º 1
0
 protected override IEnumerable <string> WriteContent(PackageDescriptor descriptor)
 {
     foreach (var dependency in descriptor.Dependencies)
     {
         yield return(dependency.ToString());
     }
 }
Exemplo n.º 2
0
        public IEnumerable <KeyValuePair <string, bool?> > ExecuteAllTests(ExecutionEnvironment environment, IPackage package)
        {
            var descriptor = new PackageDescriptor();

            descriptor.Dependencies.Add(new PackageDependencyBuilder(Guid.NewGuid().ToString()).Name(package.Name).VersionVertex(new EqualVersionVertex(package.Version)));

            var allAssemblyReferences = _manager.GetProjectAssemblyReferences(descriptor, package.Source, environment, false);

            var runners = _factories.SelectMany(x => x.GetTestRunners(allAssemblyReferences)).NotNull();

            var tests = new DefaultAssemblyExporter("tests").Items <Exports.IAssembly>(package, environment);

            if (tests == null)
            {
                return(Enumerable.Empty <KeyValuePair <string, bool?> >());
            }

            var testAssemblies = from item in tests.SelectMany(x => x)
                                 where item.File.Extension.Equals(".dll")
                                 select item.File.Path.FullPath;

            return(from runner in runners
                   from asm in testAssemblies
                   from result in runner.ExecuteTests(allAssemblyReferences.Select(x => x.File.Path.FullPath).ToList(), testAssemblies)
                   select result);
        }
 public void Parse(string line, PackageDescriptor descriptor)
 {
     var match = _regex.Match(line);
     if (!match.Success)
         return;
     ParseContent(match.Groups["content"].Value, descriptor);
 }
Exemplo n.º 4
0
        IEnumerable <ICommandOutput> Package()
        {
            var packageName = Name ?? _environment.Descriptor.Name;

            var currentPackageDescriptor      = GetCurrentPackageDescriptor();
            var packageDescriptorForEmbedding = new PackageDescriptor(currentPackageDescriptor);

            packageDescriptorForEmbedding.SemanticVersion = _generatedVersion;
            packageDescriptorForEmbedding.Name            = packageName;

#pragma warning disable 612,618
            if (currentPackageDescriptor.IncludeLegacyVersion)
            {
                packageDescriptorForEmbedding.Version = _generatedVersion.ToVersion();
            }
#pragma warning restore 612,618

            var packageFilePath = _destinationPath.GetFile(
                PackageNameUtility.PackageFileName(packageName, _generatedVersion.ToString()));

            var packageContent = GeneratePackageContent(_buildResults)
                                 .Concat(
                GenerateVersionFile(_generatedVersion),
                GenerateDescriptorFile(packageDescriptorForEmbedding)
                ).ToList();
            foreach (var item in packageContent)
            {
                yield return(new Info(string.Format("Copying: {0}/{1}{2}", item.RelativePath, item.FileName, FormatBytes(item.Size))));
            }

            Packager.NewFromFiles(packageFilePath, packageContent);
            yield return(new PackageBuilt(packageFilePath, _generatedVersion));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Extracts the Package Descriptor values from the provided string (contents of the physical file).
        /// </summary>
        /// <param name="content">
        /// The content of the physical Package Descriptor file.
        /// </param>
        /// <returns>
        /// A populated PackageDescriptor object.
        /// </returns>
        public PackageDescriptor ExtractPackageDescriptor(string content)
        {
            MatchCollection packageCategoryMatches    = this.ExecuteExpression(Expressions.PackageCategory, content);
            MatchCollection packageDescriptionMatches = this.ExecuteExpression(Expressions.PackageDescription, content);
            MatchCollection packageForumUrlMatches    = this.ExecuteExpression(Expressions.PackageForumUrl, content);
            MatchCollection packageHomepageUrlMatches = this.ExecuteExpression(Expressions.PackageHomepageUrl, content);
            MatchCollection packageIdMatches          = this.ExecuteExpression(Expressions.PackageId, content);
            MatchCollection packageNameMatches        = this.ExecuteExpression(Expressions.PackageName, content);
            MatchCollection packageNotesMatches       = this.ExecuteExpression(Expressions.PackageNotes, content);
            MatchCollection packageVersionMatches     = this.ExecuteExpression(Expressions.PackageVersion, content);

            var packageDescriptor = new PackageDescriptor
            {
                Category    = this.GetMatch(packageCategoryMatches, "category"),
                Description = this.GetMatch(packageDescriptionMatches, "description"),
                ForumUrl    = this.GetMatch(packageForumUrlMatches, "forumurl"),
                HomePageUrl = this.GetMatch(packageHomepageUrlMatches, "homepageurl"),
                Id          = this.GetMatch(packageIdMatches, "id"),
                Name        = this.GetMatch(packageNameMatches, "name"),
                Notes       = this.GetMatch(packageNotesMatches, "notes"),
                Version     = this.GetMatch(packageVersionMatches, "version"),
            };

            return(packageDescriptor);
        }
            protected void when_finding_packages(string dependency)
            {
                var dep = new PackageDescriptor();
                new DependsParser().Parse(dependency, dep);

                FoundPackage = Repository.FindAll(dep.Dependencies.First()).FirstOrDefault();
            }
Exemplo n.º 7
0
        /// <summary>
        /// GetDescriptorResourceTextFile
        /// </summary>
        /// <param name="bundleDllPath"></param>
        /// <returns></returns>
        public static PackageDescriptor LoadPackageDescriptorFromDll(string bundleDllPath)
        {
            try
            {
                var assemblyName = Path.GetFileNameWithoutExtension(bundleDllPath);
                var routePath    = string.Format("{0}.property.descriptor.xml", assemblyName);

                var assembly = Assembly.LoadFile(bundleDllPath);
                using (var stream = assembly.GetManifestResourceStream(routePath))
                {
                    if (stream == null)
                    {
                        return(null);
                    }

                    using (var sr = new StreamReader(stream))
                    {
                        var data = sr.ReadToEnd();
                        var obj  = new PackageDescriptor(data);
                        Console.WriteLine(" version: [{0}], friendly-name: [{1}]", obj.ModelVersion, obj.Name);
                        return(obj);
                    }
                }
            }
            catch (Exception exception)
            {
                throw new SynapseException(string.Format("[LoadPackageDescriptorFromDll_Error] - {0}", bundleDllPath), exception);
            }
        }
Exemplo n.º 8
0
        IEnumerable <ICommandOutput> CopyOpenWrap(PackageDescriptor projectDescriptor, IDirectory projectDirectory)
        {
            var packageManager = ServiceLocator.GetService <IPackageManager>();

            var repositoryOptions = FolderRepositoryOptions.AnchoringEnabled;

            if (projectDescriptor.UseSymLinks)
            {
                repositoryOptions |= FolderRepositoryOptions.UseSymLinks;
            }
            if (projectDescriptor.StorePackages)
            {
                repositoryOptions |= FolderRepositoryOptions.PersistPackages;
            }
            var projectRepository = new FolderRepository(projectDirectory.GetDirectory("wraps"), repositoryOptions)
            {
                Name = "Project repository"
            };

            packageManager.AddProjectPackage(PackageRequest.Any("openwrap"),
                                             new[] { Environment.SystemRepository },
                                             projectDescriptor,
                                             projectRepository,
                                             PackageAddOptions.Default | PackageAddOptions.Anchor | PackageAddOptions.Content).ToList();

            yield return(new Info("Project repository initialized."));
        }
Exemplo n.º 9
0
        private bool ValidatePackageDescriptor(PackageDescriptor packageDescriptor)
        {
            string newVersion;

            if (!VersionStringHelper.ValidateVersion(packageDescriptor.PackageVersion, out newVersion))
            {
                Log.LogWarning("PackageServerFacade",
                               $"The package '{packageDescriptor.Name}' ({packageDescriptor.Id}) did not validate and is skipped");
                return(false);
            }

            packageDescriptor.PackageVersion = newVersion;

            if (!VersionStringHelper.ValidateVersion(packageDescriptor.MinCompositeVersionSupported, out newVersion))
            {
                Log.LogWarning("PackageServerFacade",
                               $"The package '{packageDescriptor.Name}' ({packageDescriptor.Id}) did not validate and is skipped");
                return(false);
            }

            packageDescriptor.MinCompositeVersionSupported = newVersion;

            if (!VersionStringHelper.ValidateVersion(packageDescriptor.MaxCompositeVersionSupported, out newVersion))
            {
                Log.LogWarning("PackageServerFacade",
                               $"The package '{packageDescriptor.Name}' ({packageDescriptor.Id}) did not validate and is skipped");
                return(false);
            }

            packageDescriptor.MaxCompositeVersionSupported = newVersion;

            return(true);
        }
Exemplo n.º 10
0
 public void PackAllBinaries(PackageDescriptor desc)
 {
     using (var p = new Package(desc.Path, this.f.ParentPath)) {
         p.Add(q.files("^/dlls/release/*.(dll|pdb)$"), "/", "dlls/release");
         p.Add(q.files("^/[^/]+.txt$"));
     }
 }
        public Package GetPackage()
        {
            var packageId = PackageId.Create(GetStringId());
            IPackageDescriptor iPackageDescriptor = new PackageDescriptor();

            return(Package.Create(packageId, GetAbsolutePath(), iPackageDescriptor));
        }
Exemplo n.º 12
0
        public void given_dependency(string dependencyLine)
        {
            var target = new PackageDescriptor();

            ((IPackageDescriptor)target).Dependencies.Add(DependsParser.ParseDependsLine(dependencyLine));
            Declaration = target.Dependencies.First();
        }
Exemplo n.º 13
0
        static PackageContent ConvertSpecification(ZipFile file, ZipEntry entry)
        {
            var inputStream = file.GetInputStream(entry);

            var nuspec = new XmlDocument();

            nuspec.Load(inputStream);

            PackageDescriptor descriptor = NuConverter.ConvertSpecificationToDescriptor(nuspec);
            var memoryStream             = new MemoryStream();

            new PackageDescriptorWriter().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;
                }
            });
        }
Exemplo n.º 14
0
 void WriteDescriptor(IFile descriptor, PackageDescriptor packageDescriptor)
 {
     using (Stream descriptorStream = descriptor.OpenWrite())
     {
         new PackageDescriptorReaderWriter().Write(packageDescriptor, descriptorStream);
     }
 }
Exemplo n.º 15
0
        private Task <IPackage> GetPackage2 <T>(PackageDescriptor descriptor)
            where T : class, IPackage
        {
            return(_packages2.GetOrAdd(descriptor, async descriptor2 =>
            {
                foreach (var packageFinder in _packageFinders)
                {
                    var package = await packageFinder.Find <IPackage>(descriptor);
                    if (package != null)
                    {
                        if (package is Package2 package2)
                        {
                            var packageAsset = package2.Assets.OfType <T>().FirstOrDefault();
                            if (packageAsset != null)
                            {
                                return packageAsset;
                            }
                        }
                    }
                    if (package is T pkg)
                    {
                        return pkg;
                    }
                }

                return default;
            }));
        }
Exemplo n.º 16
0
        IEnumerable <ICommandOutput> Build()
        {
            var packageName     = Name ?? _environment.Descriptor.Name;
            var destinationPath = _destinationPath ?? _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;

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

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

            foreach (var item in packageContent)
            {
                yield return(new GenericMessage(string.Format("Copying: {0}/{1}{2}", item.RelativePath, item.FileName, FormatBytes(item.Size))));
            }

            Packager.NewFromFiles(packageFilePath, packageContent);
            yield return(new GenericMessage(string.Format("Package built at '{0}'.", packageFilePath)));
        }
Exemplo n.º 17
0
        public static PackageDescriptor ParseDependsInstruction(string line)
        {
            var descriptor = new PackageDescriptor();

            new DependsParser().Parse(line, descriptor);
            return(descriptor);
        }
Exemplo n.º 18
0
            public void given_dependency(string dependencyLine)
            {
                var target = new PackageDescriptor();

                new DependsParser().Parse(dependencyLine, target);
                Declaration = target.Dependencies.First();
            }
            protected void when_finding_packages(string dependency)
            {
                var dep = new PackageDescriptor();
                ((IPackageDescriptor)dep).Dependencies.Add(DependsParser.ParseDependsLine(dependency));

                FoundPackage = Repository.PackagesByName.FindAll(dep.Dependencies.First()).FirstOrDefault();
            }
            protected void when_finding_packages(string dependency)
            {
                var dep = new PackageDescriptor();

                new DependsParser().Parse(dependency, dep);

                FoundPackage = Repository.FindAll(dep.Dependencies.First()).FirstOrDefault();
            }
            protected void when_finding_packages(string dependency)
            {
                var dep = new PackageDescriptor();

                ((IPackageDescriptor)dep).Dependencies.Add(DependsParser.ParseDependsLine(dependency));

                FoundPackage = Repository.PackagesByName.FindAll(dep.Dependencies.First()).FirstOrDefault();
            }
Exemplo n.º 22
0
 public static IEnumerable<IAssemblyReferenceExportItem> GetAssemblyReferences(this IPackageResolver resolver,
     bool includeContentOnly,
     ExecutionEnvironment exec,
     PackageDescriptor descriptor,
     params IPackageRepository[] repositories)
 {
     return GetAssemblyReferences(resolver.TryResolveDependencies(descriptor, repositories), exec, includeContentOnly);
 }
Exemplo n.º 23
0
        private Package CreatePackage(string version)
        {
            AbsolutePath path    = AbsolutePath.Create(m_context.PathTable, TemporaryDirectory + $"\\random.package.name\\{version}\\nu.spec");
            var          pathStr = path.ToString(m_context.PathTable);
            var          id      = PackageId.Create(StringId.Create(m_context.StringTable, pathStr));
            var          desc    = new PackageDescriptor();

            return(Package.Create(id, path, desc));
        }
Exemplo n.º 24
0
 public DefaultPackageInfo(string packageFileName, Version versionFileContent, PackageDescriptor descriptor)
 {
     _descriptor = descriptor;
     _packageVersion = versionFileContent
                       ?? descriptor.Version
                       ?? PackageNameUtility.GetVersion(packageFileName);
     _packageName = PackageNameUtility.GetName(packageFileName);
     Identifier = new PackageIdentifier(Name, Version);
 }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
0
        public IPackageCleanResult CleanProjectPackages(PackageDescriptor packages, IPackageRepository projectRepository, string name, PackageCleanOptions options = PackageCleanOptions.Default)
        {
            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 new PackageCleanResultIterator(CleanProjectPackagesCore(packages, repoForClean, x => name.EqualsNoCase(x)));
        }
Exemplo n.º 27
0
        public IEnumerable <string> Write(PackageDescriptor descriptor)
        {
            var content = WriteContent(descriptor).ToList();

            if (content.Count == 0)
            {
                return(content);
            }
            return(content.Select(x => Header + ": " + x));
        }
 public static IPackageDescriptor Lock(this IPackageDescriptor descriptor, IPackageRepository repository, string scope = null)
 {
     scope = scope ?? string.Empty;
     var lockedRepo = repository.Feature<ISupportLocking>();
     if (lockedRepo == null)
         return descriptor;
     var lockedDescriptor = new PackageDescriptor(descriptor);
     var lockedPackages = lockedRepo.LockedPackages[scope];
     return Lock(lockedDescriptor, lockedPackages);
 }
Exemplo n.º 29
0
        protected static Package ReadPackage(BuildXLReader reader, PathTable pathTable)
        {
            var id         = ReadPackageId(reader);
            var path       = reader.ReadAbsolutePath();
            var descriptor = new PackageDescriptor()
            {
                Name = id.Name.ToString(pathTable.StringTable),
            };

            return(Package.Create(id, path, descriptor));
        }
        public void Write(PackageDescriptor descriptor, Stream descriptorStream)
        {
            var streamWriter = new StreamWriter(descriptorStream, Encoding.UTF8);
            var lines = from parser in _lineParsers
                        from parserLine in parser.Write(descriptor)
                        select parserLine;

            var content = lines.Join("\r\n");
            streamWriter.Write(content);
            streamWriter.Flush();
        }
Exemplo n.º 31
0
 public void PackMin(PackageDescriptor desc)
 {
     // 'min' - /dlls/release/ImageResizer.* - /
     // /*.txt
     using (var p = new Package(desc.Path, this.f.ParentPath)) {
         p.Add(q.files("^/dlls/release/ImageResizer.(Mvc.)?(dll|pdb|xml)$"), "/", "dlls/release");
         p.Add(q.files("^/readme.txt$"));
         p.Add(q.files("^/Core/license.txt$"), "");
         p.Add(q.files("^/Web.config$"));
     }
 }
Exemplo n.º 32
0
 public PackageInfo(PackageDescriptor descriptor, string packagePath,
                    IEnumerable <string> filePaths)
 {
     Descriptor  = descriptor;
     PackagePath = packagePath;
     FilePaths   = filePaths;
     if (PackageVersion.TryParseVersion(descriptor.PackageVersion, out PackageVersion version))
     {
         Version = version;
     }
 }
Exemplo n.º 33
0
 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 Read(Stream content)
        {
            var stringReader = new StreamReader(content, true);
            var lines = stringReader.ReadToEnd().GetUnfoldedLines();

            var descriptor = new PackageDescriptor();
            foreach (var line in lines)
                foreach (var parser in _lineParsers)
                    parser.Parse(line, descriptor);

            return descriptor;
        }
Exemplo n.º 35
0
 static 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
     };
 }
Exemplo n.º 36
0
 public dependency_resolver_context()
 {
     DependencyDescriptor = new PackageDescriptor
     {
         Name            = "test",
         SemanticVersion = "1.0".ToSemVer()
     };
     ProjectRepository          = new InMemoryRepository("Local repository");
     SystemRepository           = new InMemoryRepository("System repository");
     RemoteRepository           = new InMemoryRepository("Remote repository");
     CurrentDirectoryRepository = new InMemoryRepository("Current repository");
 }
 public dependency_resolver_context()
 {
     DependencyDescriptor = new PackageDescriptor
     {
             Name = "test",
             SemanticVersion = "1.0".ToSemVer()
     };
     ProjectRepository = new InMemoryRepository("Local repository");
     SystemRepository = new InMemoryRepository("System repository");
     RemoteRepository = new InMemoryRepository("Remote repository");
     CurrentDirectoryRepository = new InMemoryRepository("Current repository");
 }
Exemplo n.º 38
0
        private async Task <IPackage> GetPackage2 <T>(PackageDescriptor descriptor)
            where T : class, IPackage
        {
            foreach (var packgeFinder in _packageFinders)
            {
                if (await packgeFinder.Find <T>(descriptor) is T pkg)
                {
                    return(pkg);
                }
            }

            return(default);
Exemplo n.º 39
0
        IEnumerable <PackageOperationResult> CopyPackageCore(IEnumerable <IPackageRepository> sourceRepositories,
                                                             IEnumerable <IPackageRepository> destinationRepositories,
                                                             IPackageDescriptor 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 = GetSelectedPackages(resolvedPackages);

            foreach (var conflict in from errors in _exporter.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);
            }
        }
Exemplo n.º 40
0
 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").MustExist();
     Descriptor = new PackageDescriptor();
     ConfigurationDirectory = configDirectory;
     ScopedDescriptors = new Dictionary<string, FileBased<IPackageDescriptor>>(StringComparer.OrdinalIgnoreCase);
     ScopedDescriptors[string.Empty] = FileBased.New(DescriptorFile, Descriptor);
 }
Exemplo n.º 41
0
        public IPackageAddResult 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 new PackageAddResultIterator(AddProjectPackageCore(packageToAdd, sourceRepositories, projectDescriptor, projectRepository, options));
        }
Exemplo n.º 42
0
        static PackageContent GenerateDescriptorFile(PackageDescriptor descriptor)
        {
            var descriptorStream = new MemoryStream();

            new PackageDescriptorWriter().Write(descriptor.GetPersistableEntries(), descriptorStream);
            return(new PackageContent
            {
                FileName = descriptor.Name + ".wrapdesc",
                RelativePath = ".",
                Stream = descriptorStream.ResetOnRead(),
                Size = descriptorStream.Length
            });
        }
Exemplo n.º 43
0
        /// <nodoc/>
        protected Package CreateDummyPackageFromPath(AbsolutePath path)
        {
            Contract.Requires(path.IsValid);

            var pathStr = path.ToString(Context.PathTable);
            var id      = PackageId.Create(StringId.Create(Context.StringTable, pathStr));
            var desc    = new PackageDescriptor
            {
                Name = path.ToString(Context.PathTable),
            };

            return(Package.Create(id, path, desc));
        }
Exemplo n.º 44
0
 public InMemoryEnvironment(IDirectory currentDirectory, IDirectory configDirectory = null)
 {
     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").MustExist();
     Descriptor                      = new PackageDescriptor();
     ConfigurationDirectory          = configDirectory;
     ScopedDescriptors               = new Dictionary <string, FileBased <IPackageDescriptor> >(StringComparer.OrdinalIgnoreCase);
     ScopedDescriptors[string.Empty] = FileBased.New(DescriptorFile, Descriptor);
     ExecutionEnvironment            = new ExecutionEnvironment("AnyCPU", "net35");
 }
Exemplo n.º 45
0
 /// <summary>
 /// Retrieves a suitable package to put a certain type into.
 /// </summary>
 /// <param name="type">type for which a suitable package is desired</param>
 /// <returns>suitable package</returns>
 public PackageDescriptor GetPackage(Type type)
 {
     string pkgName = type.Namespace;
     if (pkgName == null)
         pkgName = "DefaultPackage";
     PackageDescriptor pd;
     if (!_pkgMap.TryGetValue(pkgName, out pd))
     {
         pd = new PackageDescriptor(pkgName);
     }
     _pkgMap[pkgName] = pd;
     _design.AddChild(pd, pd.Name);
     return pd;
 }
Exemplo n.º 46
0
        public IEnumerable<KeyValuePair<string, bool?>> ExecuteAllTests(ExecutionEnvironment environment, IPackage package)
        {
            var descriptor = new PackageDescriptor();
            descriptor.Dependencies.Add(new PackageDependencyBuilder(Guid.NewGuid().ToString()).Name(package.Name).VersionVertex(new EqualVersionVertex(package.Version)));

            var allAssemblyReferences = _manager.GetProjectAssemblyReferences(descriptor, package.Source, environment, false);

            var runners = _factories.SelectMany(x => x.GetTestRunners(allAssemblyReferences)).NotNull();

            var tests = new DefaultAssemblyExporter("tests").Items<Exports.IAssembly>(package, environment);

            if (tests == null) return Enumerable.Empty<KeyValuePair<string, bool?>>();

            var testAssemblies = from item in tests.SelectMany(x=>x)
                                 where item.File.Extension.Equals(".dll")
                                 select item.File.Path.FullPath;
            return from runner in runners
                   from asm in testAssemblies
                   from result in runner.ExecuteTests(allAssemblyReferences.Select(x => x.File.Path.FullPath).ToList(), testAssemblies)
                   select result;
        }
Exemplo n.º 47
0
        public IEnumerable<KeyValuePair<string, bool?>> ExecuteAllTests(ExecutionEnvironment environment, IPackage package)
        {
            var descriptor = new PackageDescriptor();
            descriptor.Dependencies.Add(new PackageDependencyBuilder(Guid.NewGuid().ToString()).Name(package.Name).VersionVertex(new EqualVersionVertex(package.Version)));

            var allAssemblyReferences = _resolver.GetAssemblyReferences(false, environment, descriptor, package.Source, _environment.ProjectRepository, _environment.SystemRepository);

            var runners = _factories.SelectMany(x=>x.GetTestRunners(allAssemblyReferences)).NotNull();

            var export = package.GetExport("tests", environment);

            if (export == null) return Enumerable.Empty<KeyValuePair<string, bool?>>();

            var testAssemblies = from item in export.Items
                                 where item.FullPath.EndsWithNoCase(".dll")
                                 select item.FullPath;
            return from runner in runners
                   from asm in testAssemblies
                   from result in runner.ExecuteTests(allAssemblyReferences.Select(x => x.FullPath).ToList(), testAssemblies)
                   select result;
        }
Exemplo n.º 48
0
 public UncompressedPackage(IPackageRepository source,
     IFile originalPackageFile,
     IDirectory wrapCacheDirectory,
     IEnumerable<IExportBuilder> exporters)
 {
     _originalPackageFile = originalPackageFile;
     _exporters = exporters;
     BaseDirectory = wrapCacheDirectory;
     // get the descriptor file inside the package
     var descriptorName = originalPackageFile.NameWithoutExtension;
     Source = source;
     var wrapDescriptor = wrapCacheDirectory.Files("*.wrapdesc").SingleOrDefault();
     if (wrapDescriptor == null)
         throw new InvalidOperationException("Could not find descriptor in wrap cache directory, or there are multiple .wrapdesc files in the package.");
     var versionFile = wrapCacheDirectory.GetFile("version");
     _descriptor = new PackageDescriptorReaderWriter().Read(wrapDescriptor);
     PackageInfo = new DefaultPackageInfo(originalPackageFile.Name,
                                         versionFile.Exists ? versionFile.Read(x => x.ReadString().ToVersion()) : null,
                                         _descriptor);
     Identifier = new PackageIdentifier(Name, Version);
 }
Exemplo n.º 49
0
        protected override IEnumerable<ICommandOutput> ExecuteCore()
        {
            _targetDescriptor = HostEnvironment.GetOrCreateScopedDescriptor(Scope ?? string.Empty);

            yield return VerifyDescriptor(_targetDescriptor);
            yield return VerifyProjectRepository();

            yield return SetupEnvironmentForAdd();
            var sourceRepositories = GetSourceRepositories().ToList();

            var descriptor = new PackageDescriptor(_targetDescriptor.Value);
            if (Project && System)
            {
                var sysToAdd = new List<PackageIdentifier>();
                using (SaveDescriptorOnSuccess(_targetDescriptor))
                {
                    foreach (var m in AddProjectPackage(descriptor, sourceRepositories))
                    {
                        yield return ToOutput(m);
                        ParseSuccess(m, sysToAdd.Add);
                    }
                    foreach (var identifier in sysToAdd)
                        foreach (var m in PackageManager.AddSystemPackage(PackageRequest.Exact(identifier.Name, identifier.Version), sourceRepositories, HostEnvironment.SystemRepository))
                            yield return ToOutput(m);
                }
            }
            else if (Project)
            {
                using (SaveDescriptorOnSuccess(_targetDescriptor))
                {
                    foreach (var m in AddProjectPackage(descriptor, sourceRepositories))
                    {
                        yield return ToOutput(m);
                    }
                }
            }
            else if (System)
            {
                foreach (var m in PackageManager.AddSystemPackage(PackageRequest, sourceRepositories, HostEnvironment.SystemRepository, AddOptions))
                {
                    yield return ToOutput(m);
                }
            }

            if (_packageNotFound)
            {
                var hit = false;
                foreach (var m in PackageManager.ListPackages(sourceRepositories, Name))
                {
                    if (!hit)
                    {
                        yield return new Info("Did you mean one of the following packages?", Name);
                        hit = true;
                    }
                    yield return ToOutput(m);
                }
            }
        }
Exemplo n.º 50
0
 void WriteDescriptor(IFile descriptor, PackageDescriptor packageDescriptor)
 {
     using (Stream descriptorStream = descriptor.OpenWrite())
     {
         new PackageDescriptorReaderWriter().Write(packageDescriptor, descriptorStream);
     }
 }
Exemplo n.º 51
0
        IEnumerable<ICommandOutput> Package()
        {
            var packageName = Name ?? _environment.Descriptor.Name;

            var currentPackageDescriptor = GetCurrentPackageDescriptor();
            var packageDescriptorForEmbedding = new PackageDescriptor(currentPackageDescriptor);

            packageDescriptorForEmbedding.SemanticVersion = _generatedVersion;
            packageDescriptorForEmbedding.Name = packageName;

            #pragma warning disable 612,618
            if (currentPackageDescriptor.IncludeLegacyVersion)
                packageDescriptorForEmbedding.Version = _generatedVersion.ToVersion();
            #pragma warning restore 612,618

            var packageFilePath = _destinationPath.GetFile(
                PackageNameUtility.PackageFileName(packageName, _generatedVersion.ToString()));

            var packageContent = GeneratePackageContent(_buildResults)
                .Concat(
                    GenerateVersionFile(_generatedVersion),
                    GenerateDescriptorFile(packageDescriptorForEmbedding)
                ).ToList();
            foreach (var item in packageContent)
                yield return new Info(string.Format("Copying: {0}/{1}{2}", item.RelativePath, item.FileName, FormatBytes(item.Size)));

            Packager.NewFromFiles(packageFilePath, packageContent);
            yield return new PackageBuilt(packageFilePath, _generatedVersion);
        }
Exemplo n.º 52
0
 internal void Nest(PackageDescriptor owner)
 {
     owner.AddChild(this);
     Owner = owner;
 }
Exemplo n.º 53
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;
        }
Exemplo n.º 54
0
        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;

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

            var packageContent = GeneratePackageContent(_buildResults).Concat(
                                    GenerateVersionFile(generatedVersion),
                                    GenerateDescriptorFile(packageDescriptorForEmbedding)
                                 ).ToList();
            foreach (var item in packageContent)
                yield return new GenericMessage(string.Format("Copying: {0}/{1}{2}", item.RelativePath, item.FileName, FormatBytes(item.Size)));

            Packager.NewFromFiles(packageFilePath, packageContent);
            yield return new GenericMessage(string.Format("Package built at '{0}'.", packageFilePath));
        }
Exemplo n.º 55
0
 public InMemoryPackage()
 {
     Created = DateTime.Now;
     Dependencies = new List<PackageDependency>();
     Descriptor = new PackageDescriptor();
 }
Exemplo n.º 56
0
 protected void given_descriptor(params string[] lines)
 {
     Descriptor = new PackageDescriptorReaderWriter().Read(new MemoryStream(Encoding.UTF8.GetBytes(string.Join("\r\n", lines))));
 }
 public dependency_manager_context()
 {
     DependencyDescriptor = new PackageDescriptor
     {
         Name = "test",
         Version = new Version("1.0")
     };
     ProjectRepository = new InMemoryRepository("Local repository");
     SystemRepository = new InMemoryRepository("System repository");
     RemoteRepository = new InMemoryRepository("Remote repository");
 }
 public IEnumerable<string> Write(PackageDescriptor descriptor)
 {
     var content = WriteContent(descriptor).ToList();
     if (content.Count == 0) return content;
     return content.Select(x => Header + ": " + x);
 }
 protected abstract void ParseContent(string content, PackageDescriptor descriptor);
 protected abstract IEnumerable<string> WriteContent(PackageDescriptor descriptor);