Skip to content
This repository was archived by the owner on May 22, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libxcode/src/main/groovy/org/openbakery/xcode/Xcode.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Xcode {
if (file.exists()) {
result.put(ENV_DEVELOPER_DIR, file.absolutePath)
}
println file.absolutePath

return result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class KeychainCreateTaskFunctionalTest extends Specification {
buildFile << """
xcodebuild {
signing {
certificate = project.provisioningFile1("$certificate")
certificateURI = "$certificate.absolutePath"
}
}
"""
Expand All @@ -84,6 +84,7 @@ class KeychainCreateTaskFunctionalTest extends Specification {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments(KeychainCreateTask.TASK_NAME)
.withDebug(true)
.withPluginClasspath(pluginClasspath)
.build()

Expand All @@ -96,7 +97,7 @@ class KeychainCreateTaskFunctionalTest extends Specification {
buildFile << """
xcodebuild {
signing {
certificate = project.provisioningFile1("$certificate")
certificateURI = "${certificate.toURI().toString()}"
certificatePassword = "p4ssword"
}
}
Expand All @@ -107,6 +108,7 @@ class KeychainCreateTaskFunctionalTest extends Specification {
.withProjectDir(testProjectDir.root)
.withArguments(KeychainCreateTask.TASK_NAME)
.withPluginClasspath(pluginClasspath)
.withDebug(true)
.build()

then:
Expand All @@ -118,7 +120,7 @@ class KeychainCreateTaskFunctionalTest extends Specification {
buildFile << """
xcodebuild {
signing {
certificate = project.provisioningFile1("$certificate")
certificateURI = "${certificate.toURI().toString()}"
certificatePassword = "p4ssword"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package org.openbakery.carthage

import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification

class CarthageBootStrapTaskFunctionalTest extends Specification {
@Rule
final TemporaryFolder testProjectDir = new TemporaryFolder()

List<File> pluginClasspath
File buildFile
GradleRunner gradleRunner
File carthageFolder

void setup() {
buildFile = testProjectDir.newFile('build.gradle')

buildFile << """
plugins {
id 'org.openbakery.xcode-plugin'
}
"""

def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.txt")
if (pluginClasspathResource == null) {
throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.")
}

pluginClasspath = pluginClasspathResource.readLines().collect { new File(it) }

gradleRunner = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments(CarthageBootStrapTask.NAME)
.withPluginClasspath(pluginClasspath)

carthageFolder = new File(testProjectDir.root, "Carthage")
}

def "The task list should contain the task"() {
when:
BuildResult result = gradleRunner.build()

then:
result.output.contains(CarthageBootStrapTask.NAME)
}

def "The task should be skipped if no cartfile is present"() {
when:
BuildResult result = gradleRunner.build()

then:
result.task(":" + CarthageBootStrapTask.NAME)
.outcome == TaskOutcome.SKIPPED
}

def "The task should be executed with success if a `cartfile.resolved` file is present"() {
setup:
testProjectDir.newFile(CarthageBootStrapTask.CARTHAGE_FILE)

when:
BuildResult result = gradleRunner.build()

then:
result.task(":" + CarthageBootStrapTask.NAME)
.outcome == TaskOutcome.SUCCESS
}

def "The task should resolve the defined carthage dependencies"() {
setup:
File carthageFile = testProjectDir.newFile("Cartfile")
carthageFile << """
github "ashleymills/Reachability.swift"
"""

File carthageResolvedFile = testProjectDir.newFile(CarthageBootStrapTask.CARTHAGE_FILE)
carthageResolvedFile << """
github "ashleymills/Reachability.swift" "v4.1.0"
"""

when:
BuildResult result = gradleRunner
.build()

then:
result.task(":" + CarthageBootStrapTask.NAME)
.outcome == TaskOutcome.SUCCESS

and: "The resolved framework should be existing only for iOS (default target)"
carthageFolder.exists()
new File(carthageFolder, "Build/iOS/Reachability.framework").exists()
!new File(carthageFolder, "Build/tvOS/Reachability.framework").exists()

when: "Force reset and build with cache enabled"
assert carthageFolder.deleteDir()
result = gradleRunner.withArguments('--build-cache', CarthageBootStrapTask.NAME)
.build()

then: "Should resolve the carthage dependencies from cache"
result.task(":" + CarthageBootStrapTask.NAME)
.outcome == TaskOutcome.FROM_CACHE

new File(carthageFolder, "Build/iOS/Reachability.framework").exists()
!new File(carthageFolder, "Build/tvOS/Reachability.framework").exists()
}

def "The task should resolve the defined carthage dependencies depending of the configured target"() {
setup:
File carthageFile = testProjectDir.newFile("Cartfile")
carthageFile << """
github "ashleymills/Reachability.swift"
"""

File carthageResolvedFile = testProjectDir.newFile(CarthageBootStrapTask.CARTHAGE_FILE)
carthageResolvedFile << """
github "ashleymills/Reachability.swift" "v4.1.0"
"""

buildFile << """
xcodebuild {
type = "tvOS"
}
"""

when:
BuildResult result = gradleRunner.build()

then:
result.task(":" + CarthageBootStrapTask.NAME)
.outcome == TaskOutcome.SUCCESS

and: "The resolved framework should be existing only for iOS (default target)"
carthageFolder.exists()
!new File(carthageFolder, "Build/iOS/Reachability.framework").exists()
new File(carthageFolder, "Build/tvOS/Reachability.framework").exists()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class ProvisioningInstallTaskFunctionalTest extends Specification {
provisioningFile1 = findResource("test1.mobileprovision")
assert provisioningFile1.exists()

def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.txt")
def pluginClasspathResource = getClass().classLoader
.findResource("plugin-classpath.txt")

if (pluginClasspathResource == null) {
throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.")
}
Expand Down Expand Up @@ -70,7 +72,7 @@ class ProvisioningInstallTaskFunctionalTest extends Specification {
buildFile << """
xcodebuild {
signing {
mobileProvisionURI = []
mobileProvisionList = []
}
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class XcodeBuildPluginExtension {

final Property<Boolean> bitcode = project.objects.property(Boolean)
final Property<String> version = project.objects.property(String)
final Property<Type> targetType = project.objects.property(Type)
final Property<String> scheme = project.objects.property(String)
final DirectoryProperty archiveDirectory = project.layout.directoryProperty()
final DirectoryProperty schemeArchiveFile = project.layout.directoryProperty()
Expand Down Expand Up @@ -108,6 +109,8 @@ class XcodeBuildPluginExtension {
this.symRoot.set(project.layout.buildDirectory.dir("sym"))
this.sharedPrecompsDir.set(project.layout.buildDirectory.dir("shared"))
this.derivedDataPath.set(project.layout.buildDirectory.dir("derivedData"))

this.targetType.set(Type.iOS)
}

private void configureServices() {
Expand Down Expand Up @@ -358,6 +361,7 @@ class XcodeBuildPluginExtension {

void setType(String type) {
this.type = Type.typeFromString(type)
this.targetType.set(this.type)
}

Type getType() {
Expand Down
13 changes: 9 additions & 4 deletions plugin/src/main/groovy/org/openbakery/XcodePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ class XcodePlugin implements Plugin<Project> {
public static final String OCLINT_TASK_NAME = 'oclint'
public static final String OCLINT_REPORT_TASK_NAME = 'oclintReport'
public static final String CPD_TASK_NAME = 'cpd'
public static final String CARTHAGE_BOOTSTRAP_TASK_NAME = 'carthageBootstrap'
public static final String CARTHAGE_UPDATE_TASK_NAME = 'carthageUpdate'
public static final String CARTHAGE_CLEAN_TASK_NAME = 'carthageClean'

Expand Down Expand Up @@ -522,7 +521,7 @@ class XcodePlugin implements Plugin<Project> {
}

private void configureSimulatorTasks(Project project) {
project.task(SIMULATORS_LIST_TASK_NAME, type: SimulatorsListTask, group: SIMULATORS_LIST_TASK_NAME)
project.task(SIMULATORS_LIST_TASK_NAME, type: SimulatorsListTask.class, group: SIMULATORS_LIST_TASK_NAME)
project.task(SIMULATORS_CREATE_TASK_NAME, type: SimulatorsCreateTask, group: SIMULATORS_LIST_TASK_NAME)
project.task(SIMULATORS_CLEAN_TASK_NAME, type: SimulatorsCleanTask, group: SIMULATORS_LIST_TASK_NAME)

Expand Down Expand Up @@ -692,11 +691,17 @@ class XcodePlugin implements Plugin<Project> {
private void configureCarthage(Project project) {
project.task(CARTHAGE_CLEAN_TASK_NAME, type: CarthageCleanTask, group: CARTHAGE_GROUP_NAME)
project.task(CARTHAGE_UPDATE_TASK_NAME, type: CarthageUpdateTask, group: CARTHAGE_GROUP_NAME)
project.task(CARTHAGE_BOOTSTRAP_TASK_NAME, type: CarthageBootStrapTask, group: CARTHAGE_GROUP_NAME)

project.tasks.create(CarthageBootStrapTask.NAME, CarthageBootStrapTask.class) {
it.group = CARTHAGE_GROUP_NAME
it.requiredXcodeVersion.set(xcodeBuildPluginExtension.version)
it.commandRunnerProperty.set(commandRunner)
it.platform.set(xcodeBuildPluginExtension.targetType)
}
}

private configureCarthageDependencies(Project project) {
CarthageBootStrapTask bootStrapTask = project.getTasks().getByName(CARTHAGE_BOOTSTRAP_TASK_NAME)
CarthageBootStrapTask bootStrapTask = project.getTasks().getByName(CarthageBootStrapTask.NAME) as CarthageBootStrapTask
addDependencyToBuild(project, bootStrapTask)

project.getTasks()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.openbakery.carthage

import groovy.transform.CompileStatic
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.*
import org.openbakery.AbstractXcodeTask
import org.openbakery.CommandRunnerException
import org.openbakery.XcodeBuildPluginExtension
import org.openbakery.xcode.Type

@CompileStatic
abstract class AbstractCarthageTaskBase extends AbstractXcodeTask {

static final String ACTION_BOOTSTRAP = "bootstrap"
Expand All @@ -31,7 +35,6 @@ abstract class AbstractCarthageTaskBase extends AbstractXcodeTask {

@InputFile
@Optional
@PathSensitive(PathSensitivity.RELATIVE)
Provider<File> getCartFile() {
// Cf https://github.com/gradle/gradle/issues/2016
File file = project.rootProject.file(CARTHAGE_FILE)
Expand All @@ -43,7 +46,6 @@ abstract class AbstractCarthageTaskBase extends AbstractXcodeTask {

@InputFile
@Optional
@PathSensitive(PathSensitivity.RELATIVE)
Provider<File> getCartResolvedFile() {
// Cf https://github.com/gradle/gradle/issues/2016
File file = project.rootProject.file(CARTHAGE_FILE_RESOLVED)
Expand All @@ -55,7 +57,7 @@ abstract class AbstractCarthageTaskBase extends AbstractXcodeTask {

@Input
String getCarthagePlatformName() {
switch (project.xcodebuild.type) {
switch (project.extensions.findByType(XcodeBuildPluginExtension).type) {
case Type.iOS: return CARTHAGE_PLATFORM_IOS
case Type.tvOS: return CARTHAGE_PLATFORM_TVOS
case Type.macOS: return CARTHAGE_PLATFORM_MACOS
Expand All @@ -65,6 +67,7 @@ abstract class AbstractCarthageTaskBase extends AbstractXcodeTask {
}

@OutputDirectory
@PathSensitive(PathSensitivity.NAME_ONLY)
Provider<File> getOutputDirectory() {
return project.provider {
project.rootProject.file("Carthage/Build/" + getCarthagePlatformName())
Expand All @@ -74,14 +77,14 @@ abstract class AbstractCarthageTaskBase extends AbstractXcodeTask {
String getCarthageCommand() {
try {
return commandRunner.runWithResult("which", "carthage")
} catch (CommandRunnerException) {
} catch (CommandRunnerException exception) {
// ignore, because try again with full path below
}

try {
commandRunner.runWithResult("ls", CARTHAGE_USR_BIN_PATH)
return CARTHAGE_USR_BIN_PATH
} catch (CommandRunnerException) {
} catch (CommandRunnerException exception) {
// ignore, because blow an exception is thrown
}
throw new IllegalStateException("The carthage command was not found. Make sure that Carthage is installed")
Expand Down
Loading