Created
June 29, 2013 21:16
-
-
Save esavard/5892706 to your computer and use it in GitHub Desktop.
Gradle plugin for calabash support in Android Studio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mediaarc.gradle.plugins | |
import org.gradle.api.* | |
import org.gradle.api.plugins.* | |
import org.gradle.api.tasks.* | |
class CalabashPlugin implements Plugin<Project> { | |
void apply(Project project) { | |
project.extensions.create("calabash", CalabashPluginExtension) | |
if (!project.android) { | |
throw new IllegalStateException("Android plugin is not configured.") | |
} | |
project.android.applicationVariants.each { variant -> | |
//println "Adding task for variant ${variant.name}" | |
final def buildName = variant.name | |
final def buildVar = variant.baseName | |
final def packageApp = variant.packageApplication; | |
// | |
project.task("doPrepare${buildName}") << { | |
project.calabash.init(project, buildVar) | |
def apkFile = packageApp.outputFile | |
project.calabash.writeCommandFile(apkFile) | |
} | |
project.task("doClean${buildName}") << { | |
project.calabash.init(project, buildVar) | |
project.calabash.clean() | |
} | |
project.task("calabash${buildName}", type: Exec, dependsOn: [ project["assemble${buildName}"], project["doPrepare${buildName}"] ]) { | |
project.calabash.init(project, buildVar) | |
project.calabash.execute(project[name]) | |
} | |
project.task("cleanCalabash${buildName}", dependsOn: project["doClean${buildName}"]) { | |
project.calabash.init(project, buildVar) | |
} | |
} | |
} | |
} | |
class CalabashPluginExtension { | |
def root = 'src/calabash' | |
def resultFile = "calabash-results.html" | |
//protected def hash = new Object() | |
protected File outputFile | |
protected File workingDir | |
protected File tmpFile | |
protected init(Project project, def buildVariant) { | |
if (!buildVariant) { | |
buildVariant = "debug" | |
} | |
File rootFile = project.file(root) | |
outputFile = new File(project.file("build/reports/calabash/${buildVariant}"), resultFile) | |
workingDir = rootFile | |
} | |
protected writeCommandFile(def apkFile) { | |
if (!workingDir.exists()) { | |
throw new IllegalStateException("The root directory for the calabash-tests could not be found: '${workingDir}'") | |
} | |
if (!(new File(workingDir, "features").exists())) { | |
throw new IllegalStateException("The required 'features' directory could not be found in '${workingDir}'") | |
} | |
outputFile.parentFile.mkdirs() | |
def calabashCmd = "cd ${workingDir.canonicalPath}\r\necho calabash-android run \"${apkFile.canonicalPath}\" --format html --out \"${outputFile.canonicalPath}\"\r\n" | |
getCommandFile().write calabashCmd | |
} | |
protected execute(Exec exec) { | |
exec.commandLine 'cmd', '/c', getCommandFile().canonicalPath | |
} | |
protected clean() { | |
outputFile.delete() | |
} | |
private File getCommandFile() { | |
if (!tmpFile) { | |
tmpFile = File.createTempFile("run-calabash", ".bat") | |
tmpFile.deleteOnExit() | |
} | |
return tmpFile | |
} | |
} |
or a sample installation perhaps
Hey, sounds interesting, further information how to install and use it would be great !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please add more information about your plugin ?