コード例 #1
0
        protected override void Execute(IConfiguration configuration)
        {
            _source = configuration.AddRootDirectory(_source);
            _target = configuration.AddRootDirectory(_target);

            ValidateParameters(configuration);

            if (_sourceType == PathItemType.File)
            {
                FilePath source = new FilePath(_source);
                if (_targetType == PathItemType.Directory)
                {
                    DirectoryPath target = new DirectoryPath(_target);
                    configuration.Context.CakeContext.CopyFileToDirectory(source, target);
                }
                else if (_targetType == PathItemType.File)
                {
                    FilePath target = new FilePath(_target);
                    configuration.Context.CakeContext.CopyFile(source, target);
                }
                else
                {
                    throw new NotSupportedException($"Could not copy with source {_sourceType} to {_targetType}");
                }
            }
            else if (_sourceType == PathItemType.Directory)
            {
                DirectoryPath source = new DirectoryPath(_source);
                if (_targetType == PathItemType.Directory)
                {
                    DirectoryPath target = new DirectoryPath(_target);
                    configuration.Context.CakeContext.CopyDirectory(source, target);
                }
                else
                {
                    throw new NotSupportedException($"Could not copy with source {_sourceType} to {_targetType}");
                }
            }
            else if (_sourceType == PathItemType.Pattern)
            {
                IEnumerable <FilePath> sources = configuration.Context.CakeContext.Globber.GetFiles(_source);
                if (_targetType == PathItemType.Directory)
                {
                    DirectoryPath target = new DirectoryPath(_target);
                    configuration.Context.CakeContext.CopyFiles(sources, target);
                }
                else
                {
                    throw new NotSupportedException($"Could not copy with source {_sourceType} to {_targetType}");
                }
            }
            else
            {
                throw new NotSupportedException($"Could not copy with source {_sourceType} to {_targetType}");
            }
        }
コード例 #2
0
        private string Nuspec(IConfiguration configuration, DirectoryPath nugetContentPath)
        {
            if (!configuration.TryGetSimple(NuGetConstants.NUGET_NUSPEC_FILE_KEY, out string nuspecPath))
            {
                configuration.Context.CakeContext.LogAndThrow("Missing nuspec file path");
            }
            nuspecPath = configuration.AddRootDirectory(nuspecPath);
            configuration.FileExistsOrThrow(nuspecPath);

            XDocument nuspecDocument;

            using (Stream inputStream = configuration.Context.CakeContext.FileSystem.GetFile(nuspecPath).OpenRead())
            {
                nuspecDocument = XDocument.Load(inputStream);
            }

            XElement metadataRoot = GetMetadataRootFromNuspec(configuration, nuspecDocument);
            string   packageId    = configuration.GetSimple <string>(NuGetConstants.NUGET_PACKAGE_ID_KEY);

            UpdateOrCreateNode(metadataRoot, "id", packageId);

            if (configuration.TryGetSimple(NuGetConstants.NUGET_PACKAGE_AUTHOR_KEY, out string author))
            {
                UpdateOrCreateNode(metadataRoot, "authors", author);
            }

            if (configuration.TryGetSimple(NuGetConstants.NUGET_PACKAGE_RELEASE_NOTES_FILE_KEY, out string releaseNoteFile))
            {
                releaseNoteFile = configuration.AddRootDirectory(releaseNoteFile);
                configuration.FileExistsOrThrow(releaseNoteFile);

                string releaseNoteContent = configuration.Context.CakeContext.FileSystem.GetFile(releaseNoteFile).ReadAll();

                UpdateOrCreateNode(metadataRoot, "releaseNotes", releaseNoteContent);
            }

            if (configuration.TryGetSimple(NuGetConstants.NUGET_PACKAGE_VERSION_KEY, out string version) ||
                configuration.TryGetSimple(ConfigurationConstants.VERSION_KEY, out version))
            {
                UpdateOrCreateNode(metadataRoot, "version", version);
            }

            FilePath nuspecOutputPath = nugetContentPath.CombineWithFilePath($"{packageId}.nuspec");

            using (Stream outputStream = configuration.Context.CakeContext.FileSystem.GetFile(nuspecOutputPath).OpenWrite())
            {
                nuspecDocument.Save(outputStream);
            }

            return(nuspecOutputPath.FullPath);
        }
