Hans, On Wed, 2008-05-14 at 21:58 +0200, Hans Dockter wrote: > Gradle is adding a set of import statements to any gradlefile before > it is evaluated. This saves the user typing something like > org.gradle.api.X and she can just type X. In particular for non > IntelliJ users this is an important feature ;) > > Right now the set of import statements is just a String we add to the > actual gradlefile text before we evaluate it. This has one big > disadvantage. The line numbers are changed. In case of an exception > we parse the stacktrace for line number information and add an offset > to it before we report it. This is tedious and does not work when the > line number is part of the exception message (e.g. Groovy's compile > exception). I think AST transformations could do a much better job > here. I don't have any experience here.
I came across the same problem with Gant -- not surprising as this is idiomatic of what both Gant and Gradle are doing (and any other system with a similar process). If I remember correctly I added the set of imports as a single semicolon separated statement sequence with no new lines prepended to the beginning of the first line of the users script. This means all the line numbers are correct but it has the disadvantage that if there is an error in line 1 of the script then the user gets a very bizarre character position for the error. I took the view that errors in line 1 of a script are generally rare. To date no-one has complained! > The relevant class is BuildScriptProcessor and here is the snippet > where the evaluation takes place: > > buildScript = buildScriptWithImports(project) > GroovyShell groovyShell = new GroovyShell(classLoader, > binding, conf) > Script script = groovyShell.parse(buildScript.text, > project.buildScriptFinder.buildFileName) > replaceMetaclass(script, project) > project.projectScript = script > script.run() > > Of course I could start to do my own experiments or post to the > Groovy list. But if someone has a clear idea of how to do this that > would be a great time saver. And although this is a public mail I > have a one person in mind for whom this might be very easy to do :) > > - Hans -- Russel. ==================================================== Dr Russel Winder Partner Concertant LLP t: +44 20 7585 2200, +44 20 7193 9203 41 Buckmaster Road, f: +44 8700 516 084 London SW11 1EN, UK. m: +44 7770 465 077
signature.asc
Description: This is a digitally signed message part
