Exemplo n.º 1
0
        //================================================================
        #region Getting the package from unpacked source folder

        private InstalledPackage TryGetPackageFromUnpackedSourceFolder(PackageSource source, PackageRequest request, FileSyncer binFileSyncer)
        {
            if (request.Source == null) // Unpacked source folder must be explicitly set in the package request.
            {
                return(null);
            }
            if (source.Path == null || !Directory.Exists(source.Path))
            {
                return(null);
            }

            var packageExtensions    = new[] { "*.nupkg", GetZipPackageName(request) };
            var existingPackageFiles = packageExtensions.SelectMany(ext => Directory.GetFiles(source.Path, ext));

            var existingMetadataFiles = Directory.GetFiles(source.Path, "*.nuspec");

            if (existingMetadataFiles.Length > 1)
            {
                // If any nuspec file exactly matches the packages name, use that one.
                var standardFileName = existingMetadataFiles.Where(f => string.Equals(Path.GetFileName(f), request.Id + ".nuspec", StringComparison.OrdinalIgnoreCase)).ToArray();
                if (standardFileName.Length == 1)
                {
                    existingMetadataFiles = standardFileName;
                }
            }

            var packageSourceSubfolders  = new[] { "DslScripts", "DataMigration", "Plugins", "Resources" };
            var existingSourceSubfolders = packageSourceSubfolders.Where(subfolder => Directory.Exists(Path.Combine(source.Path, subfolder)));

            if (existingPackageFiles.Any())
            {
                string ambiguousAlternative = null;
                if (existingMetadataFiles.Any())
                {
                    ambiguousAlternative = $".nuspec file '{Path.GetFileName(existingMetadataFiles.First())}'";
                }
                else if (existingSourceSubfolders.Any())
                {
                    ambiguousAlternative = $"source folder '{existingSourceSubfolders.First()}'";
                }

                if (ambiguousAlternative != null)
                {
                    throw new FrameworkException($"Ambiguous source for package {request.Id}. Source folder '{source.Path}' contains both" +
                                                 $" package file '{Path.GetFileName(existingPackageFiles.First())}' and {ambiguousAlternative}.");
                }

                _logger.Trace(() => $"Package {request.Id} source folder is not considered as unpacked source because" +
                              $" it contains a package file '{Path.GetFileName(existingPackageFiles.First())}'.");
                return(null);
            }
            else if (existingMetadataFiles.Length > 1)
            {
                _logger.Info(() => "Package " + request.Id + " source folder '" + source.ProvidedLocation + "' contains multiple .nuspec metadata files.");
                return(null);
            }
            else if (existingMetadataFiles.Length == 1)
            {
                _logger.Trace(() => "Reading package " + request.Id + " from unpacked source folder with metadata " + Path.GetFileName(existingMetadataFiles.Single()) + ".");
                _deployPackagesLogger.Trace(() => "Reading " + request.Id + " from source.");
                return(UseFilesFromUnpackedSourceWithMetadata(existingMetadataFiles.Single(), request, binFileSyncer));
            }
            else if (existingSourceSubfolders.Any())
            {
                _logger.Trace(() => "Reading package " + request.Id + " from unpacked source folder without metadata file.");
                _deployPackagesLogger.Trace(() => "Reading " + request.Id + " from source without metadata.");
                return(UseFilesFromUnpackedSourceWithoutMetadata(source.Path, request, binFileSyncer));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
 private InstalledPackage TryGetPackage(PackageSource source, PackageRequest request, FileSyncer binFileSyncer)
 {
     return(TryGetPackageFromUnpackedSourceFolder(source, request, binFileSyncer)
            ?? TryGetPackageFromLegacyZipPackage(source, request, binFileSyncer)
            ?? TryGetPackageFromNuGet(source, request, binFileSyncer));
 }