コード例 #3
0
        public void Execute(IConfiguration configuration, StepType currentStep)
        {
            string path = configuration.AddRootDirectory(_filePath);

            configuration.FileExistsOrThrow(path);

            string fileContent;

            using (Stream inputStream = configuration.Context.CakeContext.FileSystem.GetFile(path).OpenRead())
            {
                using (StreamReader streamReader = new StreamReader(inputStream))
                {
                    fileContent = streamReader.ReadToEnd();
                }
            }

            SyntaxNode node = CSharpSyntaxTree.ParseText(fileContent).GetRoot();

            node = _transformation.Execute(node);

            fileContent = node.ToFullString();

            using (Stream outputStream = configuration.Context.CakeContext.FileSystem.GetFile(path).OpenWrite())
            {
                using (StreamWriter streamWriter = new StreamWriter(outputStream))
                {
                    streamWriter.Write(fileContent);
                }
            }
        }
コード例 #4
0
        public void Execute(IConfiguration configuration, StepType currentStep)
        {
            string plistFile = configuration.AddRootDirectory(_sourceFile);

            configuration.FileExistsOrThrow(plistFile);

            _transformation.Execute(plistFile, configuration);
        }
コード例 #5
0
        private void Sign(JarsignerCommand command, IConfiguration configuration, string sourceApk, string destinationApk)
        {
            string keyStoreFile = configuration.AddRootDirectory(configuration.GetSimple <string>(AndroidConstants.ANDROID_KEYSTORE_FILE));
            string password     = configuration.GetSimple <string>(AndroidConstants.ANDROID_KEYSTORE_PASSWORD);
            string keyAlias     = configuration.GetSimple <string>(AndroidConstants.ANDROID_KEYSTORE_KEYALIAS);
            string keyPassword  = configuration.GetSimple <string>(AndroidConstants.ANDROID_KEYSTORE_KEYPASSWORD);

            command.SignApk(sourceApk, destinationApk, keyStoreFile, password, keyAlias, keyPassword);
        }
コード例 #6
0
        public void Execute(IConfiguration configuration, StepType currentStep)
        {
            if (!configuration.TryGetSimple(AndroidConstants.ANDROID_KEYSTORE_FILE, out string keyStoreFile))
            {
                configuration.LogAndThrow($"Missing path for keystore");
            }
            keyStoreFile = configuration.AddRootDirectory(keyStoreFile);

            if (!configuration.TryGetSimple(AndroidConstants.ANDROID_KEYSTORE_PASSWORD, out string password))
            {
                configuration.LogAndThrow($"Missing password for keystore");
            }
            if (!configuration.TryGetSimple(AndroidConstants.ANDROID_KEYSTORE_KEYALIAS, out string keyAlias))
            {
                configuration.LogAndThrow($"Missing alias for keystore");
            }
            if (!configuration.TryGetSimple(AndroidConstants.ANDROID_KEYSTORE_KEYPASSWORD, out string keyPassword))
            {
                configuration.LogAndThrow($"Missing alias password for keystore");
            }

            if (!configuration.TryGetSimple(AndroidConstants.ANDROID_KEYSTORE_ALLOW_CREATE, out bool allowCreate))
            {
                allowCreate = false;
            }


            KeytoolCommand command = new KeytoolCommand(configuration.Context.CakeContext);

            if (configuration.Context.CakeContext.FileExists(keyStoreFile))
            {
                if (!command.IsRightPassword(keyStoreFile, password))
                {
                    configuration.Context.CakeContext.LogAndThrow($"Invalid password for keystore {keyStoreFile}");
                }

                if (command.HasAlias(keyStoreFile, password, keyAlias))
                {
                    return;
                }
            }

            if (allowCreate)
            {
                if (!configuration.TryGetSimple(AndroidConstants.ANDROID_KEYSTORE_AUTHORITY, out string authority))
                {
                    configuration.Context.CakeContext.LogAndThrow($"Missing authority to create alias {keyAlias} in keystore {keyStoreFile}");
                }
                command.CreateAlias(keyStoreFile, password, keyAlias, keyPassword, authority);
            }
            else
            {
                configuration.Context.CakeContext.LogAndThrow($"Missing alias {keyAlias} for keystore {keyStoreFile} and we are not allowed to create it");
            }
        }
