From 477bfeea0146ca12cbf582d583220273b0d1413e Mon Sep 17 00:00:00 2001 From: Charles Pisciotta Date: Fri, 24 Nov 2023 00:39:06 -0500 Subject: [PATCH] Move beautify implementation --- .../Renderers/OutputRendering.swift | 186 ------------------ Sources/XcbeautifyLib/XCFormatter.swift | 176 ++++++++++++++++- 2 files changed, 175 insertions(+), 187 deletions(-) diff --git a/Sources/XcbeautifyLib/Renderers/OutputRendering.swift b/Sources/XcbeautifyLib/Renderers/OutputRendering.swift index d1da53d7..9e0b5c6e 100644 --- a/Sources/XcbeautifyLib/Renderers/OutputRendering.swift +++ b/Sources/XcbeautifyLib/Renderers/OutputRendering.swift @@ -3,8 +3,6 @@ import Foundation protocol OutputRendering { var colored: Bool { get } - func beautify(captureGroup: CaptureGroup, line: String, additionalLines: @escaping () -> (String?)) -> String? - func format(testSummary: TestSummary) -> String func format(line: String, command: String, pattern: Pattern, arguments: String) -> String? @@ -75,190 +73,6 @@ protocol OutputRendering { func formatWriteFile(group: WriteFileCaptureGroup) -> String? } -extension OutputRendering { - func beautify( - captureGroup: CaptureGroup, - line: String, - additionalLines: @escaping () -> (String?) - ) -> String? { - switch captureGroup { - case let group as AggregateTargetCaptureGroup: - return formatTargetCommand(command: "Aggregate", group: group) - case let group as AnalyzeCaptureGroup: - return formatAnalyze(group: group) - case let group as AnalyzeTargetCaptureGroup: - return formatTargetCommand(command: "Analyze", group: group) - case let group as BuildTargetCaptureGroup: - return formatTargetCommand(command: "Build", group: group) - case _ as CheckDependenciesCaptureGroup: - return format(line: line, command: "Check Dependencies", pattern: .checkDependencies, arguments: "") - case let group as CheckDependenciesErrorsCaptureGroup: - return formatError(group: group) - case let group as ClangErrorCaptureGroup: - return formatError(group: group) - case let group as CleanRemoveCaptureGroup: - return formatCleanRemove(group: group) - case let group as CleanTargetCaptureGroup: - return formatTargetCommand(command: "Clean", group: group) - case let group as CodesignCaptureGroup: - return formatCodeSign(group: group) - case let group as CodesignFrameworkCaptureGroup: - return formatCodeSignFramework(group: group) - case let group as CompileCaptureGroup: - return formatCompile(group: group) - case let group as CompileCommandCaptureGroup: - return formatCompileCommand(group: group) - case let group as CompileErrorCaptureGroup: - return formatCompileError(group: group, additionalLines: additionalLines) - case let group as CompileStoryboardCaptureGroup: - return formatCompile(group: group) - case let group as CompileWarningCaptureGroup: - return formatCompileWarning(group: group, additionalLines: additionalLines) - case let group as CompileXibCaptureGroup: - return formatCompile(group: group) - case let group as CopyHeaderCaptureGroup: - return formatCopy(group: group) - case let group as CopyPlistCaptureGroup: - return formatCopy(group: group) - case let group as CopyStringsCaptureGroup: - return formatCopy(group: group) - case let group as CpresourceCaptureGroup: - return formatCopy(group: group) - case let group as CursorCaptureGroup: - return formatCursor(group: group) - case let group as DuplicateLocalizedStringKeyCaptureGroup: - return formatDuplicateLocalizedStringKey(group: group) - case let group as ExecutedWithoutSkippedCaptureGroup: - return formatExecutedWithoutSkipped(group: group) - case let group as ExecutedWithSkippedCaptureGroup: - return formatExecutedWithSkipped(group: group) - case let group as FailingTestCaptureGroup: - return formatFailingTest(group: group) - case let group as FatalErrorCaptureGroup: - return formatError(group: group) - case let group as FileMissingErrorCaptureGroup: - return formatFileMissingError(group: group) - case let group as GenerateCoverageDataCaptureGroup: - return formatGenerateCoverageData(group: group) - case let group as GeneratedCoverageReportCaptureGroup: - return formatCoverageReport(group: group) - case let group as GenerateDSYMCaptureGroup: - return formatGenerateDsym(group: group) - case let group as GenericWarningCaptureGroup: - return formatWarning(group: group) - case let group as LDErrorCaptureGroup: - return formatError(group: group) - case let group as LDWarningCaptureGroup: - return formatLdWarning(group: group) - case let group as LibtoolCaptureGroup: - return formatLibtool(group: group) - case let group as LinkerDuplicateSymbolsCaptureGroup: - return formatLinkerDuplicateSymbolsError(group: group) - case let group as LinkerDuplicateSymbolsLocationCaptureGroup: - return formatLinkerDuplicateSymbolsLocation(group: group) - case let group as LinkerUndefinedSymbolLocationCaptureGroup: - return formatLinkerUndefinedSymbolLocation(group: group) - case let group as LinkerUndefinedSymbolsCaptureGroup: - return formatLinkerUndefinedSymbolsError(group: group) - case let group as LinkingCaptureGroup: - return formatLinking(group: group) - case let group as ModuleIncludesErrorCaptureGroup: - return formatError(group: group) - case let group as NoCertificateCaptureGroup: - return formatError(group: group) - case let group as PackageCheckingOutCaptureGroup: - return formatPackageCheckingOut(group: group) - case let group as PackageFetchingCaptureGroup: - return formatPackageFetching(group: group) - case let group as PackageGraphResolvedItemCaptureGroup: - return formatPackageItem(group: group) - case _ as PackageGraphResolvingEndedCaptureGroup: - return formatPackageEnd() - case _ as PackageGraphResolvingStartCaptureGroup: - return formatPackageStart() - case let group as PackageUpdatingCaptureGroup: - return formatPackageUpdating(group: group) - case let group as ParallelTestCaseAppKitPassedCaptureGroup: - return formatParallelTestCaseAppKitPassed(group: group) - case let group as ParallelTestCaseFailedCaptureGroup: - return formatParallelTestCaseFailed(group: group) - case let group as ParallelTestCasePassedCaptureGroup: - return formatParallelTestCasePassed(group: group) - case let group as ParallelTestingFailedCaptureGroup: - return formatParallelTestingFailed(line: line, group: group) - case let group as ParallelTestingPassedCaptureGroup: - return formatParallelTestingPassed(line: line, group: group) - case let group as ParallelTestingStartedCaptureGroup: - return formatParallelTestingStarted(line: line, group: group) - case let group as ParallelTestSuiteStartedCaptureGroup: - return formatParallelTestSuiteStarted(group: group) - case let group as PbxcpCaptureGroup: - return formatCopy(group: group) - case let group as PhaseScriptExecutionCaptureGroup: - return formatPhaseScriptExecution(group: group) - case let group as PhaseSuccessCaptureGroup: - return formatPhaseSuccess(group: group) - case let group as PodsErrorCaptureGroup: - return formatError(group: group) - case _ as PreprocessCaptureGroup: -// return format(line: line, command: "Preprocessing", pattern: pattern, arguments: "$1") - // FIXME - return nil - case let group as ProcessInfoPlistCaptureGroup: - return formatProcessInfoPlist(group: group) - case let group as ProcessPchCaptureGroup: - return formatProcessPch(group: group) - case let group as ProcessPchCommandCaptureGroup: - return formatProcessPchCommand(group: group) - case let group as ProvisioningProfileRequiredCaptureGroup: - return formatError(group: group) - case let group as RestartingTestCaptureGroup: - return formatRestartingTest(line: line, group: group) - case let group as ShellCommandCaptureGroup: - return formatShellCommand(group: group) - case _ as SymbolReferencedFromCaptureGroup: - return formatCompleteError(line: line) - case let group as TestCaseMeasuredCaptureGroup: - return formatTestCaseMeasured(group: group) - case let group as TestCasePassedCaptureGroup: - return formatTestCasePassed(group: group) - case let group as TestCasePendingCaptureGroup: - return formatTestCasePending(group: group) - case let group as TestCaseStartedCaptureGroup: - return formatTestCasesStarted(group: group) - case let group as TestsRunCompletionCaptureGroup: - return formatTestsRunCompletion(group: group) - case let group as TestSuiteAllTestsFailedCaptureGroup: - return formatTestSuiteAllTestsFailed(group: group) - case let group as TestSuiteAllTestsPassedCaptureGroup: - return formatTestSuiteAllTestsPassed(group: group) - case let group as TestSuiteStartCaptureGroup: - return formatTestSuiteStart(group: group) - case let group as TestSuiteStartedCaptureGroup: - return formatTestSuiteStarted(group: group) - case let group as TIFFutilCaptureGroup: - return formatTIFFUtil(group: group) - case let group as TouchCaptureGroup: - return formatTouch(group: group) - case let group as UIFailingTestCaptureGroup: - return formatUIFailingTest(group: group) - case _ as UndefinedSymbolLocationCaptureGroup: - return formatCompleteWarning(line: line) - case let group as WillNotBeCodeSignedCaptureGroup: - return formatWillNotBeCodesignWarning(group: group) - case let group as WriteAuxiliaryFilesCaptureGroup: - return formatWriteAuxiliaryFiles(group: group) - case let group as WriteFileCaptureGroup: - return formatWriteFile(group: group) - case let group as XcodebuildErrorCaptureGroup: - return formatError(group: group) - default: - assertionFailure() - return nil - } - } -} - extension OutputRendering { func format(line: String, command: String, pattern: Pattern, arguments: String) -> String? { diff --git a/Sources/XcbeautifyLib/XCFormatter.swift b/Sources/XcbeautifyLib/XCFormatter.swift index c78aae2d..98274aaa 100644 --- a/Sources/XcbeautifyLib/XCFormatter.swift +++ b/Sources/XcbeautifyLib/XCFormatter.swift @@ -22,6 +22,180 @@ public struct XCFormatter { line: String, additionalLines: @escaping () -> String? ) -> String? { - renderer.beautify(captureGroup: captureGroup, line: line, additionalLines: additionalLines) + switch captureGroup { + case let group as AggregateTargetCaptureGroup: + return renderer.formatTargetCommand(command: "Aggregate", group: group) + case let group as AnalyzeCaptureGroup: + return renderer.formatAnalyze(group: group) + case let group as AnalyzeTargetCaptureGroup: + return renderer.formatTargetCommand(command: "Analyze", group: group) + case let group as BuildTargetCaptureGroup: + return renderer.formatTargetCommand(command: "Build", group: group) + case _ as CheckDependenciesCaptureGroup: + return renderer.format(line: line, command: "Check Dependencies", pattern: .checkDependencies, arguments: "") + case let group as CheckDependenciesErrorsCaptureGroup: + return renderer.formatError(group: group) + case let group as ClangErrorCaptureGroup: + return renderer.formatError(group: group) + case let group as CleanRemoveCaptureGroup: + return renderer.formatCleanRemove(group: group) + case let group as CleanTargetCaptureGroup: + return renderer.formatTargetCommand(command: "Clean", group: group) + case let group as CodesignCaptureGroup: + return renderer.formatCodeSign(group: group) + case let group as CodesignFrameworkCaptureGroup: + return renderer.formatCodeSignFramework(group: group) + case let group as CompileCaptureGroup: + return renderer.formatCompile(group: group) + case let group as CompileCommandCaptureGroup: + return renderer.formatCompileCommand(group: group) + case let group as CompileErrorCaptureGroup: + return renderer.formatCompileError(group: group, additionalLines: additionalLines) + case let group as CompileStoryboardCaptureGroup: + return renderer.formatCompile(group: group) + case let group as CompileWarningCaptureGroup: + return renderer.formatCompileWarning(group: group, additionalLines: additionalLines) + case let group as CompileXibCaptureGroup: + return renderer.formatCompile(group: group) + case let group as CopyHeaderCaptureGroup: + return renderer.formatCopy(group: group) + case let group as CopyPlistCaptureGroup: + return renderer.formatCopy(group: group) + case let group as CopyStringsCaptureGroup: + return renderer.formatCopy(group: group) + case let group as CpresourceCaptureGroup: + return renderer.formatCopy(group: group) + case let group as CursorCaptureGroup: + return renderer.formatCursor(group: group) + case let group as DuplicateLocalizedStringKeyCaptureGroup: + return renderer.formatDuplicateLocalizedStringKey(group: group) + case let group as ExecutedWithoutSkippedCaptureGroup: + return renderer.formatExecutedWithoutSkipped(group: group) + case let group as ExecutedWithSkippedCaptureGroup: + return renderer.formatExecutedWithSkipped(group: group) + case let group as FailingTestCaptureGroup: + return renderer.formatFailingTest(group: group) + case let group as FatalErrorCaptureGroup: + return renderer.formatError(group: group) + case let group as FileMissingErrorCaptureGroup: + return renderer.formatFileMissingError(group: group) + case let group as GenerateCoverageDataCaptureGroup: + return renderer.formatGenerateCoverageData(group: group) + case let group as GeneratedCoverageReportCaptureGroup: + return renderer.formatCoverageReport(group: group) + case let group as GenerateDSYMCaptureGroup: + return renderer.formatGenerateDsym(group: group) + case let group as GenericWarningCaptureGroup: + return renderer.formatWarning(group: group) + case let group as LDErrorCaptureGroup: + return renderer.formatError(group: group) + case let group as LDWarningCaptureGroup: + return renderer.formatLdWarning(group: group) + case let group as LibtoolCaptureGroup: + return renderer.formatLibtool(group: group) + case let group as LinkerDuplicateSymbolsCaptureGroup: + return renderer.formatLinkerDuplicateSymbolsError(group: group) + case let group as LinkerDuplicateSymbolsLocationCaptureGroup: + return renderer.formatLinkerDuplicateSymbolsLocation(group: group) + case let group as LinkerUndefinedSymbolLocationCaptureGroup: + return renderer.formatLinkerUndefinedSymbolLocation(group: group) + case let group as LinkerUndefinedSymbolsCaptureGroup: + return renderer.formatLinkerUndefinedSymbolsError(group: group) + case let group as LinkingCaptureGroup: + return renderer.formatLinking(group: group) + case let group as ModuleIncludesErrorCaptureGroup: + return renderer.formatError(group: group) + case let group as NoCertificateCaptureGroup: + return renderer.formatError(group: group) + case let group as PackageCheckingOutCaptureGroup: + return renderer.formatPackageCheckingOut(group: group) + case let group as PackageFetchingCaptureGroup: + return renderer.formatPackageFetching(group: group) + case let group as PackageGraphResolvedItemCaptureGroup: + return renderer.formatPackageItem(group: group) + case _ as PackageGraphResolvingEndedCaptureGroup: + return renderer.formatPackageEnd() + case _ as PackageGraphResolvingStartCaptureGroup: + return renderer.formatPackageStart() + case let group as PackageUpdatingCaptureGroup: + return renderer.formatPackageUpdating(group: group) + case let group as ParallelTestCaseAppKitPassedCaptureGroup: + return renderer.formatParallelTestCaseAppKitPassed(group: group) + case let group as ParallelTestCaseFailedCaptureGroup: + return renderer.formatParallelTestCaseFailed(group: group) + case let group as ParallelTestCasePassedCaptureGroup: + return renderer.formatParallelTestCasePassed(group: group) + case let group as ParallelTestingFailedCaptureGroup: + return renderer.formatParallelTestingFailed(line: line, group: group) + case let group as ParallelTestingPassedCaptureGroup: + return renderer.formatParallelTestingPassed(line: line, group: group) + case let group as ParallelTestingStartedCaptureGroup: + return renderer.formatParallelTestingStarted(line: line, group: group) + case let group as ParallelTestSuiteStartedCaptureGroup: + return renderer.formatParallelTestSuiteStarted(group: group) + case let group as PbxcpCaptureGroup: + return renderer.formatCopy(group: group) + case let group as PhaseScriptExecutionCaptureGroup: + return renderer.formatPhaseScriptExecution(group: group) + case let group as PhaseSuccessCaptureGroup: + return renderer.formatPhaseSuccess(group: group) + case let group as PodsErrorCaptureGroup: + return renderer.formatError(group: group) + case _ as PreprocessCaptureGroup: +// return renderer.format(line: line, command: "Preprocessing", pattern: pattern, arguments: "$1") + // FIXME + return nil + case let group as ProcessInfoPlistCaptureGroup: + return renderer.formatProcessInfoPlist(group: group) + case let group as ProcessPchCaptureGroup: + return renderer.formatProcessPch(group: group) + case let group as ProcessPchCommandCaptureGroup: + return renderer.formatProcessPchCommand(group: group) + case let group as ProvisioningProfileRequiredCaptureGroup: + return renderer.formatError(group: group) + case let group as RestartingTestCaptureGroup: + return renderer.formatRestartingTest(line: line, group: group) + case let group as ShellCommandCaptureGroup: + return renderer.formatShellCommand(group: group) + case _ as SymbolReferencedFromCaptureGroup: + return renderer.formatCompleteError(line: line) + case let group as TestCaseMeasuredCaptureGroup: + return renderer.formatTestCaseMeasured(group: group) + case let group as TestCasePassedCaptureGroup: + return renderer.formatTestCasePassed(group: group) + case let group as TestCasePendingCaptureGroup: + return renderer.formatTestCasePending(group: group) + case let group as TestCaseStartedCaptureGroup: + return renderer.formatTestCasesStarted(group: group) + case let group as TestsRunCompletionCaptureGroup: + return renderer.formatTestsRunCompletion(group: group) + case let group as TestSuiteAllTestsFailedCaptureGroup: + return renderer.formatTestSuiteAllTestsFailed(group: group) + case let group as TestSuiteAllTestsPassedCaptureGroup: + return renderer.formatTestSuiteAllTestsPassed(group: group) + case let group as TestSuiteStartCaptureGroup: + return renderer.formatTestSuiteStart(group: group) + case let group as TestSuiteStartedCaptureGroup: + return renderer.formatTestSuiteStarted(group: group) + case let group as TIFFutilCaptureGroup: + return renderer.formatTIFFUtil(group: group) + case let group as TouchCaptureGroup: + return renderer.formatTouch(group: group) + case let group as UIFailingTestCaptureGroup: + return renderer.formatUIFailingTest(group: group) + case _ as UndefinedSymbolLocationCaptureGroup: + return renderer.formatCompleteWarning(line: line) + case let group as WillNotBeCodeSignedCaptureGroup: + return renderer.formatWillNotBeCodesignWarning(group: group) + case let group as WriteAuxiliaryFilesCaptureGroup: + return renderer.formatWriteAuxiliaryFiles(group: group) + case let group as WriteFileCaptureGroup: + return renderer.formatWriteFile(group: group) + case let group as XcodebuildErrorCaptureGroup: + return renderer.formatError(group: group) + default: + assertionFailure() + return nil + } } }