[Gradle][Cocoapods] Error messages for the case of invalid pod repo

#KT-42202

Merge-request: KT-MR-4790
This commit is contained in:
Viacheslav Kormushkin
2021-10-19 08:15:38 +00:00
committed by Space
parent 8466f26093
commit 9307757bb4
@@ -74,7 +74,12 @@ open class PodInstallTask : DefaultTask() {
runCommand(podInstallCommand, runCommand(podInstallCommand,
project.logger, project.logger,
errorHandler = { returnCode, output, _ -> errorHandler = { returnCode, output, _ ->
CocoapodsErrorHandlingUtil.handlePodInstallError(returnCode, output, project, frameworkName.get()) CocoapodsErrorHandlingUtil.handlePodInstallError(
podInstallCommand.joinToString(" "),
returnCode,
output,
project,
frameworkName.get())
}, },
exceptionHandler = { e: IOException -> exceptionHandler = { e: IOException ->
CocoapodsErrorHandlingUtil.handle(e, podInstallCommand) CocoapodsErrorHandlingUtil.handle(e, podInstallCommand)
@@ -112,16 +117,21 @@ open class PodDownloadUrlTask : DownloadCocoapodsTask() {
} }
@get:Internal @get:Internal
internal val permittedFileExtensions = listOf("zip", "tar", "tgz", "tbz", "txz", "gzip", "tar.gz", "tar.bz2", "tar.xz", "jar") internal val permittedFileExtensions = listOf("tar.gz", "tar.bz2", "tar.xz", "tar", "tgz", "tbz", "txz", "zip", "gzip", "jar")
@TaskAction @TaskAction
fun download() { fun download() {
val podLocation = podSource.get() val podLocation = podSource.get()
val fileName = podLocation.url.toString().substringAfterLast("/") val fileName = podLocation.url.toString().substringAfterLast("/")
val fileNameWithoutExtension = fileName.substringBefore(".") val permittedFileNameFormat = Regex(".*(\\.)(${permittedFileExtensions.joinToString("|") { it.replace(".", "\\.") }})")
val extension = fileName.substringAfter(".") val extension = permittedFileNameFormat.matchEntire(fileName)?.groups?.lastOrNull()?.value
require(permittedFileExtensions.contains(extension)) { "Unknown file extension" } require(extension != null) {
"""
$fileName has an unsupported file extension
Only the following extensions are supported: ${permittedFileExtensions.joinToString(", ")}
""".trimIndent()
}
val fileNameWithoutExtension = fileName.substringBeforeLast(".$extension")
val repo = setupRepo(podLocation) val repo = setupRepo(podLocation)
val dependency = createDependency(fileNameWithoutExtension, extension) val dependency = createDependency(fileNameWithoutExtension, extension)
val configuration = project.configurations.detachedConfiguration(dependency) val configuration = project.configurations.detachedConfiguration(dependency)
@@ -275,7 +285,16 @@ open class PodDownloadGitTask : DownloadCocoapodsTask() {
"${podspecLocation.url}", "${podspecLocation.url}",
podName.get() podName.get()
) )
runCommand(cloneAllCommand, project.logger) { directory(gitDir) } runCommand(
cloneAllCommand,
project.logger,
errorHandler = { retCode, error, _ ->
CocoapodsErrorHandlingUtil.handlePodDownloadError(podName.get(), cloneAllCommand.joinToString(" "), retCode, error)
},
processConfiguration = {
directory(gitDir)
}
)
} }
} }
@@ -328,7 +347,7 @@ private fun runCommand(
) )
check(retCode == 0) { check(retCode == 0) {
errorHandler?.invoke(retCode, inputText, process) errorHandler?.invoke(retCode, inputText.ifBlank { errorText }, process)
?: """ ?: """
|Executing of '${command.joinToString(" ")}' failed with code $retCode and message: |Executing of '${command.joinToString(" ")}' failed with code $retCode and message:
| |
@@ -403,7 +422,7 @@ open class PodGenTask : DefaultTask() {
CocoapodsErrorHandlingUtil.handle(e, podGenProcessArgs) CocoapodsErrorHandlingUtil.handle(e, podGenProcessArgs)
}, },
errorHandler = { retCode, output, _ -> errorHandler = { retCode, output, _ ->
CocoapodsErrorHandlingUtil.handlePodGenError(retCode, output, family) CocoapodsErrorHandlingUtil.handlePodGenError(podGenProcessArgs.joinToString(" "), retCode, output, family)
}, },
processConfiguration = { processConfiguration = {
directory(syntheticDir) directory(syntheticDir)
@@ -589,6 +608,8 @@ private object CocoapodsErrorHandlingUtil {
|'${command.take(2).joinToString(" ")}' command failed with an exception: |'${command.take(2).joinToString(" ")}' command failed with an exception:
| ${e.message} | ${e.message}
| |
| Full command: ${command.joinToString(" ")}
|
| Possible reason: CocoaPods is not installed | Possible reason: CocoaPods is not installed
| Please check that CocoaPods v1.10 or above and cocoapods-generate plugin are installed. | Please check that CocoaPods v1.10 or above and cocoapods-generate plugin are installed.
| |
@@ -604,25 +625,26 @@ private object CocoapodsErrorHandlingUtil {
} }
} }
fun handlePodInstallError(retCode: Int, error: String, project: Project, frameworkName: String): String { fun handlePodInstallError(command: String, retCode: Int, error: String, project: Project, frameworkName: String): String {
val specReposMessages = retrieveSpecRepos(project)?.let { MissingSpecReposMessage(it).missingMessage } val specReposMessages = retrieveSpecRepos(project)?.let { MissingSpecReposMessage(it).missingMessage }
val cocoapodsMessages = retrievePods(project)?.map { MissingCocoapodsMessage(it, project).missingMessage } val cocoapodsMessages = retrievePods(project)?.map { MissingCocoapodsMessage(it, project).missingMessage }
return listOfNotNull( return listOfNotNull(
"'pod install' command failed with code $retCode.", "'pod install' command failed with code $retCode.",
"Full command: $command",
"Error message:", "Error message:",
error, error,
specReposMessages?.let { specReposMessages?.let {
""" """
| Please, check that podfile contains following lines in header: | Please, check that podfile contains following lines in header:
| $it | $it
| |
""".trimMargin() """.trimMargin()
}, },
cocoapodsMessages?.let { cocoapodsMessages?.let {
""" """
| Please, check that each target depended on $frameworkName contains following dependencies: | Please, check that each target depended on $frameworkName contains following dependencies:
| ${it.joinToString("\n")} | ${it.joinToString("\n")}
| |
""".trimMargin() """.trimMargin()
} }
@@ -630,12 +652,14 @@ private object CocoapodsErrorHandlingUtil {
).joinToString("\n") ).joinToString("\n")
} }
fun handlePodGenError(retCode: Int, error: String, family: Family): String? { fun handlePodGenError(command: String, retCode: Int, error: String, family: Family): String? {
var message = """ var message = """
|'pod gen' command failed with return code: $retCode |'pod gen' command failed with return code: $retCode
| |
| Error: ${error.lines().filter { it.contains("[!]") }?.joinToString("\n")} | Full command: $command
|
| Error: ${error.lines().filter { it.contains("[!]") }.joinToString("\n")}
|
""".trimMargin() """.trimMargin()
if (error.contains("Unknown command: `gen`")) { if (error.contains("Unknown command: `gen`")) {
@@ -683,4 +707,17 @@ private object CocoapodsErrorHandlingUtil {
} }
return null return null
} }
fun handlePodDownloadError(podName: String, command: String, retCode: Int, error: String): String {
return """
|'git clone' command failed with return code: $retCode
|
| Full command: $command
|
| Error: ${error.lines().filter { it.contains("fatal", true) }.joinToString("\n")}
|
| Possible reason: source of a pod '$podName' is invalid or inaccessible
|
""".trimMargin()
}
} }