コード例 #7
0
        protected override void Execute(IConfiguration configuration)
        {
            string file = configuration.AddRootDirectory(_file);

            configuration.FileExistsOrThrow(file);

            string content        = File.ReadAllText(file);
            string updatedContent = _transformation.Execute(content);

            File.WriteAllText(file, updatedContent);
        }
コード例 #8
0
        public void Execute(IConfiguration configuration)
        {
            foreach (string relativeFilePath in _files)
            {
                string file = configuration.AddRootDirectory(relativeFilePath);
                configuration.FileExistsOrThrow(file);

                string content = File.ReadAllText(file);
                foreach (var replacement in _replacements)
                {
                    content = content.Replace(replacement.Source, replacement.Target);
                }

                File.WriteAllText(file, content);
            }
        }
コード例 #9
0
        public void Execute(IConfiguration configuration, StepType currentStep)
        {
            string projectFile;

            if (_projectFile == null)
            {
                projectFile = configuration.GetProjectPath();
            }
            else
            {
                projectFile = configuration.AddRootDirectory(_projectFile);
            }


            configuration.FileExistsOrThrow(projectFile);

            _transformation.Execute(projectFile, configuration);
        }
コード例 #10
0
        public void Execute(IConfiguration configuration, StepType currentStep)
        {
            string directory = _directoryPath ?? configuration.AddRootDirectory(".");

            if (!configuration.Context.CakeContext.DirectoryExists(directory))
            {
                configuration.Context.CakeContext.LogAndThrow($"Directory {directory} does not exists");
            }

            List <FilePath> solutions = configuration.Context.CakeContext.Globber.GetFiles(System.IO.Path.Combine(directory, "**", "*.sln")).ToList();

            if (solutions.Count == 0)
            {
                configuration.Context.CakeContext.LogAndThrow($"No solution file found in directory {directory}");
            }

            configuration.Context.CakeContext.NuGetRestore(solutions);
        }
コード例 #11
0
        public void Execute(IConfiguration configuration, StepType currentStep)
        {
            FastlaneCommand command = new FastlaneCommand(configuration.Context.CakeContext);

            if (!configuration.TryGetSimple(iOSConstants.FASTLANE_APPLE_USERNAME, out string userName))
            {
                configuration.LogAndThrow("Fastlane: missing user name");
            }

            if (!configuration.TryGetSimple(iOSConstants.FASTLANE_APPLE_TEAMNAME, out string teamName))
            {
                configuration.LogAndThrow("Fastlane: missing team name");
            }

            if (!configuration.TryGetSimple(iOSConstants.IOS_BUNDLE_ID_KEY, out string bundleId))
            {
                configuration.LogAndThrow("Fastlane: missing bundle id");
            }

            if (!configuration.TryGetSimple(iOSConstants.FASTLANE_SIGH_CERTIFICATE_TYPE, out CertificateType certificateType))
            {
                certificateType = CertificateType.Development;
            }

            string certificateOutputFile = configuration.AddRootDirectory($"{Guid.NewGuid():N}.mobileprovision");

            if (!command.SynchronizeProvisionningProfile(userName, teamName, bundleId, certificateType, certificateOutputFile) ||
                !configuration.Context.CakeContext.FileExists(certificateOutputFile))
            {
                configuration.Context.CakeContext.LogAndThrow("Error happened with fastlane, unable to read downloaded provisioning profile");
            }

            string provisioningContent = File.ReadAllText(certificateOutputFile);

            int keyIndex        = provisioningContent.IndexOf("<key>UUID</key>", StringComparison.Ordinal);
            int valueStartIndex = provisioningContent.IndexOf("<string>", keyIndex, StringComparison.Ordinal) + "<string>".Length;
            int valueEndIndex   = provisioningContent.IndexOf("</string>", keyIndex, StringComparison.Ordinal);

            string uuid = provisioningContent.Substring(valueStartIndex, valueEndIndex - valueStartIndex);

            configuration.Context.CakeContext.DeleteFile(certificateOutputFile);

            configuration.WithSignProvision(uuid);
        }
