Skip to content

Commit

Permalink
Add artifactory repository handling to pod install task [ATLAS-1531] (#…
Browse files Browse the repository at this point in the history
…17)

Add artifactory repository handling to pod install task

Description
===========

In order to handle custom artifactory repositories for cocoapods
I added a new property to the `PodInstall` task.
When the property `artRepositories` is set with a list of
repository URL's, the task will call `pod art-repo add ...` and
`pod art-repo update` for each configured repository URL.
It is assumed that the art-cocoapods extension is installed.

Changes
=======

* ![ADD] artifactory repository handling in `PodInstall` task
  • Loading branch information
Larusso authored Oct 18, 2023
1 parent d61e558 commit c6bb09d
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,73 @@ class PodInstallTaskSpec extends CocoaPodSpec<PodInstallTask> {
query.matches(result, expectedValue)

where:
property | method | rawValue | returnValue | type
"projectDirectory" | toProviderSet(property) | "/path/to/project" | _ | "File"
"projectDirectory" | toProviderSet(property) | "/path/to/project" | _ | "Provider<Directory>"
"projectDirectory" | toSetter(property) | "/path/to/project" | _ | "File"
"projectDirectory" | toSetter(property) | "/path/to/project" | _ | "Provider<Directory>"

"xcodeProjectFileName" | toProviderSet(property) | "test.xcodeproj" | _ | "String"
"xcodeProjectFileName" | toProviderSet(property) | "test.xcodeproj" | _ | "Provider<String>"
"xcodeProjectFileName" | toSetter(property) | "test.xcodeproj" | _ | "String"
"xcodeProjectFileName" | toSetter(property) | "test.xcodeproj" | _ | "Provider<String>"

"xcodeWorkspaceFileName" | toProviderSet(property) | "test.xcworkspace" | _ | "String"
"xcodeWorkspaceFileName" | toProviderSet(property) | "test.xcworkspace" | _ | "Provider<String>"
"xcodeWorkspaceFileName" | toSetter(property) | "test.xcworkspace" | _ | "String"
"xcodeWorkspaceFileName" | toSetter(property) | "test.xcworkspace" | _ | "Provider<String>"
property | method | rawValue | returnValue | type
"projectDirectory" | toProviderSet(property) | "/path/to/project" | _ | "File"
"projectDirectory" | toProviderSet(property) | "/path/to/project" | _ | "Provider<Directory>"
"projectDirectory" | toSetter(property) | "/path/to/project" | _ | "File"
"projectDirectory" | toSetter(property) | "/path/to/project" | _ | "Provider<Directory>"

"xcodeProjectFileName" | toProviderSet(property) | "test.xcodeproj" | _ | "String"
"xcodeProjectFileName" | toProviderSet(property) | "test.xcodeproj" | _ | "Provider<String>"
"xcodeProjectFileName" | toSetter(property) | "test.xcodeproj" | _ | "String"
"xcodeProjectFileName" | toSetter(property) | "test.xcodeproj" | _ | "Provider<String>"

"xcodeWorkspaceFileName" | toProviderSet(property) | "test.xcworkspace" | _ | "String"
"xcodeWorkspaceFileName" | toProviderSet(property) | "test.xcworkspace" | _ | "Provider<String>"
"xcodeWorkspaceFileName" | toSetter(property) | "test.xcworkspace" | _ | "String"
"xcodeWorkspaceFileName" | toSetter(property) | "test.xcworkspace" | _ | "Provider<String>"

"artRepositories" | toProviderSet(property) | ["https://foo.bar"] | _ | "List<String>"
"artRepositories" | toProviderSet(property) | ["https://foo.bar"] | _ | "Provider<List<String>>"
"artRepositories" | toSetter(property) | ["https://foo.bar"] | _ | "List<String>"
"artRepositories" | toSetter(property) | ["https://foo.bar"] | _ | "Provider<List<String>>"
value = wrapValueBasedOnType(rawValue, type, wrapValueFallback)
expectedValue = returnValue == _ ? rawValue : returnValue
}

def "adds repo-art repositories when configured"() {
given: "a sample Pod file"
def podFile = createFile("Podfile")

and: "a list of artifactory repositories configured"
appendToSubjectTask("""
setArtRepositories(${wrapValueBasedOnType(repositories.values().toList(), "List<String>")})
""".stripIndent())

when:
def result = runTasks(taskName)

then:
result.success
repositories.each {repoName, repoUrl ->
assert outputContains(result, "repo-art add ${repoName} ${repoUrl} --silent")
assert outputContains(result, "repo-art update ${repoName}")
}

where:
repositories = [
"repo1-443-foo-bar": "https://repo1/foo/bar",
"repo2-443-" : "https://repo2/",
"repo3" : "https://repo3"
]
taskName = subjectUnderTestName
}

def "does not call repo-art commands when artRepositories properties is empty"() {
given: "a sample Pod file"
def podFile = createFile("Podfile")

and: "empty artRepositories"
appendToSubjectTask("""
setArtRepositories([])
""".stripIndent())

when:
def result = runTasks(subjectUnderTestName)

then:
result.success
!outputContains(result, "repo-art add")
!outputContains(result, "repo-art update")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import org.gradle.api.Action
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.file.Directory
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.internal.provider.Providers
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging
import org.gradle.api.plugins.BasePlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import org.gradle.api.DefaultTask
import org.gradle.api.file.Directory
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileCollection
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.*
Expand All @@ -28,6 +30,17 @@ class PodInstallTask extends DefaultTask implements ExecSpec, LogFileSpec, Proce
projectDirectory.set(value)
}

private final ListProperty<String> artRepositories = project.objects.listProperty(String)

@Input
ListProperty<String> getArtRepositories() {
artRepositories
}

void setArtRepositories(Provider<Iterable<String>> value) {
artRepositories.set(value)
}

@InputFiles
@SkipWhenEmpty
protected FileCollection getInputFiles() {
Expand Down Expand Up @@ -93,6 +106,22 @@ class PodInstallTask extends DefaultTask implements ExecSpec, LogFileSpec, Proce

@TaskAction
protected void install() {
artRepositories.get().each { repoUrl ->
def repoName = repoUrl.replaceAll("https?://","").replaceFirst("/","-443-").replaceAll("[/]","-")
ProcessExecutor.from(this)

.withArguments(['repo-art', 'add', repoName, repoUrl, "--silent"])
.withOutputLogFile(this, this)
.execute()
.assertNormalExitValue()

ProcessExecutor.from(this)
.withArguments(['repo-art', 'update', repoName])
.withOutputLogFile(this, this)
.execute()
.assertNormalExitValue()
}

ProcessExecutor.from(this)
.withArguments(['repo', 'update'])
.withOutputLogFile(this, this)
Expand Down

0 comments on commit c6bb09d

Please sign in to comment.