Exemplo n.º 1
0
        protected List <HandlerResponse> ProcessOutputHandlers(FileSystemInfo outputPath)
        {
            var results =
                OutputHandlers.Where(_ => !string.IsNullOrWhiteSpace(outputPath?.FullName))
                .Select(handler => handler.Process(outputPath.FullName))
                .ToList();

            return(results);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Publishes the app to the given directory using the current settings
        /// </summary>
        /// <param name="outputDirectory">Output path for the final published artifacts</param>
        public void PublishTo(DirectoryPath outputDirectory)
        {
            OutputHandlers.Add(new PublishPageHandler());
            Loggers.Add(new CakeLogger(Log));
            var mgr       = new CakePublishManager(this);
            var responses = mgr.PublishApp(outputDirectory.MakeAbsolute(Environment).FullPath,
                                           ForceBuild ? PublishBehaviour.CleanFirst : PublishBehaviour.DoNotBuild);

            foreach (var r in responses)
            {
                Log.Information($"Handler finished: {r.Result} - {r.ResultMessage}");
            }
        }
Exemplo n.º 3
0
        public ClickTwicePackSettings WithHandler(IHandler handler)
        {
            var input  = handler as IInputHandler;
            var output = handler as IOutputHandler;

            if (input != null)
            {
                InputHandlers.Add(input);
            }
            if (output != null)
            {
                OutputHandlers.Add(output);
            }
            return(this);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Publishes the app to the given folder
        /// </summary>
        /// <param name="targetPath">Folder to publsh the project too</param>
        /// <param name="behaviour">Preferred treatment of previous builds</param>
        /// <returns>The collection of results from the output handlers</returns>
        public List <HandlerResponse> PublishApp(string targetPath,
                                                 PublishBehaviour behaviour = PublishBehaviour.CleanFirst)
        {
            var results = InputHandlers.ProcessHandlers(
                new FilePath(ProjectFilePath).GetDirectory().MakeAbsolute(Environment).FullPath, s => Log(s));

            Log(
                $"Completed processing input handlers: {results.Count(r => r.Result == HandlerResult.OK)} OK, {results.Count(r => r.Result == HandlerResult.Error)} errors, {results.Count(r => r.Result == HandlerResult.NotRun)} not run");
            if (results.Any(r => r.Result == HandlerResult.Error))
            {
                throw new HandlerProcessingException(InputHandlers, results);
            }
            string outputPath;

            if (behaviour == PublishBehaviour.DoNotBuild)
            {
                outputPath  = Path.Combine(new FileInfo(ProjectFilePath).Directory.FullName, "bin", Configuration);
                BuildAction = null;
            }
            else
            {
                outputPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString("N"));
                if (!FileSystem.Exist((DirectoryPath)outputPath))
                {
                    FileSystem.GetDirectory(outputPath).Create();
                }
            }
            var props = new Dictionary <string, string>
            {
                { "Configuration", Configuration },
                { "Platform", Platform },
                { "OutputPath", outputPath },
                { "PublishDir", Path.Combine(outputPath, "app.publish") + "\\" }
            };

            BuildSettings = new MSBuildSettings
            {
                Configuration   = Configuration,
                MSBuildPlatform = GetMSBuildPlatform(Platform),
                Verbosity       = Verbosity.Quiet
            };
            BuildSettings.AddTargets(behaviour);
            BuildSettings.AddProperties(props, AdditionalProperties);
            BuildAction?.Invoke(this);
            var publishDir =
                new DirectoryPath(
                    new DirectoryInfo(props["OutputPath"]).GetDirectories()
                    .FirstOrDefault(d => d.Name == "app.publish")
                    .FullName);

            if (GenerateManifest)
            {
                PrepareManifestManager(publishDir, InformationSource.Both);
                ManifestManager.DeployManifest(ManifestManager.CreateAppManifest());
            }
            Log("Processing output handlers");
            var output = OutputHandlers.ProcessHandlers(publishDir.FullPath, s => Log(s));

            Log(
                $"Completed processing output handlers: {output.Count(r => r.Result == HandlerResult.OK)} OK, {output.Count(r => r.Result == HandlerResult.Error)} errors, {output.Count(r => r.Result == HandlerResult.NotRun)} not run");
            if (output.Any(o => o.Result == HandlerResult.Error) && ErrorAction != null)
            {
                Log("Error encountered while processing output handlers. Aborting!");
                ErrorAction?.Invoke(output);
                //throw new HandlerProcessingException(OutputHandlers, output); // in case something goes real wrong
            }
            if (string.IsNullOrWhiteSpace(targetPath))
            {
                return(output);
            }
            Log("Copying publish results to target directory");
            new DirectoryInfo(publishDir.MakeAbsolute(Environment).FullPath).Copy(destDirPath: targetPath,
                                                                                  copySubDirs: true);
            return(output);
        }