コード例 #12
0
        public void Execute(IConfiguration configuration, StepType currentStep)
        {
            //get artifacts output directory
            DirectoryPath artifactsPath = configuration.GetArtifactsPath();

            if (!configuration.TryGetSimple(NuGetConstants.NUGET_NUSPEC_FILE_KEY, out string nuspecPath))
            {
                configuration.Context.CakeContext.LogAndThrow("Can not determine nuget package id using either the PackageId configuration or the id in the Nuspec file");
            }


            if (!configuration.TryGetSimple(NuGetConstants.NUGET_PACKAGE_ID_KEY, out string packageId))
            {
                packageId = ReadPackageIdFromNuspec(configuration, configuration.AddRootDirectory(nuspecPath));
                configuration.AddSimple(NuGetConstants.NUGET_PACKAGE_ID_KEY, packageId);
            }

            if (!configuration.TryGetSimple(NuGetConstants.NUGET_PACKAGE_VERSION_KEY, out string packageVersion))
            {
                if (!configuration.TryGetSimple(ConfigurationConstants.VERSION_KEY, out packageVersion))
                {
                    packageVersion = ReadPackageVersionFromNuspec(configuration, configuration.AddRootDirectory(nuspecPath));
                }
                configuration.AddSimple(NuGetConstants.NUGET_PACKAGE_VERSION_KEY, packageVersion);
            }

            IDirectory           artifactsDirectory = configuration.Context.CakeContext.FileSystem.GetDirectory(artifactsPath);
            List <FilePath>      inputFiles         = artifactsDirectory.GetFiles("*", SearchScope.Current).Select(x => x.Path).ToList();
            List <DirectoryPath> inputDirectories   = artifactsDirectory.GetDirectories("*", SearchScope.Current).Select(x => x.Path).ToList();

            //create nuget output directory
            DirectoryPath nugetContentPath = artifactsPath.Combine(packageId);

            configuration.Context.CakeContext.EnsureDirectoryExists(nugetContentPath);

            DirectoryPath nugetLibPath = nugetContentPath.Combine("lib");

            configuration.Context.CakeContext.EnsureDirectoryExists(nugetLibPath);

            //copy existing file in nuget content directory
            foreach (DirectoryPath inputDirectory in inputDirectories)
            {
                DirectoryPath output = nugetLibPath.Combine(inputDirectory.GetDirectoryName());
                configuration.Context.CakeContext.EnsureDirectoryExists(output);
                configuration.Context.CakeContext.CopyDirectory(inputDirectory, output);
            }
            foreach (FilePath inputFile in inputFiles)
            {
                configuration.Context.CakeContext.CopyFileToDirectory(inputFile, nugetLibPath);
            }

            //copy nuspec with parameters
            string nuspecOutputPath = Nuspec(configuration, nugetContentPath);

            if (configuration.TryGet(NuGetConstants.NUGET_ADDITIONAL_FILES_KEY, out ListConfigurationItem <NugetFile> list))
            {
                foreach (NugetFile nugetFile in list.Values)
                {
                    string file = configuration.AddRootDirectory(nugetFile.FilePath);
                    configuration.FileExistsOrThrow(file);
                    DirectoryPath destinationPath = nugetContentPath;
                    if (!string.IsNullOrEmpty(nugetFile.NugetRelativePath))
                    {
                        destinationPath = destinationPath.Combine(nugetFile.NugetRelativePath);
                    }
                    configuration.Context.CakeContext.EnsureDirectoryExists(destinationPath);
                    configuration.Context.CakeContext.CopyFileToDirectory(file, destinationPath);
                }
            }

            configuration.Context.CakeContext.NuGetPack(nuspecOutputPath, new NuGetPackSettings
            {
                OutputDirectory = artifactsPath,
            });

            string nugetPackagePath = artifactsPath.CombineWithFilePath($"{packageId}.{packageVersion}.nupkg").FullPath;

            configuration.AddSimple(NuGetConstants.NUGET_PACK_OUTPUT_FILE_KEY, nugetPackagePath);
        }
コード例 #13
0
 public static string GetProjectPath(this IConfiguration configuration)
 {
     return(configuration.AddRootDirectory(configuration.GetSimple <string>(ConfigurationConstants.PROJECT_KEY)));
 }
コード例 #14
0
 public static string GetSolutionPath(this IConfiguration configuration)
 {
     return(configuration.AddRootDirectory(configuration.GetSimple <string>(ConfigurationConstants.SOLUTION_KEY)));
 }
コード例 #15
0
 public void Execute(IConfiguration configuration, StepType currentStep)
 {
     _transformation.Execute(configuration.AddRootDirectory(_manifestFile), configuration);
 }