Skip to content

Instantly share code, notes, and snippets.

@nbransby
Created July 12, 2014 22:35
Show Gist options
  • Save nbransby/546cf66e710174dc956b to your computer and use it in GitHub Desktop.
Save nbransby/546cf66e710174dc956b to your computer and use it in GitHub Desktop.
task translateJava(type:Exec) {
inputs.files configurations.runtime.allDependencies.dependencyProject.sourceSets.main.allJava.inject(sourceSets.main.allJava) { acc, val -> acc.plus(val) }
outputs.files files((configurations.runtime.allDependencies.dependencyProject.sourceSets.main.allJava + sourceSets.main.allJava).collect { i ->
i.collect { j ->
def name = j.path.replace(i.srcDirs.iterator().next().path, file('src/gen/objc').path)
return [name.replace('.java', '.h'), name.replace('.java', '.m')]
}
}.flatten())
executable System.getenv()['J2OBJC_HOME'] + '/j2objc'
args '--prefixes', file('src/main/resources/prefixes.properties').path
args '--mapping', file('mapping.properties').path
args '-use-arc', '--no-package-directories'
args '-d', file('src/gen/objc').path
args '-sourcepath', (sourceSets.main.allJava.srcDirs + configurations.runtime.allDependencies.dependencyProject.sourceSets.main.allJava.srcDirs.flatten()).join(':')
args inputs.files
}
task translateTestJava(type:Exec, dependsOn: translateJava) {
inputs.files configurations.runtime.allDependencies.dependencyProject.sourceSets.test.allJava.inject(sourceSets.test.allJava) { acc, val -> acc.plus(val) }
outputs.files files((configurations.runtime.allDependencies.dependencyProject.sourceSets.test.allJava + sourceSets.test.allJava).collect { i ->
i.collect { j ->
def name = j.path.replace(i.srcDirs.iterator().next().path, buildDir.path)
return [name.replace('.java', '.h'), name.replace('.java', '.m')]
}
}.flatten())
executable System.getenv()['J2OBJC_HOME'] + '/j2objc'
args '--prefixes', file('src/main/resources/prefixes.properties').path
args '-use-arc', '--no-package-directories'
args '-d', buildDir
args '-sourcepath', (sourceSets.main.allJava.srcDirs + sourceSets.test.allJava.srcDirs + configurations.runtime.allDependencies.dependencyProject.sourceSets.main.allJava.srcDirs.flatten() + configurations.runtime.allDependencies.dependencyProject.sourceSets.test.allJava.srcDirs.flatten()).join(':')
args '-classpath', System.getenv()['J2OBJC_HOME'] + '/lib/junit-4.10.jar'
args inputs.files
}
task compileTestObjC(type:Exec, dependsOn: translateTestJava) {
inputs.files fileTree(dir: buildDir, includes: ['**/*.h','**/*.m']).plus(fileTree(dir: file('src/main/objc'), includes: ['**/*.h','**/*.m']))
outputs.files file("$buildDir/testrunner")
executable System.getenv()['J2OBJC_HOME'] + '/j2objcc'
workingDir buildDir
args "-I$buildDir", "-I${file('src/gen/objc').path}"
args "-ObjC", "-ljunit"
args "-o", "testrunner"
fileTree(dir: buildDir, include: '**/*.m').files.each { i ->
args i.path
}
fileTree(dir: file('src/gen/objc'), include: '**/*.m').files.each { i ->
args i.path
}
}
task testObjC(type:Exec, dependsOn: compileTestObjC) {
inputs.files file("$buildDir/testrunner")
executable file("$buildDir/testrunner")
args 'org.junit.runner.JUnitCore'
args sourceSets.test.allJava.files.findAll { f -> f.name.endsWith('Test.java')}*.path*.replace("${sourceSets.test.java.srcDirs.iterator().next().path}/", '')*.replace('.java', '')*.replace('/', '.')
configurations.runtime.allDependencies.dependencyProject.sourceSets.test.allJava.each { i ->
args i.files.findAll { f -> f.name.endsWith('Test.java')}*.path*.replace("${i.srcDirs.iterator().next().path}/", '')*.replace('.java', '')*.replace('/', '.')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment