[KT-53392] Cocoapods: remove downloading pods from url.
This commit is contained in:
committed by
Space
parent
fdac190511
commit
81ad6140e1
+6
-180
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.gradle.BaseGradleIT
|
||||
import org.jetbrains.kotlin.gradle.GradleVersionRequired
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.DUMMY_FRAMEWORK_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.POD_BUILD_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.POD_DOWNLOAD_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.POD_GEN_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.POD_IMPORT_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.POD_INSTALL_TASK_NAME
|
||||
@@ -29,7 +28,6 @@ import java.io.File
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.test.assertContentEquals
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.test.fail
|
||||
@@ -65,7 +63,6 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
|
||||
private val dummyTaskName = ":$DUMMY_FRAMEWORK_TASK_NAME"
|
||||
private val podspecTaskName = ":$POD_SPEC_TASK_NAME"
|
||||
private val podDownloadTaskName = ":$POD_DOWNLOAD_TASK_NAME"
|
||||
private val podGenTaskName = ":$POD_GEN_TASK_NAME"
|
||||
private val podBuildTaskName = ":$POD_BUILD_TASK_NAME"
|
||||
private val podSetupBuildTaskName = ":$POD_SETUP_BUILD_TASK_NAME"
|
||||
@@ -76,21 +73,13 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
private val defaultPodRepo = "https://github.com/AFNetworking/AFNetworking"
|
||||
private val defaultPodName = "AFNetworking"
|
||||
private val defaultLibraryPodName = "YandexMapKit"
|
||||
private val downloadUrlPodName = "podspecWithFilesExample"
|
||||
private val downloadUrlRepoName = "https://github.com/alozhkin/podspecWithFilesExample/raw/master"
|
||||
private val defaultTarget = "IOS"
|
||||
private val defaultFamily = "IOS"
|
||||
private val defaultSDK = "iphonesimulator"
|
||||
private val defaultPodDownloadTaskName = podDownloadFullTaskName()
|
||||
private val defaultPodGenTaskName = podGenFullTaskName()
|
||||
private val defaultBuildTaskName = podBuildFullTaskName()
|
||||
private val defaultSetupBuildTaskName = podSetupBuildFullTaskName()
|
||||
private val defaultCinteropTaskName = cinteropTaskName + defaultPodName + defaultTarget
|
||||
private val downloadUrlTaskName =
|
||||
podDownloadTaskName + downloadUrlPodName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
|
||||
|
||||
private fun podDownloadFullTaskName(podName: String = defaultPodName) =
|
||||
podDownloadTaskName + podName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
|
||||
|
||||
private fun podGenFullTaskName(familyName: String = defaultFamily) =
|
||||
podGenTaskName + familyName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
|
||||
@@ -295,10 +284,7 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
with(project.gradleBuildScript()) {
|
||||
addPod(defaultPodName, produceGitBlock(defaultPodRepo, branchName = branch, commitName = commit))
|
||||
}
|
||||
hooks.addHook {
|
||||
checkGitRepo(commitName = commit)
|
||||
}
|
||||
project.testDownload(listOf(defaultPodRepo))
|
||||
project.testImportWithAsserts(listOf(defaultPodRepo))
|
||||
}
|
||||
|
||||
// tag priority is bigger than branch priority
|
||||
@@ -309,39 +295,15 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
with(project.gradleBuildScript()) {
|
||||
addPod(defaultPodName, produceGitBlock(defaultPodRepo, branchName = branch, tagName = tag))
|
||||
}
|
||||
hooks.addHook {
|
||||
checkGitRepo(tagName = tag)
|
||||
}
|
||||
project.testDownload(listOf(defaultPodRepo))
|
||||
project.testImportWithAsserts(listOf(defaultPodRepo))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPodDownloadUrlZip() = doTestPodDownloadUrl("zip")
|
||||
|
||||
@Test
|
||||
fun testPodDownloadUrlTar() = doTestPodDownloadUrl("tar")
|
||||
|
||||
@Test
|
||||
fun testPodDownloadUrlGZ() = doTestPodDownloadUrl("tar.gz")
|
||||
|
||||
@Test
|
||||
fun testPodDownloadUrlBZ2() = doTestPodDownloadUrl("tar.bz2")
|
||||
|
||||
@Test
|
||||
fun testPodDownloadUrlJar() = doTestPodDownloadUrl("jar")
|
||||
|
||||
@Test
|
||||
fun testPodDownloadUrlWrongName() = doTestPodDownloadUrl(fileExtension = "zip", archiveName = "wrongName")
|
||||
|
||||
@Test
|
||||
fun testDownloadAndImport() {
|
||||
val tag = "4.0.0"
|
||||
with(project.gradleBuildScript()) {
|
||||
addPod(defaultPodName, produceGitBlock(defaultPodRepo, tagName = tag))
|
||||
}
|
||||
hooks.addHook {
|
||||
checkGitRepo(tagName = tag)
|
||||
}
|
||||
project.testImportWithAsserts(listOf(defaultPodRepo))
|
||||
}
|
||||
|
||||
@@ -354,7 +316,7 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
.joinToString(separator = File.separator)
|
||||
)
|
||||
}
|
||||
project.test(":kotlin-library:podDownload")
|
||||
project.test(":kotlin-library:tasks")
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -389,19 +351,10 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
project.testWithWrapper(dummyTaskName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPodDownloadUTDWithoutPods() {
|
||||
hooks.addHook {
|
||||
assertTasksUpToDate(podDownloadTaskName)
|
||||
}
|
||||
project.testWithWrapper(podDownloadTaskName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun basicUTDTest() {
|
||||
val tasks = listOf(
|
||||
podspecTaskName,
|
||||
defaultPodDownloadTaskName,
|
||||
defaultPodGenTaskName,
|
||||
defaultSetupBuildTaskName,
|
||||
defaultBuildTaskName,
|
||||
@@ -455,14 +408,12 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
hooks.rewriteHooks {
|
||||
assertTasksExecuted(
|
||||
podspecTaskName,
|
||||
podDownloadFullTaskName(anotherPodName),
|
||||
defaultPodGenTaskName,
|
||||
podSetupBuildFullTaskName(anotherPodName),
|
||||
podBuildFullTaskName(anotherPodName),
|
||||
cinteropFullTaskName(anotherPodName)
|
||||
)
|
||||
assertTasksUpToDate(
|
||||
defaultPodDownloadTaskName,
|
||||
defaultSetupBuildTaskName,
|
||||
defaultBuildTaskName,
|
||||
defaultCinteropTaskName
|
||||
@@ -476,14 +427,12 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
hooks.rewriteHooks {
|
||||
assertTasksNotRegisteredByPrefix(
|
||||
listOf(
|
||||
podDownloadFullTaskName(anotherPodName),
|
||||
podBuildFullTaskName(anotherPodName),
|
||||
cinteropFullTaskName(anotherPodName)
|
||||
)
|
||||
)
|
||||
assertTasksUpToDate(
|
||||
defaultBuildTaskName,
|
||||
defaultPodDownloadTaskName,
|
||||
defaultSetupBuildTaskName,
|
||||
defaultCinteropTaskName
|
||||
)
|
||||
@@ -523,7 +472,6 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
)
|
||||
assertTasksUpToDate(
|
||||
podspecTaskName,
|
||||
defaultPodDownloadTaskName,
|
||||
defaultPodGenTaskName,
|
||||
defaultSetupBuildTaskName,
|
||||
defaultBuildTaskName,
|
||||
@@ -548,7 +496,6 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
)
|
||||
assertTasksUpToDate(
|
||||
podspecTaskName,
|
||||
defaultPodDownloadTaskName,
|
||||
defaultPodGenTaskName,
|
||||
defaultSetupBuildTaskName,
|
||||
defaultBuildTaskName,
|
||||
@@ -593,34 +540,6 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
project.testWithWrapper(podspecTaskName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUTDDownload() {
|
||||
val gitRepo = downloadUrlRepoName.substringBeforeLast("/").substringBeforeLast("/")
|
||||
with(project.gradleBuildScript()) {
|
||||
addPod(downloadUrlPodName, produceGitBlock(repo = gitRepo))
|
||||
}
|
||||
hooks.addHook {
|
||||
assertTasksExecuted(downloadUrlTaskName)
|
||||
}
|
||||
project.testDownload(listOf(gitRepo))
|
||||
with(project.gradleBuildScript()) {
|
||||
changePod(downloadUrlPodName, produceGitBlock(repo = gitRepo, commitName = "f52f035018b4f3fe253d50ce85a7e0652a62ee9b"))
|
||||
}
|
||||
project.testDownload(listOf(gitRepo))
|
||||
hooks.rewriteHooks {
|
||||
assertTasksUpToDate(downloadUrlTaskName)
|
||||
}
|
||||
project.testDownload(listOf(gitRepo))
|
||||
val podArchivePath = "$downloadUrlRepoName/$downloadUrlPodName.tar.gz"
|
||||
with(project.gradleBuildScript()) {
|
||||
changePod(downloadUrlPodName, "source = url(\"$podArchivePath\")")
|
||||
}
|
||||
hooks.rewriteHooks {
|
||||
assertTasksExecuted(downloadUrlTaskName)
|
||||
}
|
||||
project.testDownload(listOf(podArchivePath))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUTDPodGen() {
|
||||
with(project.gradleBuildScript()) {
|
||||
@@ -661,17 +580,6 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
}
|
||||
project.testImport()
|
||||
|
||||
val repo = "$downloadUrlRepoName/$downloadUrlPodName.tar.gz"
|
||||
with(project.gradleBuildScript()) {
|
||||
addPod(downloadUrlPodName, "source = url(\"$repo\")")
|
||||
}
|
||||
val urlTaskName = podBuildFullTaskName(downloadUrlPodName)
|
||||
hooks.rewriteHooks {
|
||||
assertTasksUpToDate(defaultBuildTaskName)
|
||||
assertTasksExecuted(urlTaskName)
|
||||
}
|
||||
project.testImport()
|
||||
|
||||
val anotherTarget = "MacosX64"
|
||||
val anotherSdk = "macosx"
|
||||
with(project.gradleBuildScript()) {
|
||||
@@ -679,15 +587,14 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
appendToKotlinBlock(anotherTarget.replaceFirstChar { it.lowercase(Locale.getDefault()) } + "()")
|
||||
}
|
||||
val anotherSdkDefaultPodTaskName = podBuildFullTaskName(sdkName = anotherSdk)
|
||||
val anotherTargetUrlTaskName = podBuildFullTaskName(downloadUrlPodName, anotherSdk)
|
||||
hooks.rewriteHooks {
|
||||
assertTasksUpToDate(defaultBuildTaskName, urlTaskName)
|
||||
assertTasksExecuted(anotherSdkDefaultPodTaskName, anotherTargetUrlTaskName)
|
||||
assertTasksUpToDate(defaultBuildTaskName)
|
||||
assertTasksExecuted(anotherSdkDefaultPodTaskName)
|
||||
}
|
||||
project.testImport()
|
||||
|
||||
hooks.rewriteHooks {
|
||||
assertTasksUpToDate(defaultBuildTaskName, urlTaskName, anotherSdkDefaultPodTaskName, anotherTargetUrlTaskName)
|
||||
assertTasksUpToDate(defaultBuildTaskName, anotherSdkDefaultPodTaskName)
|
||||
}
|
||||
project.testImport()
|
||||
}
|
||||
@@ -726,34 +633,12 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
with(project.gradleBuildScript()) {
|
||||
addPod(defaultPodName, produceGitBlock(defaultPodRepo, tagName = tag))
|
||||
}
|
||||
hooks.addHook {
|
||||
checkGitRepo(tagName = tag)
|
||||
}
|
||||
project.testImportWithAsserts(listOf(defaultPodRepo))
|
||||
}
|
||||
|
||||
|
||||
// other tests
|
||||
|
||||
@Test
|
||||
fun testDownloadUrlTestSupportDashInNames() {
|
||||
val fileExtension = "tar.gz"
|
||||
val podName = "Pod-with-dashes"
|
||||
val repoPath = "https://github.com/alozhkin/Pod-with-dashes/raw/master"
|
||||
val flatten = true
|
||||
val repo = "$repoPath/$podName.$fileExtension"
|
||||
with(project.gradleBuildScript()) {
|
||||
addPod(
|
||||
podName,
|
||||
"source = url(\"$repo\", $flatten)"
|
||||
)
|
||||
}
|
||||
hooks.addHook {
|
||||
assertTrue(url().resolve(podName).exists())
|
||||
}
|
||||
project.testImportWithAsserts(listOf(repo))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun supportPodsWithDependencies() {
|
||||
with(project.gradleBuildScript()) {
|
||||
@@ -1077,16 +962,6 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
// paths
|
||||
|
||||
private fun CompiledProject.url() = externalSources().resolve("url")
|
||||
|
||||
private fun CompiledProject.git() = externalSources().resolve("git")
|
||||
|
||||
private fun CompiledProject.externalSources() =
|
||||
fileInWorkingDir("build").resolve("cocoapods").resolve("externalSources")
|
||||
|
||||
|
||||
// test configuration phase
|
||||
|
||||
private class CustomHooks {
|
||||
@@ -1143,26 +1018,6 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
with(project.gradleBuildScript()) {
|
||||
addPod(pod, produceGitBlock(repo, branch, commit, tag))
|
||||
}
|
||||
hooks.addHook {
|
||||
checkGitRepo(branch, commit, tag, pod)
|
||||
}
|
||||
project.testDownload(listOf(repo))
|
||||
}
|
||||
|
||||
private fun doTestPodDownloadUrl(
|
||||
fileExtension: String,
|
||||
podName: String = downloadUrlPodName,
|
||||
repoPath: String = downloadUrlRepoName,
|
||||
archiveName: String = podName,
|
||||
flatten: Boolean = false
|
||||
) {
|
||||
val repo = "$repoPath/$archiveName.$fileExtension"
|
||||
with(project.gradleBuildScript()) {
|
||||
addPod(podName, "source = url(\"$repo\", $flatten)")
|
||||
}
|
||||
hooks.addHook {
|
||||
assertTrue(url().resolve(podName).exists())
|
||||
}
|
||||
project.testImportWithAsserts(listOf(repo))
|
||||
}
|
||||
|
||||
@@ -1186,16 +1041,6 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
testSynthetic(podImportTaskName, *args)
|
||||
}
|
||||
|
||||
private fun Project.testDownload(
|
||||
repos: List<String>,
|
||||
vararg args: String
|
||||
) {
|
||||
for (repo in repos) {
|
||||
assumeTrue(isRepoAvailable(repo))
|
||||
}
|
||||
test(podDownloadTaskName, *args)
|
||||
}
|
||||
|
||||
private fun Project.testSynthetic(
|
||||
taskName: String,
|
||||
vararg args: String
|
||||
@@ -1293,25 +1138,6 @@ class CocoaPodsIT : BaseGradleIT() {
|
||||
|
||||
// proposition phase
|
||||
|
||||
private fun CompiledProject.checkGitRepo(
|
||||
branchName: String? = null,
|
||||
commitName: String? = null,
|
||||
tagName: String? = null,
|
||||
aPodDownloadName: String = defaultPodName,
|
||||
podspecName: String = aPodDownloadName.split("/")[0]
|
||||
) {
|
||||
val gitDir = git().resolve(aPodDownloadName.validTaskName)
|
||||
val podspecFile = gitDir.resolve("$podspecName.podspec")
|
||||
assertTrue(podspecFile.exists())
|
||||
if (tagName != null) {
|
||||
checkTag(gitDir, tagName)
|
||||
}
|
||||
checkPresentCommits(gitDir, commitName)
|
||||
if (branchName != null) {
|
||||
checkBranch(gitDir, branchName)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkTag(gitDir: File, tagName: String) {
|
||||
runCommand(
|
||||
gitDir,
|
||||
|
||||
+12
-30
@@ -16,9 +16,9 @@ import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.Cocoapods
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBinary
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
|
||||
import org.jetbrains.kotlin.gradle.targets.native.tasks.PodDownloadUrlTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.addArg
|
||||
import org.jetbrains.kotlin.gradle.tasks.addArgs
|
||||
import org.jetbrains.kotlin.gradle.utils.relativeToRoot
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import java.io.File
|
||||
import java.net.URI
|
||||
@@ -304,19 +304,6 @@ abstract class CocoapodsExtension @Inject constructor(private val project: Proje
|
||||
@Input
|
||||
override fun getName(): String = name
|
||||
|
||||
/**
|
||||
* Url to archived (tar, jar, zip) pod folder, that should contain the podspec file and all sources required by it.
|
||||
*
|
||||
* Archive name should match pod name.
|
||||
*
|
||||
* @param url url to tar, jar or zip archive.
|
||||
* @param flatten does archive contains subdirectory that needs to be expanded
|
||||
* @param isAllowInsecureProtocol enables communication with a repository over an insecure HTTP connection.
|
||||
*/
|
||||
@Deprecated("Will be removed in a 1.8 version. Use pods published as a git repository instead")
|
||||
@JvmOverloads
|
||||
fun url(url: String, flatten: Boolean = false, isAllowInsecureProtocol: Boolean = false): PodLocation = Url(URI(url), flatten, isAllowInsecureProtocol)
|
||||
|
||||
/**
|
||||
* Path to local pod
|
||||
*/
|
||||
@@ -347,26 +334,15 @@ abstract class CocoapodsExtension @Inject constructor(private val project: Proje
|
||||
}
|
||||
|
||||
sealed class PodLocation {
|
||||
internal abstract fun getLocalPath(project: Project, podName: String): String
|
||||
|
||||
data class Url(
|
||||
@get:Input val url: URI,
|
||||
@get:Input var flatten: Boolean,
|
||||
@get:Input var isAllowInsecureProtocol: Boolean
|
||||
) : PodLocation() {
|
||||
override fun getLocalPath(project: Project, podName: String): String {
|
||||
return project.cocoapodsBuildDirs.externalSources("url").resolve(podName).absolutePath
|
||||
}
|
||||
}
|
||||
internal abstract fun getPodSourcePath(): String
|
||||
|
||||
data class Path(
|
||||
@get:InputDirectory
|
||||
@get:IgnoreEmptyDirectories
|
||||
val dir: File
|
||||
) : PodLocation() {
|
||||
override fun getLocalPath(project: Project, podName: String): String {
|
||||
return dir.absolutePath
|
||||
}
|
||||
@Internal
|
||||
override fun getPodSourcePath() = ":path => '${dir.absolutePath}'"
|
||||
}
|
||||
|
||||
data class Git(
|
||||
@@ -375,8 +351,14 @@ abstract class CocoapodsExtension @Inject constructor(private val project: Proje
|
||||
@get:Input @get:Optional var tag: String? = null,
|
||||
@get:Input @get:Optional var commit: String? = null
|
||||
) : PodLocation() {
|
||||
override fun getLocalPath(project: Project, podName: String): String {
|
||||
return project.cocoapodsBuildDirs.externalSources("git").resolve(podName).absolutePath
|
||||
@Internal
|
||||
override fun getPodSourcePath() = buildString {
|
||||
append(":git => '$url'")
|
||||
when {
|
||||
branch != null -> append(", :branch => '$branch'")
|
||||
tag != null -> append(", :tag => '$tag'")
|
||||
commit != null -> append(", :commit => '$commit'")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-47
@@ -18,8 +18,6 @@ import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.addExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.CocoapodsDependency
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.CocoapodsDependency.PodLocation.Git
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.CocoapodsDependency.PodLocation.Url
|
||||
import org.jetbrains.kotlin.gradle.plugin.ide.Idea222Api
|
||||
import org.jetbrains.kotlin.gradle.plugin.ide.ideaImportDependsOn
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
|
||||
@@ -62,13 +60,8 @@ internal class CocoapodsBuildDirs(val project: Project) {
|
||||
|
||||
fun synthetic(family: Family) = synthetic.resolve(family.name)
|
||||
|
||||
val externalSources: File
|
||||
get() = root.resolve("externalSources")
|
||||
|
||||
val publish: File = root.resolve("publish")
|
||||
|
||||
fun externalSources(fileName: String) = externalSources.resolve(fileName)
|
||||
|
||||
fun fatFramework(buildType: NativeBuildType) =
|
||||
root.resolve("fat-frameworks/${buildType.getName()}")
|
||||
}
|
||||
@@ -93,12 +86,6 @@ private fun String.toBuildDependenciesTaskName(pod: CocoapodsDependency): String
|
||||
this
|
||||
)
|
||||
|
||||
private val CocoapodsDependency.toPodDownloadTaskName: String
|
||||
get() = lowerCamelCaseName(
|
||||
KotlinCocoapodsPlugin.POD_DOWNLOAD_TASK_NAME,
|
||||
name.asValidTaskName()
|
||||
)
|
||||
|
||||
private val KotlinNativeTarget.toValidSDK: String
|
||||
get() = when (konanTarget) {
|
||||
IOS_X64, IOS_SIMULATOR_ARM64 -> "iphonesimulator"
|
||||
@@ -443,44 +430,13 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
||||
}
|
||||
}
|
||||
|
||||
private fun registerPodDownloadTask(
|
||||
project: Project,
|
||||
cocoapodsExtension: CocoapodsExtension
|
||||
) {
|
||||
val downloadAllTask = project.tasks.register(POD_DOWNLOAD_TASK_NAME) {
|
||||
it.group = TASK_GROUP
|
||||
it.description = "Downloads CocoaPods dependencies from external sources"
|
||||
}
|
||||
|
||||
cocoapodsExtension.pods.all { pod ->
|
||||
val downloadPodTask = when (val podSource = pod.source) {
|
||||
is Git -> project.tasks.register(pod.toPodDownloadTaskName, PodDownloadGitTask::class.java) {
|
||||
it.podName = project.provider { pod.name.asValidTaskName() }
|
||||
it.podSource = project.provider<Git> { podSource }
|
||||
}
|
||||
is Url -> {
|
||||
SingleWarningPerBuild.show(project, "Direct pod downloading by url will be removed in a 1.8 version. Use pods published as a git repository instead.")
|
||||
project.tasks.register(pod.toPodDownloadTaskName, PodDownloadUrlTask::class.java) {
|
||||
it.podName = project.provider { pod.name.asValidTaskName() }
|
||||
it.podSource = project.provider<Url> { podSource }
|
||||
}
|
||||
}
|
||||
else -> return@all
|
||||
}
|
||||
|
||||
downloadAllTask.dependsOn(downloadPodTask)
|
||||
}
|
||||
}
|
||||
|
||||
private fun registerPodGenTask(
|
||||
project: Project, kotlinExtension: KotlinMultiplatformExtension, cocoapodsExtension: CocoapodsExtension
|
||||
) {
|
||||
val families = mutableSetOf<Family>()
|
||||
|
||||
val podspecTaskProvider = project.tasks.named(POD_SPEC_TASK_NAME, PodspecTask::class.java)
|
||||
val downloadPods = project.tasks.named(POD_DOWNLOAD_TASK_NAME)
|
||||
kotlinExtension.supportedTargets().all { target ->
|
||||
|
||||
val family = target.konanTarget.family
|
||||
if (family in families) {
|
||||
return@all
|
||||
@@ -504,7 +460,6 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
||||
it.family = family
|
||||
it.platformSettings = platformSettings
|
||||
it.pods.set(cocoapodsExtension.pods)
|
||||
it.dependsOn(downloadPods)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -735,7 +690,6 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
||||
checkFrameworkLinkingType(project, kotlinExtension)
|
||||
registerPodspecTask(project, cocoapodsExtension)
|
||||
|
||||
registerPodDownloadTask(project, cocoapodsExtension)
|
||||
registerPodGenTask(project, kotlinExtension, cocoapodsExtension)
|
||||
registerPodInstallTask(project, cocoapodsExtension)
|
||||
registerPodSetupBuildTasks(project, kotlinExtension, cocoapodsExtension)
|
||||
@@ -763,7 +717,6 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
||||
const val POD_SPEC_TASK_NAME = "podspec"
|
||||
const val DUMMY_FRAMEWORK_TASK_NAME = "generateDummyFramework"
|
||||
const val POD_INSTALL_TASK_NAME = "podInstall"
|
||||
const val POD_DOWNLOAD_TASK_NAME = "podDownload"
|
||||
const val POD_GEN_TASK_NAME = "podGen"
|
||||
const val POD_SETUP_BUILD_TASK_NAME = "podSetupBuild"
|
||||
const val POD_BUILD_TASK_NAME = "podBuild"
|
||||
|
||||
+5
-3
@@ -19,9 +19,11 @@ class MissingSpecReposMessage(override val missingInfo: SpecRepos) : MissingInfo
|
||||
get() = missingInfo.getAll().joinToString(separator = "\n") { "source '$it'" }
|
||||
}
|
||||
|
||||
class MissingCocoapodsMessage(override val missingInfo: CocoapodsDependency, private val project: Project) :
|
||||
MissingInfoMessage<CocoapodsDependency> {
|
||||
class MissingCocoapodsMessage(
|
||||
override val missingInfo: CocoapodsDependency,
|
||||
private val project: Project
|
||||
) : MissingInfoMessage<CocoapodsDependency> {
|
||||
override val missingMessage: String
|
||||
get() = "pod '${missingInfo.name}'${missingInfo.source?.let { ", :path => '${it.getLocalPath(project, missingInfo.name)}'" } ?: ""}"
|
||||
get() = "pod '${missingInfo.name}'${missingInfo.source?.let { ", ${it.getPodSourcePath()}" }.orEmpty()}"
|
||||
}
|
||||
|
||||
|
||||
+1
-222
@@ -114,213 +114,6 @@ open class PodInstallTask : CocoapodsTask() {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class DownloadCocoapodsTask : CocoapodsTask() {
|
||||
@get:Input
|
||||
internal lateinit var podName: Provider<String>
|
||||
}
|
||||
|
||||
open class PodDownloadUrlTask : DownloadCocoapodsTask() {
|
||||
companion object {
|
||||
private val permittedFileExtensions = listOf("tar.gz", "tar.bz2", "tar.xz", "tar", "tgz", "tbz", "txz", "zip", "gzip", "jar")
|
||||
|
||||
internal fun getFileExtension(fileName: String): String? {
|
||||
val permittedFileNameFormat = Regex(
|
||||
".*(\\.)(${permittedFileExtensions.joinToString("|") { it.replace(".", "\\.") }})"
|
||||
)
|
||||
return permittedFileNameFormat.matchEntire(fileName)?.groups?.lastOrNull()?.value
|
||||
}
|
||||
}
|
||||
|
||||
@get:Nested
|
||||
internal lateinit var podSource: Provider<Url>
|
||||
|
||||
@get:Internal
|
||||
internal val urlDir = project.cocoapodsBuildDirs.externalSources("url")
|
||||
|
||||
|
||||
@get:OutputDirectory
|
||||
internal val podSourceDir = project.provider {
|
||||
urlDir.resolve(podName.get())
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun download() {
|
||||
val podLocation = podSource.get()
|
||||
val fileName = podLocation.url.toString().substringAfterLast("/")
|
||||
val extension = getFileExtension(fileName)
|
||||
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 dependency = createDependency(fileNameWithoutExtension, extension)
|
||||
val configuration = project.configurations.detachedConfiguration(dependency)
|
||||
val artifact = configuration.singleFile
|
||||
copyArtifactToUrlDir(artifact, extension, podLocation.flatten)
|
||||
project.repositories.remove(repo)
|
||||
}
|
||||
|
||||
private fun setupRepo(podUrl: CocoapodsDependency.PodLocation.Url): ArtifactRepository {
|
||||
return project.repositories.ivy { repo ->
|
||||
val repoUrl = podUrl.url.toString().substringBeforeLast("/")
|
||||
repo.setUrl(repoUrl)
|
||||
repo.patternLayout {
|
||||
it.artifact("[artifact].[ext]")
|
||||
}
|
||||
repo.metadataSources {
|
||||
it.artifact()
|
||||
}
|
||||
repo.isAllowInsecureProtocol = podUrl.isAllowInsecureProtocol
|
||||
}
|
||||
}
|
||||
|
||||
private fun createDependency(fileNameWithoutExtension: String, extension: String) = project.dependencies.create(
|
||||
mapOf(
|
||||
"name" to fileNameWithoutExtension,
|
||||
"version" to "1.0",
|
||||
"ext" to extension
|
||||
)
|
||||
)
|
||||
|
||||
private fun copyArtifactToUrlDir(artifact: File, extension: String, flatten: Boolean) {
|
||||
val archiveTree = archiveTree(artifact.absolutePath, extension)
|
||||
project.copy {
|
||||
val destinationDir = podSourceDir.get()
|
||||
it.into(destinationDir)
|
||||
it.from(archiveTree)
|
||||
if (extension == "jar") {
|
||||
it.exclude("META-INF/")
|
||||
}
|
||||
if (!flatten) {
|
||||
it.eachFile { file ->
|
||||
file.relativePath = RelativePath(true, *file.relativePath.segments.drop(1).toTypedArray())
|
||||
}
|
||||
it.includeEmptyDirs = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun archiveTree(path: String, extension: String): FileTree {
|
||||
return if (extension == "zip" || extension == "jar") {
|
||||
project.zipTree(path)
|
||||
} else {
|
||||
project.tarTree(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class PodDownloadGitTask : DownloadCocoapodsTask() {
|
||||
|
||||
@get:Nested
|
||||
internal lateinit var podSource: Provider<Git>
|
||||
|
||||
@get:Internal
|
||||
internal val gitDir = project.cocoapodsBuildDirs.externalSources("git")
|
||||
|
||||
@get:OutputDirectory
|
||||
internal val repo = project.provider {
|
||||
gitDir.resolve(podName.get())
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun download() {
|
||||
repo.get().deleteRecursively()
|
||||
val git = podSource.get()
|
||||
val branch = git.tag ?: git.branch
|
||||
val commit = git.commit
|
||||
val url = git.url
|
||||
try {
|
||||
when {
|
||||
commit != null -> {
|
||||
retrieveCommit(url, commit)
|
||||
}
|
||||
branch != null -> {
|
||||
cloneShallow(url, branch)
|
||||
}
|
||||
else -> {
|
||||
cloneHead(git)
|
||||
}
|
||||
}
|
||||
} catch (e: IllegalStateException) {
|
||||
fallback(git)
|
||||
}
|
||||
}
|
||||
|
||||
private fun retrieveCommit(url: URI, commit: String) {
|
||||
val logger = project.logger
|
||||
val initCommand = listOf(
|
||||
"git",
|
||||
"init"
|
||||
)
|
||||
val repo = repo.get()
|
||||
repo.mkdir()
|
||||
runCommand(initCommand, logger) { directory(repo) }
|
||||
|
||||
val fetchCommand = listOf(
|
||||
"git",
|
||||
"fetch",
|
||||
"--depth", "1",
|
||||
"$url",
|
||||
commit
|
||||
)
|
||||
runCommand(fetchCommand, logger) { directory(repo) }
|
||||
|
||||
val checkoutCommand = listOf(
|
||||
"git",
|
||||
"checkout",
|
||||
"FETCH_HEAD"
|
||||
)
|
||||
runCommand(checkoutCommand, logger) { directory(repo) }
|
||||
}
|
||||
|
||||
private fun cloneShallow(url: URI, branch: String) {
|
||||
val shallowCloneCommand = listOf(
|
||||
"git",
|
||||
"clone",
|
||||
"$url",
|
||||
podName.get(),
|
||||
"--branch", branch,
|
||||
"--depth", "1"
|
||||
)
|
||||
runCommand(shallowCloneCommand, project.logger) { directory(gitDir) }
|
||||
}
|
||||
|
||||
private fun cloneHead(podspecLocation: Git) {
|
||||
val cloneHeadCommand = listOf(
|
||||
"git",
|
||||
"clone",
|
||||
"${podspecLocation.url}",
|
||||
podName.get(),
|
||||
"--depth", "1"
|
||||
)
|
||||
runCommand(cloneHeadCommand, project.logger) { directory(gitDir) }
|
||||
}
|
||||
|
||||
private fun fallback(podspecLocation: Git) {
|
||||
// removing any traces of other commands
|
||||
gitDir.resolve(podName.get()).deleteRecursively()
|
||||
val cloneAllCommand = listOf(
|
||||
"git",
|
||||
"clone",
|
||||
"${podspecLocation.url}",
|
||||
podName.get()
|
||||
)
|
||||
runCommand(
|
||||
cloneAllCommand,
|
||||
project.logger,
|
||||
errorHandler = { retCode, error, _ ->
|
||||
CocoapodsErrorHandlingUtil.handlePodDownloadError(podName.get(), cloneAllCommand.joinToString(" "), retCode, error)
|
||||
},
|
||||
processConfiguration = {
|
||||
directory(gitDir)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun runCommand(
|
||||
command: List<String>,
|
||||
logger: Logger,
|
||||
@@ -497,21 +290,7 @@ open class PodGenTask : CocoapodsTask() {
|
||||
val source = it.source
|
||||
|
||||
if (source != null) {
|
||||
when (source) {
|
||||
is Path, is Url -> {
|
||||
val path = source.getLocalPath(project, it.name)
|
||||
append(", :path => '$path'")
|
||||
}
|
||||
|
||||
is Git -> {
|
||||
append(", :git => '${source.url}'")
|
||||
when {
|
||||
source.branch != null -> append(", :branch => '${source.branch}'")
|
||||
source.tag != null -> append(", :tag => '${source.tag}'")
|
||||
source.commit != null -> append(", :commit => '${source.commit}'")
|
||||
}
|
||||
}
|
||||
}
|
||||
append(", ${source.getPodSourcePath()}")
|
||||
} else if (version != null) {
|
||||
append(", '$version'")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user