示例#1
0
        public StoredPackage GetPackage(PackageMetadata metadata)
        {
            var name = GetNameOfPackage(metadata);

            fileSystem.EnsureDirectoryExists(rootDirectory);

            var files = fileSystem.EnumerateFilesRecursively(rootDirectory, name + ".nupkg-*");

            foreach (var file in files)
            {
                var storedPackage = GetPackage(file);
                if (storedPackage == null)
                {
                    continue;
                }

                if (!string.Equals(storedPackage.Metadata.Id, metadata.Id, StringComparison.OrdinalIgnoreCase) || !string.Equals(storedPackage.Metadata.Version, metadata.Version, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                if (string.IsNullOrWhiteSpace(metadata.Hash))
                {
                    return(storedPackage);
                }

                if (metadata.Hash == storedPackage.Metadata.Hash)
                {
                    return(storedPackage);
                }
            }

            return(null);
        }
示例#2
0
        string[] MatchingFiles(RunningDeployment deployment)
        {
            var files = fileSystem.EnumerateFilesRecursively(deployment.CurrentDirectory, "*.config");

            var additional = deployment.Variables.GetStrings(ActionVariables.AdditionalPaths)
                             .Where(s => !string.IsNullOrWhiteSpace(s))
                             .SelectMany(p => fileSystem.EnumerateFilesRecursively(p, "*.config"));


            return(files.Concat(additional).Distinct().ToArray());
        }
示例#3
0
        private List <string> MatchingFiles(RunningDeployment deployment, string[] sourceExtensions)
        {
            var files = fileSystem.EnumerateFilesRecursively(deployment.CurrentDirectory, sourceExtensions).ToList();

            foreach (var path in deployment.Variables.GetStrings(ActionVariables.AdditionalPaths).Where(s => !string.IsNullOrWhiteSpace(s)))
            {
                var pathFiles = fileSystem.EnumerateFilesRecursively(path, sourceExtensions);
                files.AddRange(pathFiles);
            }

            return(files);
        }
        public void Install(RunningDeployment deployment)
        {
            if (deployment.Variables.GetFlag(SpecialVariables.Package.AutomaticallyUpdateAppSettingsAndConnectionStrings) == false)
            {
                return;
            }

            var appliedAsTransforms = deployment.Variables.GetStrings(SpecialVariables.AppliedXmlConfigTransforms, '|');

            Log.Verbose("Looking for appSettings, applicationSettings, and connectionStrings in any .config files");

            if (deployment.Variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors))
            {
                Log.Info("Variable replacement errors are supressed because the variable Octopus.Action.Package.IgnoreVariableReplacementErrors has been set.");
            }

            var configurationFiles = fileSystem.EnumerateFilesRecursively(deployment.CurrentDirectory, "*.config");

            foreach (var configurationFile in configurationFiles)
            {
                if (appliedAsTransforms.Contains(configurationFile))
                {
                    Log.VerboseFormat("File '{0}' was interpreted as an XML configuration transform; variable substitution won't be attempted.", configurationFile);
                    continue;
                }

                replacer.ModifyConfigurationFile(configurationFile, deployment.Variables);
            }
        }
示例#5
0
        PackagePhysicalFileMetadata?AttemptToGetPackageFromCache(string packageId, IVersion version, string cacheDirectory)
        {
            Log.VerboseFormat("Checking package cache for package {0} v{1}", packageId, version.ToString());

            var files = fileSystem.EnumerateFilesRecursively(cacheDirectory, PackageName.ToSearchPatterns(packageId, version, new[] { ".nupkg" }));

            foreach (var file in files)
            {
                var package = PackageName.FromFile(file);
                if (package == null)
                {
                    continue;
                }

                var idMatches         = string.Equals(package.PackageId, packageId, StringComparison.OrdinalIgnoreCase);
                var versionExactMatch = string.Equals(package.Version.ToString(), version.ToString(), StringComparison.OrdinalIgnoreCase);
                var nugetVerMatches   = package.Version.Equals(version);

                if (idMatches && (nugetVerMatches || versionExactMatch))
                {
                    return(PackagePhysicalFileMetadata.Build(file, package));
                }
            }

            return(null);
        }
        public void Install(RunningDeployment deployment)
        {
            var transformDefinitions = GetTransformDefinitions(deployment.Variables.Get(SpecialVariables.Package.AdditionalXmlConfigurationTransforms));

            var sourceExtensions = new HashSet <string>(
                transformDefinitions
                .Where(transform => transform.Advanced)
                .Select(transform => "*" + Path.GetExtension(transform.SourcePattern))
                .Distinct()
                );

            if (deployment.Variables.GetFlag(SpecialVariables.Package.AutomaticallyRunConfigurationTransformationFiles))
            {
                sourceExtensions.Add("*.config");
                transformDefinitions.Add(new XmlConfigTransformDefinition("Release"));

                var environment = deployment.Variables.Get(SpecialVariables.Environment.Name);
                if (!string.IsNullOrWhiteSpace(environment))
                {
                    transformDefinitions.Add(new XmlConfigTransformDefinition(environment));
                }
            }

            var transformsRun = new HashSet <string>();

            foreach (var configFile in fileSystem.EnumerateFilesRecursively(deployment.CurrentDirectory,
                                                                            sourceExtensions.ToArray()))
            {
                ApplyTransformations(configFile, transformDefinitions, transformsRun);
            }

            deployment.Variables.SetStrings(SpecialVariables.AppliedXmlConfigTransforms, transformsRun, "|");
        }
示例#7
0
        public void Install(RunningDeployment deployment)
        {
            var configurationFiles = fileSystem.EnumerateFilesRecursively(deployment.CurrentDirectory, "*.config", "*.xml");

            foreach (var configurationFile in configurationFiles)
            {
                substituter.PerformSubstitution(configurationFile, deployment.Variables);
            }
        }
示例#8
0
        private static void MockSearchableFiles(ICalamariFileSystem fileSystem, string parentDirectory, string[] files, string searchPattern)
        {
            fileSystem.EnumerateFilesRecursively(parentDirectory,
                                                 Arg.Is <string[]>(x => new List <string>(x).Contains(searchPattern))).Returns(files);

            foreach (var file in files)
            {
                fileSystem.FileExists(file).Returns(true);
            }
        }
        public void SetUp()
        {
            fileSystem = Substitute.For <ICalamariFileSystem>();
            fileSystem.EnumerateFilesRecursively(Arg.Any <string>(), Arg.Any <string[]>()).Returns(new[]
            {
                "C:\\App\\MyApp\\Web.config",
                "C:\\App\\MyApp\\Web.Release.config",
                "C:\\App\\MyApp\\Views\\Web.config"
            });

            deployment = new RunningDeployment("C:\\Packages", new CalamariVariableDictionary());
            replacer   = Substitute.For <IConfigurationVariablesReplacer>();
        }
        public void SetUp()
        {
            fileSystem = Substitute.For<ICalamariFileSystem>();
            fileSystem.EnumerateFilesRecursively(Arg.Any<string>(), Arg.Any<string[]>()).Returns(new[]
            {
                "C:\\App\\MyApp\\Web.config",
                "C:\\App\\MyApp\\Web.Release.config",
                "C:\\App\\MyApp\\Views\\Web.config"
            });

            deployment = new RunningDeployment("C:\\Packages", new CalamariVariableDictionary());
            replacer = Substitute.For<IConfigurationVariablesReplacer>();
        }
示例#11
0
        private void RemovedFailedPackageDownloads()
        {
            var pattern = "*" + NuGetPackageDownloader.DownloadingExtension;

            if (fileSystem.DirectoryExists(PackageDownloaderUtils.RootDirectory))
            {
                var toDelete = fileSystem.EnumerateFilesRecursively(PackageDownloaderUtils.RootDirectory, pattern)
                               .Where(f => fileSystem.GetCreationTime(f) <= DateTime.Now.AddDays(-1))
                               .ToArray();

                foreach (var file in toDelete)
                {
                    Log.Verbose($"Removing the failed to download file {file}");
                    fileSystem.DeleteFile(file, FailureOptions.IgnoreFailure);
                }
            }
        }
        public void Install(RunningDeployment deployment)
        {
            var explicitTransforms  = GetExplicitTransforms(deployment);
            var automaticTransforms = GetAutomaticTransforms(deployment);
            var sourceExtensions    = GetSourceExtensions(deployment, explicitTransforms);

            var allTransforms = explicitTransforms.Concat(automaticTransforms).ToList();
            var transformDefinitionsApplied = new List <XmlConfigTransformDefinition>();
            var transformFilesApplied       = new HashSet <Tuple <string, string> >();

            foreach (var configFile in fileSystem.EnumerateFilesRecursively(deployment.CurrentDirectory, sourceExtensions.ToArray()))
            {
                ApplyTransformations(configFile, allTransforms, transformFilesApplied, transformDefinitionsApplied);
            }

            LogFailedTransforms(explicitTransforms.Except(transformDefinitionsApplied));
            deployment.Variables.SetStrings(SpecialVariables.AppliedXmlConfigTransforms, transformFilesApplied.Select(t => t.Item1), "|");
        }
示例#13
0
        PackagePhysicalFileMetadata SourceFromCache(string packageId, IVersion version, string cacheDirectory)
        {
            Log.VerboseFormat("Checking package cache for package {0} v{1}", packageId, version.ToString());

            var files = fileSystem.EnumerateFilesRecursively(cacheDirectory, PackageName.ToSearchPatterns(packageId, version, new [] { Extension }));

            foreach (var file in files)
            {
                var package = PackageName.FromFile(file);
                if (package == null)
                {
                    continue;
                }

                if (string.Equals(package.PackageId, packageId, StringComparison.OrdinalIgnoreCase) && package.Version.Equals(version))
                {
                    return(PackagePhysicalFileMetadata.Build(file, package));
                }
            }

            return(null);
        }
示例#14
0
        /// <summary>
        /// Attempt to find a package id and version in the local cache
        /// </summary>
        /// <param name="packageId">The desired package id</param>
        /// <param name="version">The desired version</param>
        /// <param name="cacheDirectory">The location of cached files</param>
        /// <returns>The path to a cached version of the file, or null if none are found</returns>
        string SourceFromCache(
            string packageId,
            IVersion version,
            string cacheDirectory)
        {
            Guard.NotNullOrWhiteSpace(packageId, "packageId can not be null");
            Guard.NotNull(version, "version can not be null");
            Guard.NotNullOrWhiteSpace(cacheDirectory, "cacheDirectory can not be null");

            Log.VerboseFormat("Checking package cache for package {0} {1}", packageId, version.ToString());

            fileSystem.EnsureDirectoryExists(cacheDirectory);

            var filename = new MavenPackageID(packageId).FileSystemName;

            return(JarExtractor.EXTENSIONS
                   .Select(extension => filename + "*" + extension)
                   // Convert the search pattern to matching file paths
                   .SelectMany(searchPattern => fileSystem.EnumerateFilesRecursively(cacheDirectory, searchPattern))
                   // Filter out unparseable and unmatched results
                   .FirstOrDefault(file => FileMatchesDetails(file, packageId, version)));
        }
示例#15
0
        string FindPackage(string workingDirectory)
        {
            var packages = fileSystem.EnumerateFiles(workingDirectory, "*.cspkg").ToList();

            if (packages.Count == 0)
            {
                // Try subdirectories
                packages = fileSystem.EnumerateFilesRecursively(workingDirectory, "*.cspkg").ToList();
            }

            if (packages.Count == 0)
            {
                throw new CommandException("Your package does not appear to contain any Azure Cloud Service package (.cspkg) files.");
            }

            if (packages.Count > 1)
            {
                throw new CommandException("Your deployment package contains more than one Cloud Service package (.cspkg) file, which is unsupported. Files: "
                                           + string.Concat(packages.Select(p => Environment.NewLine + " - " + p)));
            }

            return(packages.Single());
        }
示例#16
0
        private IEnumerable <string> PackageFiles(string name)
        {
            var patterns = packageExtractorFactory.Extensions.Select(e => name + e + "-*").ToArray();

            return(fileSystem.EnumerateFilesRecursively(rootDirectory, patterns));
        }
示例#17
0
 private IEnumerable <string> PackageFiles(string packageId, IVersion version = null)
 {
     return(fileSystem.EnumerateFilesRecursively(RootDirectory,
                                                 PackageName.ToSearchPatterns(packageId, version, packageExtractorFactory.Extensions)));
 }
        private static void MockSearchableFiles(ICalamariFileSystem fileSystem, string parentDirectory, string[] files, string searchPattern)
        {
            fileSystem.EnumerateFilesRecursively(parentDirectory,
                Arg.Is<string[]>(x => new List<string>(x).Contains(searchPattern))).Returns(files);

            foreach (var file in files)
            {
                fileSystem.FileExists(file).Returns(true);
                fileSystem.EnumerateFiles(Path.GetDirectoryName(files[0]), Arg.Is<string[]>(s => s.Contains(GetRelativePathToTransformFile(files[0], file)))).Returns(new[] {file});
            }
        }
示例#19
0
 IEnumerable <string> PackageFiles(string packageId, IVersion?version = null)
 {
     return(fileSystem.EnumerateFilesRecursively(GetPackagesDirectory(),
                                                 PackageName.ToSearchPatterns(packageId, version, supportedExtensions)));
 }