Hey, I ended up going down the resource route. Much easier I think!
Is there a better, more "groovy" way to write this code? :
URL url = getClass().getClassLoader().getResource("export.template")
File exportTemplateFile = new File(url.getFile())
thanks
phil
On Wed, Apr 27, 2011 at 6:12 PM, Adam Murdoch
<[email protected]> wrote:
>
> On 28/04/2011, at 10:00 AM, phil swenson wrote:
>
> I am writing a Gradle Plugin Test I'm writing (first plugin ever for me).
>
> one of the methods looks like (notice the hard-coded path):
>
> @Test
> public void testLoadExportTemplate() {
> //TODO make this relational to the project
> LocalizationPluginConvention pluginConvention =
> project.convention.plugins["config"]
> String command =
> plugin.buildBatchCommand("/Users/phil/dev/sag/bas_core/trunk/modules/plugins-localization/src/main/groovy/com/sag/bas/plugins/export.template",
> pluginConvention)
>
> String expectedBatchCommand = <A bunch of XML>
> String expectedXmlAsText = new
> XmlSlurper().parseText(expectedBatchCommand).text()
> String actualXmlAsText = new XmlSlurper().parseText(command).text()
> assert expectedXmlAsText == actualXmlAsText : "batch commands
> don't match"
> println "wows!"
> }
>
>
> My question is how do I get rid of the hard-coded path
> "/Users/phil/dev/sag/bas_core/trunk/modules/plugins-localization/src/main/groovy/com/sag/bas/plugins/export.template"?
> It is stored in my gradle src tree.... Note I want it to work from
> gradle AND from my IDE.
>
> Gradle runs tests with the working directory set to the project directory.
> The IDEs do a similar thing. In both instances the working directory is
> configurable. So, you could use a relative path in your test.
> Or, another option would be to add the template file as a resource and load
> it using ClassLoader.getResource().
>
> --
> Adam Murdoch
> Gradle Co-founder
> http://www.gradle.org
> VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
> http://www.gradleware.com
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email