Skip to content

Commit

Permalink
added carthage support
Browse files Browse the repository at this point in the history
  • Loading branch information
renep committed Aug 18, 2016
1 parent 6779ec6 commit 8639b20
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changes
* XcodebuildTask and XcodeTestTask can now override the global xcodebuild settings for building for supporting multiproject build
* Added an option that a custom entitlements file can be specified for codesigningcd
* SimulatorControl now also creates the tvOS simulator
* Initial Carthage support. Carthage is not bootstraped, so make sure that Carthage is installed if your project uses it.

Note: There is no 0.14.1 version. (Reason is a typo)

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ Here a brief overview of the features:
* Override sign settings for builds
* Perform unit tests
* Support for multiple Xcodes (on one machine)
* [Cocoapods](Cocoapods) support
* [Cocoapods](https://cocoapods.org/) support
* [Carthage](https://github.com/Carthage/Carthage) support
* [Appledoc](http://gentlebytes.com/appledoc/) support
* Code coverage support (using [gcovr](http://gcovr.com) )
* Code coverage support (using [gcovr](http://gcovr.com) or using [CoverageReport](https://github.com/openbakery/CoverageReport) )
* [Hockeykit](http://hockeykit.net/), [HockeyApp](http://hockeyapp.net), [DeployGate](https://deploygate.com/) , [Apple TestFlight](https://developer.apple.com/testflight/), [Crashlytics](https://www.crashlytics.com/)
* OCLint

Expand Down
Empty file added example/iOS/Example/Cartfile
Empty file.
15 changes: 14 additions & 1 deletion plugin/src/main/groovy/org/openbakery/XcodePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.openbakery.appledoc.AppledocTask
import org.openbakery.appstore.AppstorePluginExtension
import org.openbakery.appstore.AppstoreValidateTask
import org.openbakery.appstore.AppstoreUploadTask

import org.openbakery.carthage.CarthageUpdateTask
import org.openbakery.cocoapods.CocoapodsInstallTask
import org.openbakery.cocoapods.CocoapodsUpdateTask
import org.openbakery.configuration.XcodeConfigTask
Expand Down Expand Up @@ -81,6 +81,7 @@ class XcodePlugin implements Plugin<Project> {
public static final String APPLE_DOC_GROUP_NAME = "Appledoc"
public static final String COVERAGE_GROUP_NAME = "Coverage"
public static final String COCOAPODS_GROUP_NAME = "Cocoapods"
public static final String CARTHAGE_GROUP_NAME = "Carthage"
public static final String SIMULATORS_GROUP_NAME = "Simulators"
public static final String ANALYTICS_GROUP_NAME = "Analytics"

Expand Down Expand Up @@ -123,6 +124,8 @@ 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_UPDATE_TASK_NAME = 'carthageUpdate'


public static final String APPLEDOC_TASK_NAME = 'appledoc'
public static final String APPLEDOC_CLEAN_TASK_NAME = 'appledocClean'
Expand Down Expand Up @@ -159,6 +162,7 @@ class XcodePlugin implements Plugin<Project> {
configureCoverage(project)
configureCpd(project)
configureCocoapods(project)
configureCarthage(project)
configureOCLint(project)
configureSimulatorTasks(project)
configureProperties(project)
Expand Down Expand Up @@ -565,6 +569,15 @@ class XcodePlugin implements Plugin<Project> {
project.task(COCOAPODS_UPDATE_TASK_NAME, type: CocoapodsUpdateTask, group: COCOAPODS_GROUP_NAME)
}

private void configureCarthage(Project project) {

CarthageUpdateTask task = project.task(CARTHAGE_UPDATE_TASK_NAME, type: CarthageUpdateTask, group: CARTHAGE_GROUP_NAME)
if (task.hasCartfile()) {
addDependencyToBuild(project, task);
}

}

private void configureOCLint(Project project) {
OCLintTask reportTask = project.task(OCLINT_REPORT_TASK_NAME, type: OCLintTask, group: ANALYTICS_GROUP_NAME)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.openbakery.carthage

import org.gradle.api.tasks.TaskAction
import org.gradle.internal.logging.text.StyledTextOutputFactory
import org.openbakery.AbstractXcodeTask
import org.openbakery.CommandRunner
import org.openbakery.CommandRunnerException
import org.openbakery.cocoapods.CocoapodsInstallTask
import org.openbakery.output.ConsoleOutputAppender

/**
* Created by rene on 17.08.16.
*/
class CarthageUpdateTask extends AbstractXcodeTask {


public CarthageUpdateTask() {
super()
setDescription "Installs the carthage dependencies for the given project"
}

@TaskAction
void update() {

checkCarthageInstallation()

def output = services.get(StyledTextOutputFactory).create(CarthageUpdateTask)
commandRunner.run(["carthage", "update"], new ConsoleOutputAppender(output))

}

void checkCarthageInstallation() {
try {
commandRunner.run("which", "carthage")
} catch (CommandRunnerException) {
throw new IllegalStateException("The carthage command was not found. Make sure that Carthage is installed")
}
}

boolean hasCartfile() {
File cartfile = new File(project.projectDir, "Cartfile")
return cartfile.exists()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import org.junit.Test
import org.openbakery.appstore.AppstorePluginExtension
import org.openbakery.appstore.AppstoreUploadTask
import org.openbakery.appstore.AppstoreValidateTask
import org.openbakery.carthage.CarthageUpdateTask
import org.openbakery.cocoapods.CocoapodsInstallTask
import org.openbakery.cocoapods.CocoapodsUpdateTask
import org.openbakery.cpd.CpdTask
import org.openbakery.hockeykit.HockeyKitArchiveTask
import org.openbakery.hockeykit.HockeyKitImageTask
Expand Down Expand Up @@ -217,16 +220,45 @@ class XcodePluginSpecification extends Specification {
cpdTask.group == XcodePlugin.ANALYTICS_GROUP_NAME
}

/*
def "pass parameters to property"() {
def "has cocoapods update task"() {
expect:
project.tasks.findByName('cocoapodsUpdate') instanceof CocoapodsUpdateTask

}

def "has cocoapods install task"() {
expect:
project.tasks.findByName('cocoapodsInstall') instanceof CocoapodsInstallTask
}

def "xcodebuild has cocoapods dependency"() {
when:
File projectDir = new File("../example/iOS/SwiftExample")
project = ProjectBuilder.builder().withProjectDir(projectDir).build()
project.apply plugin: org.openbakery.XcodePlugin

XcodeBuildTask task = project.tasks.findByName('xcodebuild')

then:

task.getTaskDependencies().getDependencies() contains(project.getTasks().getByName(XcodePlugin.COCOAPODS_INSTALL_TASK_NAME))
}

def "has carthage task"() {
expect:
project.tasks.findByName('carthageUpdate') instanceof CarthageUpdateTask
}

def "xcodebuild has carthage dependency"() {
when:
project.properties.put("xcodebuild.destination", "iPhone")
File projectDir = new File("../example/iOS/Example")
project = ProjectBuilder.builder().withProjectDir(projectDir).build()
project.apply plugin: org.openbakery.XcodePlugin

XcodeBuildTask task = project.tasks.findByName('xcodebuild')

then:
project.xcodebuild.destinations contains("iPhone")

task.getTaskDependencies().getDependencies() contains(project.getTasks().getByName(XcodePlugin.CARTHAGE_UPDATE_TASK_NAME))
}
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.openbakery.carthage

import org.apache.commons.io.FileUtils
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.openbakery.CommandRunner
import org.openbakery.CommandRunnerException
import org.openbakery.output.ConsoleOutputAppender
import spock.lang.Specification

/**
* Created by rene on 18.08.16.
*/
class CarthageUpdateTaskSpecification extends Specification {


Project project
CarthageUpdateTask carthageUpdateTask;

CommandRunner commandRunner = Mock(CommandRunner)

def setup() {

File projectDir = new File(System.getProperty("java.io.tmpdir"), "gradle-xcodebuild")

project = ProjectBuilder.builder().withProjectDir(projectDir).build()
project.buildDir = new File('build').absoluteFile
project.apply plugin: org.openbakery.XcodePlugin

carthageUpdateTask = project.getTasks().getByPath('carthageUpdate')

carthageUpdateTask.commandRunner = commandRunner

}


def cleanup() {
FileUtils.deleteDirectory(project.projectDir)
}

def "has carthageUpdate task"() {

expect:
carthageUpdateTask instanceof CarthageUpdateTask

}

def "verify that if carthage is not installed a excpetion is thrown"() {
given:
commandRunner.run("which", "carthage") >> { throw new CommandRunnerException("Command failed to run (exit code 1):") }

when:
carthageUpdateTask.update()

then:
def e = thrown(IllegalStateException)
e.message.startsWith("The carthage command was not found. Make sure that Carthage is installed")
}

def "verify that carthage is installed"() {
when:
carthageUpdateTask.update()

then:
1 * commandRunner.run("which", "carthage")

}

def "run carthage update"() {
when:
carthageUpdateTask.update()


then:
1 * commandRunner.run(["carthage", "update"], _ ) >> {
args -> args[1] instanceof ConsoleOutputAppender
}

}

}

0 comments on commit 8639b20

Please sign in to comment.