buildr-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rhett Sutphin <rh...@detailedbalance.net>
Subject Re: Resources & post-processing project definitions
Date Mon, 09 Feb 2009 17:53:05 GMT
Hi,

On Feb 6, 2009, at 4:30 PM, Alex Boisvert wrote:

> Take a look at the "Creating Extensions" section here:
> http://buildr.apache.org/extending.html
>
> I think it would be applicable to what you are doing.

Thanks to everyone for the suggestions.  I got it to work using  
before_define.  Here's my extension in case someone else comes across  
this thread in the future with similar needs:

------
# Uses before_define to default all projects to including their  
resources from
# src/main/java instead of src/main/resources (& similar for test) if
# those source directories exist
module InlineResources
   include Buildr::Extension

   before_define do |p|
     [
       [p.resources, p._("src/main/java")],
       [p.test.resources, p._("src/test/java")]
     ].each do |res, path|
       if File.exist?(path)
         res.from(path).exclude("**/*.java")
       end
     end
   end
end

class Buildr::Project
   include InlineResources
end
------

Thanks again,
Rhett

>
> On Fri, Feb 6, 2009 at 2:02 PM, Rhett Sutphin <rhett@detailedbalance.net 
> >wrote:
>
>> [Apologies if you see this twice -- I accidentally sent it to the  
>> old list.
>> It hasn't shown up in the archives so I'm resending it.]
>>
>> Hi,
>>
>> Synopsis:  I'm having a problem with a buildfile where, if I define  
>> the
>> resource paths outside of the initial project definition block, the  
>> resource
>> target directories are not included on the classpath when running  
>> tests.
>> The resources are copied to target (during the compile and  
>> test:compile
>> tasks) and packaged correctly (if I do package test=no), but they  
>> are not
>> visible to the tests.
>>
>> Details:  I am converting an existing project to use buildr.  It  
>> stores its
>> resources alongside the code, so in each of the subprojects I have  
>> lines
>> like these:
>>
>> resources.from(_("src/main/java")).exclude("**/*.java")
>> test.resources.from(_("src/test/java")).exclude("**/*.java")
>>
>> Hoping to DRY this up a bit, I replaced those repeated blocks with  
>> this
>> code at the end of my buildfile:
>>
>> projects.each do |p|
>> if File.exist?(p._("src/main/java"))
>>  # All resources come from source path
>>  p.resources.from(p._("src/main/java")).exclude("**/*.java")
>>  p.test.resources.from(p._("src/test/java")).exclude("**/*.java")
>> end
>> end
>>
>> This introduced the problem I described in the synopsis.  Two  
>> questions:
>>
>> - Is this a bug I should report on the issue tracker?  Or is it  
>> expected
>> behavior?
>>
>> - Is there a better way to do what I'm trying to do?
>>
>> Thanks,
>> Rhett
>>


Mime
View raw message