Пример #1
0
        private InstalledPackage UseFilesFromUnpackedSourceWithMetadata(string metadataFile, PackageRequest request, FileSyncer binFileSyncer)
        {
            var properties = new SimplePropertyProvider
            {
                { "Configuration", "Debug" },
            };
            var packageBuilder = new PackageBuilder(metadataFile, properties, includeEmptyDirectories: false);

            var sourceFolder = Path.GetDirectoryName(metadataFile);
            var targetFolder = GetTargetFolder(packageBuilder.Id, packageBuilder.Version.ToString());

            // Copy binary files and resources:

            foreach (PhysicalPackageFile file in FilterCompatibleLibFiles(packageBuilder.Files))
            {
                binFileSyncer.AddFile(file.SourcePath, Paths.PluginsFolder, Path.Combine(Paths.PluginsFolder, file.EffectivePath));
            }

            foreach (PhysicalPackageFile file in packageBuilder.Files)
            {
                if (file.Path.StartsWith(@"Plugins\")) // Obsolete bin folder; lib should be used instead.
                {
                    binFileSyncer.AddFile(file.SourcePath, Paths.PluginsFolder);
                }
                else if (file.Path.StartsWith(@"Resources\"))
                {
                    binFileSyncer.AddFile(file.SourcePath, Paths.ResourcesFolder, Path.Combine(SimplifyPackageName(packageBuilder.Id), file.Path.Substring(@"Resources\".Length)));
                }
            }

            return(new InstalledPackage(packageBuilder.Id, packageBuilder.Version.ToString(), GetNuGetPackageDependencies(packageBuilder),
                                        sourceFolder, request, sourceFolder));
        }
Пример #2
0
        private InstalledPackage UseFilesFromUnpackedSourceWithMetadata(string metadataFile, PackageRequest request, FileSyncer binFileSyncer)
        {
            var properties = new SimplePropertyProvider
            {
                { "Configuration", "Debug" },
            };
            var packageBuilder = new PackageBuilder(metadataFile, properties, includeEmptyDirectories: false);

            string sourceFolder = Path.GetDirectoryName(metadataFile);

            // Copy binary files:

            foreach (var file in FilterCompatibleLibFiles(packageBuilder.Files).Cast <PhysicalPackageFile>())
            {
                binFileSyncer.AddFile(file.SourcePath, Paths.PluginsFolder, Path.Combine(Paths.PluginsFolder, file.EffectivePath));
            }

            foreach (var file in packageBuilder.Files.Cast <PhysicalPackageFile>())
            {
                if (file.Path.StartsWith(@"Plugins\")) // Obsolete bin folder; lib should be used instead.
                {
                    binFileSyncer.AddFile(file.SourcePath, Paths.PluginsFolder);
                }
            }

            var contentFiles = packageBuilder.Files.Cast <PhysicalPackageFile>()
                               .Select(file => new ContentFile {
                PhysicalPath = file.SourcePath, InPackagePath = file.Path
            })
                               .ToList();

            return(new InstalledPackage(packageBuilder.Id, packageBuilder.Version.ToString(), GetNuGetPackageDependencies(packageBuilder),
                                        sourceFolder, request, sourceFolder, contentFiles));
        }
Пример #3
0
        //================================================================
        #region Getting the package from NuGet

        private InstalledPackage TryGetPackageFromNuGet(PackageSource source, PackageRequest request, FileSyncer binFileSyncer)
        {
            var sw = Stopwatch.StartNew();

            // Find the NuGet package:

            var nugetRepository = (source.Path != null && IsLocalPath(source.Path))
                ? new LocalPackageRepository(source.Path, enableCaching: false) // When developer rebuilds a package, the package version does not need to be increased every time.
                : PackageRepositoryFactory.Default.CreateRepository(source.ProcessedLocation);
            var requestVersionsRange = !string.IsNullOrEmpty(request.VersionsRange)
                ? VersionUtility.ParseVersionSpec(request.VersionsRange)
                : new VersionSpec();
            IEnumerable <IPackage> packages = nugetRepository.FindPackages(request.Id, requestVersionsRange, allowPrereleaseVersions: true, allowUnlisted: true).ToList();

            if (requestVersionsRange.MinVersion != null && !requestVersionsRange.MinVersion.Equals(new SemanticVersion("0.0")))
            {
                packages = packages.OrderBy(p => p.Version); // Find the lowest compatible version if the version is specified (default NuGet behavior).
            }
            else
            {
                packages = packages.OrderByDescending(p => p.Version);
            }

            var package = packages.FirstOrDefault();

            _performanceLogger.Write(sw, () => "PackageDownloader find NuGet package " + request.Id + ".");

            if (package == null)
            {
                _logger.Trace("Package " + request.ReportIdVersionsRange() + " not found by NuGet at " + source.ProcessedLocation + ".");
                return(null);
            }

            // Download the NuGet package:

            _logger.Trace("Downloading NuGet package " + package.Id + " " + package.Version + " from " + source.ProcessedLocation + ".");
            var packageManager = new PackageManager(nugetRepository, Paths.PackagesFolder)
            {
                Logger = new LoggerForNuget(_logProvider)
            };

            packageManager.LocalRepository.PackageSaveMode = PackageSaveModes.Nuspec;

            packageManager.InstallPackage(package, ignoreDependencies: true, allowPrereleaseVersions: true);
            _performanceLogger.Write(sw, () => "PackageDownloader install NuGet package " + request.Id + ".");

            string targetFolder = packageManager.PathResolver.GetInstallPath(package);

            // Copy binary files and resources:

            foreach (var file in FilterCompatibleLibFiles(package.GetFiles()))
            {
                binFileSyncer.AddFile(Path.Combine(targetFolder, file.Path), Paths.PluginsFolder);
            }

            binFileSyncer.AddFolderContent(Path.Combine(targetFolder, "Plugins"), Paths.PluginsFolder, recursive: false); // Obsolete bin folder; lib should be used instead.
            binFileSyncer.AddFolderContent(Path.Combine(targetFolder, "Resources"), Paths.ResourcesFolder, SimplifyPackageName(package.Id), recursive: true);

            return(new InstalledPackage(package.Id, package.Version.ToString(), GetNuGetPackageDependencies(package), targetFolder, request, source.ProcessedLocation));
        }
        private void CopyResourcesFromPackages()
        {
            var stopwatch   = Stopwatch.StartNew();
            var _fileSyncer = new FileSyncer(_logProvider);

            _fileSyncer.AddDestinations(_rhetosBuildEnvironment.GeneratedAssetsFolder); // Even if there are no packages, the old folder content must be emptied.

            string ResourcesPathPrefix = "Resources" + Path.DirectorySeparatorChar;
            string HostApplicationResourcesPathPrefix = ResourcesPathPrefix + "Rhetos" + Path.DirectorySeparatorChar;

            var resourceFiles = _installedPackages.Packages
                                .SelectMany(package => package.ContentFiles
                                            .Where(file => file.InPackagePath.StartsWith(ResourcesPathPrefix))
                                            .Where(file => !file.PhysicalPath.StartsWith(_rhetosBuildEnvironment.ProjectFolder)) // Prevent from including the generated output folder as in input.
                                            .Select(file => new
            {
                Package = package,
                Source  = file.PhysicalPath,
                Target  = Path.Combine(SimplifyPackageName(package.Id), file.InPackagePath.Substring(ResourcesPathPrefix.Length))
            }))
                                //The resource files that are used by Rhetos are located in the Resources folder of a NuGet package.
                                //We also want to add the possibility that a Rhetos resource file can be added in the current project by the application developer.
                                //The Resources folder can be used as in any other NuGet Rhetos package but this way unwanted files could be copied in the RhetosAssets folder
                                //because the Resources folder in a project is usually used to store other resource files.
                                .Union(_installedPackages.Packages
                                       .SelectMany(package => package.ContentFiles
                                                   .Where(file => file.PhysicalPath.StartsWith(_rhetosBuildEnvironment.ProjectFolder)) // Prevent from including the generated output folder as in input.
                                                   .Where(file => file.InPackagePath.StartsWith(HostApplicationResourcesPathPrefix))
                                                   .Select(file => new
            {
                Package = package,
                Source  = file.PhysicalPath,
                Target  = Path.Combine(SimplifyPackageName(package.Id), file.InPackagePath.Substring(HostApplicationResourcesPathPrefix.Length))
            })))
                                .ToList();

            var similarPackages = resourceFiles.Select(file => file.Package).Distinct()
                                  .GroupBy(package => SimplifyPackageName(package.Id), StringComparer.OrdinalIgnoreCase)
                                  .FirstOrDefault(group => group.Count() > 1);

            if (similarPackages != null)
            {
                throw new UserException($"Incompatible package names, resource files would result in the same target folder '{similarPackages.Key}'."
                                        + $"\r\nPackage 1: {similarPackages.First().Report()}"
                                        + $"\r\nPackage 2: {similarPackages.Last().Report()}");
            }

            foreach (var file in resourceFiles)
            {
                _fileSyncer.AddFile(file.Source, _rhetosBuildEnvironment.GeneratedAssetsFolder, file.Target);
            }

            _logger.Info($"Copying {resourceFiles.Count} resource files.");
            _fileSyncer.UpdateDestination(false, false);

            _performanceLogger.Write(stopwatch, "Resources generated.");
        }
Пример #5
0
        //================================================================
        #region Getting the package from NuGet

        private InstalledPackage TryGetPackageFromNuGetCache(PackageRequest request, FileSyncer binFileSyncer)
        {
            var sw = Stopwatch.StartNew();

            // Use cache only if not deploying from source and an exact version is specified:

            if (request.Source != null)
            {
                return(null);
            }

            var requestVersionsRange = !string.IsNullOrEmpty(request.VersionsRange)
                ? VersionUtility.ParseVersionSpec(request.VersionsRange)
                : new VersionSpec();

            if (requestVersionsRange.MinVersion == null ||
                requestVersionsRange.MinVersion.Equals(new SemanticVersion("0.0")) ||
                requestVersionsRange.MinVersion != requestVersionsRange.MaxVersion)
            {
                _logger.Trace(() => $"Not looking for {request.ReportIdVersionsRange()} in packages cache because the request does not specify an exact version.");
                return(null);
            }

            // Find the NuGet package:

            var      nugetRepository = new LocalPackageRepository(Paths.PackagesCacheFolder, enableCaching: false);
            IPackage package         = nugetRepository.FindPackage(request.Id, requestVersionsRange, allowPrereleaseVersions: true, allowUnlisted: true);

            _performanceLogger.Write(sw, () => $"PackageDownloader: {(package == null ? "Did not find" : "Found")} the NuGet package {request.ReportIdVersionsRange()} in cache.");
            if (package == null)
            {
                return(null);
            }

            // Copy binary files and resources:

            string packageSubfolder = nugetRepository.PathResolver.GetPackageDirectory(request.Id, requestVersionsRange.MinVersion);

            _deployPackagesLogger.Trace(() => $"Reading package from cache '{packageSubfolder}'.");
            string targetFolder = Path.Combine(Paths.PackagesCacheFolder, packageSubfolder);

            foreach (var file in FilterCompatibleLibFiles(package.GetFiles()))
            {
                binFileSyncer.AddFile(Path.Combine(targetFolder, file.Path), Paths.PluginsFolder, Path.Combine(Paths.PluginsFolder, file.EffectivePath));
            }

            binFileSyncer.AddFolderContent(Path.Combine(targetFolder, "Plugins"), Paths.PluginsFolder, recursive: false); // Obsolete bin folder; lib should be used instead.
            binFileSyncer.AddFolderContent(Path.Combine(targetFolder, "Resources"), Paths.ResourcesFolder, SimplifyPackageName(package.Id), recursive: true);

            return(new InstalledPackage(package.Id, package.Version.ToString(), GetNuGetPackageDependencies(package), targetFolder, request, Paths.PackagesCacheFolder));
        }
Пример #6
0
        //================================================================
        #region Getting the package from NuGet

        private InstalledPackage TryGetPackageFromNuGetCache(PackageRequest request, FileSyncer binFileSyncer)
        {
            // Use cache only if not deploying from source and an exact version is specified:

            if (request.Source != null)
            {
                return(null);
            }

            var requestVersionsRange = !string.IsNullOrEmpty(request.VersionsRange)
                ? VersionUtility.ParseVersionSpec(request.VersionsRange)
                : new VersionSpec();

            // Default NuGet behavior is to download the smallest version in the given range, so only MinVersion is checked here:
            if (!SpecifiedMinVersion(requestVersionsRange))
            {
                _logger.Trace(() => $"Not looking for {request.ReportIdVersionsRange()} in packages cache because the request does not specify an exact version.");
                return(null);
            }

            // Find the NuGet package:

            var      nugetRepository = new LocalPackageRepository(_packagesCacheFolder, enableCaching: false);
            IPackage package         = nugetRepository.FindPackage(request.Id, requestVersionsRange, allowPrereleaseVersions: true, allowUnlisted: true);

            if (package == null)
            {
                _logger.Trace(() => $"Did not find NuGet package {request.ReportIdVersionsRange()} in cache.");
                return(null);
            }

            // Copy binary files:

            string packageSubfolder = nugetRepository.PathResolver.GetPackageDirectory(request.Id, package.Version);

            _logger.Trace(() => $"Reading package {request.Id} from cache '{packageSubfolder}'.");
            _logger.Info(() => $"Reading {request.Id} from cache.");
            string targetFolder = Path.Combine(_packagesCacheFolder, packageSubfolder);

            foreach (var file in FilterCompatibleLibFiles(package.GetFiles()))
            {
                binFileSyncer.AddFile(Path.Combine(targetFolder, file.Path), Paths.PluginsFolder, Path.Combine(Paths.PluginsFolder, file.EffectivePath));
            }

            binFileSyncer.AddFolderContent(Path.Combine(targetFolder, "Plugins"), Paths.PluginsFolder, recursive: false); // Obsolete bin folder; lib should be used instead.

            return(new InstalledPackage(package.Id, package.Version.ToString(), GetNuGetPackageDependencies(package), targetFolder, request, _packagesCacheFolder));
        }
Пример #7
0
        private void CopyResourcesFromPackages()
        {
            var stopwatch   = Stopwatch.StartNew();
            var _fileSyncer = new FileSyncer(_logProvider);

            _fileSyncer.AddDestinations(Paths.ResourcesFolder); // Even if there are no packages, the old folder content must be emptied.

            const string ResourcesPathPrefix = @"Resources\";

            var resourceFiles = _installedPackages.Packages
                                .SelectMany(package => package.ContentFiles
                                            .Where(file => file.InPackagePath.StartsWith(ResourcesPathPrefix))
                                            .Where(file => !file.PhysicalPath.StartsWith(Paths.ResourcesFolder)) // Prevent from including the generated output folder as in input.
                                            .Select(file => new
            {
                Package = package,
                Source  = file.PhysicalPath,
                Target  = Path.Combine(SimplifyPackageName(package.Id), file.InPackagePath.Substring(ResourcesPathPrefix.Length))
            }))
                                .ToList();

            var similarPackages = resourceFiles.Select(file => file.Package).Distinct()
                                  .GroupBy(package => SimplifyPackageName(package.Id), StringComparer.OrdinalIgnoreCase)
                                  .FirstOrDefault(group => group.Count() > 1);

            if (similarPackages != null)
            {
                throw new UserException($"Incompatible package names, resource files would result in the same target folder '{similarPackages.Key}'."
                                        + $"\r\nPackage 1: {similarPackages.First().ReportIdVersionRequestSource()}"
                                        + $"\r\nPackage 2: {similarPackages.Last().ReportIdVersionRequestSource()}");
            }

            foreach (var file in resourceFiles)
            {
                _fileSyncer.AddFile(file.Source, Paths.ResourcesFolder, file.Target);
            }

            _logger.Info($"Copying {resourceFiles.Count} resource files.");
            _fileSyncer.UpdateDestination();

            _performanceLogger.Write(stopwatch, "Resources generated.");
        }