Skip to content

Instantly share code, notes, and snippets.

@ponkichi7
ponkichi7 / gist:1991302
Created March 7, 2012 05:40
DSLのサンプル
class Main {
static main(args){
run( new File("src/main/resources/dsl.groovy"))
}
static run(File file){
Script script = new GroovyShell().parse(file.text)
Message mes = new Message()
script.metaClass = createEMC(script.class,{
ExpandoMetaClass emc ->
emc.hello = {
@ponkichi7
ponkichi7 / gist:1937155
Created February 29, 2012 02:43
GroovyでXML
import groovy.xml.MarkupBuilder
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.example() {
person(name: 'hoge', type: 'hage'){
city('Tokyo')
remarks('特に無し')
}
@ponkichi7
ponkichi7 / gist:1897895
Created February 24, 2012 05:01
Gradle to run Java and Groovy
fileTree(dir: 'src/main', includes: ['**/*.java','**/*.groovy']).each {File file ->
def path = relativePath(file.path)
def kind = path.split(/\./).toList().last()
def taskName = path - "src/main/${kind}/" - ".${kind}"
taskName = taskName.replaceAll('/','.')
task "$taskName"(type: JavaExec, dependsOn: classes){
group = "Run"
description = "Run the $taskName program($kind)"
main = taskName
classpath sourceSets.main.output + sourceSets.main.runtimeClasspath