How to do a copy filter the gradle way?

classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|

How to do a copy filter the gradle way?

Jason Porter
In a war I've got I'd like to filter a file that ultimately ends up in
the WEB-INF directory (chances are I'll just put it here under
webapp/WEB-INF anyway), but I want to replace some tokens in it
(preferably with items that exist in a properties file).  I know how
I'd do this in ant, but what's the gradle way of doing it?

--
Jason Porter
Real Programmers think better when playing Adventure or Rogue.

PGP key id: 926CCFF5
PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
PGP key available at: keyserver.net, pgp.mit.edu

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

Levi Hoogenberg
Hi Jason,

I don't know if it's the Gradle way, but in one of my projects' build.gradle I have the following:

processResources {
    filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [version: project.version])
}


This replaces @version@ in a property file, so that it can be read from the code.

Regards,
  Levi

On Wed, Nov 4, 2009 at 7:46 AM, Jason Porter <lightguard.jp@gmail.com> wrote:
In a war I've got I'd like to filter a file that ultimately ends up in
the WEB-INF directory (chances are I'll just put it here under
webapp/WEB-INF anyway), but I want to replace some tokens in it
(preferably with items that exist in a properties file).  I know how
I'd do this in ant, but what's the gradle way of doing it?

--
Jason Porter
Real Programmers think better when playing Adventure or Rogue.

PGP key id: 926CCFF5
PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
PGP key available at: keyserver.net, pgp.mit.edu

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

Jason Porter
Sent from my iPhone

On Nov 4, 2009, at 4:43, Levi Hoogenberg <[hidden email]> wrote:

Hi Jason,

I don't know if it's the Gradle way, but in one of my projects' build.gradle I have the following:

processResources {
    filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [version: project.version])
}


This replaces @version@ in a property file, so that it can be read from the code.

Regards,
  Levi

On Wed, Nov 4, 2009 at 7:46 AM, Jason Porter <lightguard.jp@gmail.com> wrote:
In a war I've got I'd like to filter a file that ultimately ends up in
the WEB-INF directory (chances are I'll just put it here under
webapp/WEB-INF anyway), but I want to replace some tokens in it
(preferably with items that exist in a properties file).  I know how
I'd do this in ant, but what's the gradle way of doing it?

--
Jason Porter
Real Programmers think better when playing Adventure or Rogue.

PGP key id: 926CCFF5
PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
PGP key available at: keyserver.net, pgp.mit.edu

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email




That would work fine, but I don't want to list the tokens and their values in the build file. I'd rather have them pulled from a properties file (so it can change from box / environment). Think stuff like user names and passwords, external locations, etc.
Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

hans_d
Administrator

On Nov 4, 2009, at 3:04 PM, Jason Porter wrote:

Sent from my iPhone

On Nov 4, 2009, at 4:43, Levi Hoogenberg <[hidden email]> wrote:

Hi Jason,

I don't know if it's the Gradle way, but in one of my projects' build.gradle I have the following:

processResources {
    filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [version: project.version])
}


This replaces @version@ in a property file, so that it can be read from the code.

The processResources task is of type Copy.


What you could do in your case:

Properties props = new Props()
props.load(...)

copy {
   from 'path_to_file_to_be_filtered'
   into ...
   props.each { key, value ->
      filter(ReplaceTokens, tokens: props) // It depends on you set up if this is exactly what you want.
   }
}

- Hans

--
Hans Dockter
Gradle Project Manager


Regards,
  Levi

On Wed, Nov 4, 2009 at 7:46 AM, Jason Porter <lightguard.jp@gmail.com> wrote:
In a war I've got I'd like to filter a file that ultimately ends up in
the WEB-INF directory (chances are I'll just put it here under
webapp/WEB-INF anyway), but I want to replace some tokens in it
(preferably with items that exist in a properties file).  I know how
I'd do this in ant, but what's the gradle way of doing it?

--
Jason Porter
Real Programmers think better when playing Adventure or Rogue.

PGP key id: 926CCFF5
PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
PGP key available at: keyserver.net, pgp.mit.edu

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email




That would work fine, but I don't want to list the tokens and their values in the build file. I'd rather have them pulled from a properties file (so it can change from box / environment). Think stuff like user names and passwords, external locations, etc.

Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

Jason Porter
On Wed, Nov 4, 2009 at 12:22, Hans Dockter <[hidden email]> wrote:

>
> On Nov 4, 2009, at 3:04 PM, Jason Porter wrote:
>
> Sent from my iPhone
> On Nov 4, 2009, at 4:43, Levi Hoogenberg <[hidden email]> wrote:
>
> Hi Jason,
>
> I don't know if it's the Gradle way, but in one of my projects' build.gradle
> I have the following:
>
> processResources {
>     filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [version:
> project.version])
> }
>
> This replaces @version@ in a property file, so that it can be read from the
> code.
>
> The processResources task is of type Copy.
> See
> Javadoc: http://gradle.org/0.8/docs/javadoc/index.html?org/gradle/api/tasks/Copy.html
> What you could do in your case:
> Properties props = new Props()
> props.load(...)
> copy {
>    from 'path_to_file_to_be_filtered'
>    into ...
>    props.each { key, value ->
>       filter(ReplaceTokens, tokens: props) // It depends on you set up if
> this is exactly what you want.
>    }
> }
> - Hans
> --
> Hans Dockter
> Gradle Project Manager
> http://www.gradle.org

Thans Hans, that's very, very close to what I want to do.  I guess
what I really want is a way to filter files before they're added to an
artifact (in this case the war).  For example I need to replace a
context-param in my web.xml based on the environment I'll be deploying
to (dev, qa, prod, etc).  I could copy out that new file to a
different location and modify the war task.  If this is the only way
to do it, okay cool.  However, filtering while building an archive
would be awesome.  It doesn't look like ant this though, and gradle
may not either (as it's using the ant tasks for this I believe).

>
> Regards,
>   Levi
>
> On Wed, Nov 4, 2009 at 7:46 AM, Jason Porter <[hidden email]>
> wrote:
>>
>> In a war I've got I'd like to filter a file that ultimately ends up in
>> the WEB-INF directory (chances are I'll just put it here under
>> webapp/WEB-INF anyway), but I want to replace some tokens in it
>> (preferably with items that exist in a properties file).  I know how
>> I'd do this in ant, but what's the gradle way of doing it?
>>
>> --
>> Jason Porter
>> Real Programmers think better when playing Adventure or Rogue.
>>
>> PGP key id: 926CCFF5
>> PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
>> PGP key available at: keyserver.net, pgp.mit.edu
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
>
> That would work fine, but I don't want to list the tokens and their values
> in the build file. I'd rather have them pulled from a properties file (so it
> can change from box / environment). Think stuff like user names and
> passwords, external locations, etc.
>



--
Jason Porter
Real Programmers think better when playing Adventure or Rogue.

PGP key id: 926CCFF5
PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
PGP key available at: keyserver.net, pgp.mit.edu

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

Adam Murdoch-2


Jason Porter wrote:
On Wed, Nov 4, 2009 at 12:22, Hans Dockter [hidden email] wrote:
  
On Nov 4, 2009, at 3:04 PM, Jason Porter wrote:

Sent from my iPhone
On Nov 4, 2009, at 4:43, Levi Hoogenberg [hidden email] wrote:

Hi Jason,

I don't know if it's the Gradle way, but in one of my projects' build.gradle
I have the following:

processResources {
    filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [version:
project.version])
}

This replaces @version@ in a property file, so that it can be read from the
code.

The processResources task is of type Copy.
See
Javadoc: http://gradle.org/0.8/docs/javadoc/index.html?org/gradle/api/tasks/Copy.html
What you could do in your case:
Properties props = new Props()
props.load(...)
copy {
   from 'path_to_file_to_be_filtered'
   into ...
   props.each { key, value ->
      filter(ReplaceTokens, tokens: props) // It depends on you set up if
this is exactly what you want.
   }
}
- Hans
--
Hans Dockter
Gradle Project Manager
http://www.gradle.org
    

Thans Hans, that's very, very close to what I want to do.  I guess
what I really want is a way to filter files before they're added to an
artifact (in this case the war).  For example I need to replace a
context-param in my web.xml based on the environment I'll be deploying
to (dev, qa, prod, etc).  I could copy out that new file to a
different location and modify the war task.  If this is the only way
to do it, okay cool.  However, filtering while building an archive
would be awesome.

You can do this in trunk now, as the archive tasks now have the same API as the copy task (more on this in another email, soon). You can do something like:

war {
    webInf {
        from 'path.to.file.or.dir'
        filter(ReplaceTokens, tokens: [some: map])
    }
}


  It doesn't look like ant this though, and gradle
may not either (as it's using the ant tasks for this I believe).

  
Regards,
  Levi

On Wed, Nov 4, 2009 at 7:46 AM, Jason Porter [hidden email]
wrote:
    
In a war I've got I'd like to filter a file that ultimately ends up in
the WEB-INF directory (chances are I'll just put it here under
webapp/WEB-INF anyway), but I want to replace some tokens in it
(preferably with items that exist in a properties file).  I know how
I'd do this in ant, but what's the gradle way of doing it?

--
Jason Porter
Real Programmers think better when playing Adventure or Rogue.

PGP key id: 926CCFF5
PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
PGP key available at: keyserver.net, pgp.mit.edu

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


      
That would work fine, but I don't want to list the tokens and their values
in the build file. I'd rather have them pulled from a properties file (so it
can change from box / environment). Think stuff like user names and
passwords, external locations, etc.

    



  

-- 
Adam Murdoch
Gradle Developer
http://www.gradle.org
Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

Jason Porter
On Wed, Nov 4, 2009 at 14:51, Adam Murdoch <[hidden email]> wrote:

>
> You can do this in trunk now, as the archive tasks now have the same API as
> the copy task (more on this in another email, soon). You can do something
> like:
>
> war {
>     webInf {
>         from 'path.to.file.or.dir'
>         filter(ReplaceTokens, tokens: [some: map])
>     }
> }
>
> --
> Adam Murdoch
> Gradle Developer
> http://www.gradle.org
>

Awesome!  Thanks adam.  I think I have a work around I'll use until
0.9 is finish then update the build then.  I just need to look more at
the filter and see what options are available to me besides a hard
coded map, that one's a stickler for me.

--
Jason Porter
Real Programmers think better when playing Adventure or Rogue.

PGP key id: 926CCFF5
PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
PGP key available at: keyserver.net, pgp.mit.edu

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

Adam Murdoch-2
In reply to this post by hans_d


Hans Dockter wrote:

On Nov 4, 2009, at 3:04 PM, Jason Porter wrote:

Sent from my iPhone

On Nov 4, 2009, at 4:43, Levi Hoogenberg <[hidden email]> wrote:

Hi Jason,

I don't know if it's the Gradle way, but in one of my projects' build.gradle I have the following:

processResources {
    filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [version: project.version])
}


This replaces @version@ in a property file, so that it can be read from the code.

The processResources task is of type Copy.


What you could do in your case:

Properties props = new Props()
props.load(...)

copy {
   from 'path_to_file_to_be_filtered'
   into ...
   props.each { key, value ->
      filter(ReplaceTokens, tokens: props) // It depends on you set up if this is exactly what you want.
   }
}

This seems like such a common thing to do, we should probably add some convenience methods for doing this. Or perhaps there should be something in the convention or in each source set, for properties to substitute into the resources of the source set.


-- 
Adam Murdoch
Gradle Developer
http://www.gradle.org
Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

Jason Porter
On Wed, Nov 4, 2009 at 15:16, Adam Murdoch <[hidden email]> wrote:

>
>
> Hans Dockter wrote:
>
> On Nov 4, 2009, at 3:04 PM, Jason Porter wrote:
>
> Sent from my iPhone
> On Nov 4, 2009, at 4:43, Levi Hoogenberg <[hidden email]> wrote:
>
> Hi Jason,
>
> I don't know if it's the Gradle way, but in one of my projects' build.gradle
> I have the following:
>
> processResources {
>     filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [version:
> project.version])
> }
>
> This replaces @version@ in a property file, so that it can be read from the
> code.
>
> The processResources task is of type Copy.
> See
> Javadoc: http://gradle.org/0.8/docs/javadoc/index.html?org/gradle/api/tasks/Copy.html
> What you could do in your case:
> Properties props = new Props()
> props.load(...)
> copy {
>    from 'path_to_file_to_be_filtered'
>    into ...
>    props.each { key, value ->
>       filter(ReplaceTokens, tokens: props) // It depends on you set up if
> this is exactly what you want.
>    }
> }
>
> This seems like such a common thing to do, we should probably add some
> convenience methods for doing this. Or perhaps there should be something in
> the convention or in each source set, for properties to substitute into the
> resources of the source set.
>
>
> --
> Adam Murdoch
> Gradle Developer
> http://www.gradle.org
>

+10

--
Jason Porter
Real Programmers think better when playing Adventure or Rogue.

PGP key id: 926CCFF5
PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
PGP key available at: keyserver.net, pgp.mit.edu

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

Steve Appling
In reply to this post by hans_d


Hans Dockter wrote:

>
> On Nov 4, 2009, at 3:04 PM, Jason Porter wrote:
>
>> Sent from my iPhone
>>
>> On Nov 4, 2009, at 4:43, Levi Hoogenberg <[hidden email]
>> <mailto:[hidden email]>> wrote:
>>
>>> Hi Jason,
>>>
>>> I don't know if it's the Gradle way, but in one of my projects'
>>> build.gradle I have the following:
>>>
>>> processResources {
>>>     filter(org.apache.tools.ant.filters.ReplaceTokens, tokens:
>>> [version: project.version])
>>> }
>>>
>>> This replaces @version@ in a property file, so that it can be read
>>> from the code.
>
> The processResources task is of type Copy.
>
> See
> Javadoc: http://gradle.org/0.8/docs/javadoc/index.html?org/gradle/api/tasks/Copy.html
>
> What you could do in your case:
>
> Properties props = new Props()
> props.load(...)
>
> copy {
>    from 'path_to_file_to_be_filtered'
>    into ...
>    props.each { key, value ->
>       filter(ReplaceTokens, tokens: props) // It depends on you set up
> if this is exactly what you want.
>    }
> }
>
> - Hans
>
> --
> Hans Dockter
> Gradle Project Manager
> http://www.gradle.org
I haven't tried this, but I think the ReplaceTokens filter can read from a
properties file all by itself so you can do:
copy {
     from 'path_to_file_to_be_filtered'
     into ...
     filter(ReplaceTokens, propertiesfile: 'mysettings.properties')
}


>
>>>
>>> Regards,
>>>   Levi
>>>
>>> On Wed, Nov 4, 2009 at 7:46 AM, Jason Porter <
>>> <http://lightguard.jp/>lightguard.jp <http://lightguard.jp/>@
>>> <http://gmail.com/>gmail.com <http://gmail.com/>> wrote:
>>>
>>>     In a war I've got I'd like to filter a file that ultimately ends
>>>     up in
>>>     the WEB-INF directory (chances are I'll just put it here under
>>>     webapp/WEB-INF anyway), but I want to replace some tokens in it
>>>     (preferably with items that exist in a properties file).  I know how
>>>     I'd do this in ant, but what's the gradle way of doing it?
>>>
>>>     --
>>>     Jason Porter
>>>     Real Programmers think better when playing Adventure or Rogue.
>>>
>>>     PGP key id: 926CCFF5
>>>     PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
>>>     PGP key available at: <http://keyserver.net/>keyserver.net
>>>     <http://keyserver.net/>, <http://pgp.mit.edu/>pgp.mit.edu
>>>     <http://pgp.mit.edu/>
>>>
>>>     ---------------------------------------------------------------------
>>>     To unsubscribe from this list, please visit:
>>>
>>>        
>>>     <http://xircles.codehaus.org/manage_email>http://xircles.codehaus.org/manage_email
>>>
>>>
>>>
>>
>> That would work fine, but I don't want to list the tokens and their
>> values in the build file. I'd rather have them pulled from a
>> properties file (so it can change from box / environment). Think stuff
>> like user names and passwords, external locations, etc.
>

--
Steve Appling
Automated Logic Research Team

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

Narco
on gradle0.8 filter(ReplaceTokens, propertiesfile: 'mysettings.properties') gives:
Cause: Error - Invalid filter specification for org.apache.tools.ant.filters.ReplaceTokens

Steve Appling wrote

Hans Dockter wrote:
>
> On Nov 4, 2009, at 3:04 PM, Jason Porter wrote:
>
>> Sent from my iPhone
>>
>> On Nov 4, 2009, at 4:43, Levi Hoogenberg <levihoogenberg@gmail.com
>> <mailto:levihoogenberg@gmail.com>> wrote:
>>
>>> Hi Jason,
>>>
>>> I don't know if it's the Gradle way, but in one of my projects'
>>> build.gradle I have the following:
>>>
>>> processResources {
>>>     filter(org.apache.tools.ant.filters.ReplaceTokens, tokens:
>>> [version: project.version])
>>> }
>>>
>>> This replaces @version@ in a property file, so that it can be read
>>> from the code.
>
> The processResources task is of type Copy.
>
> See
> Javadoc: http://gradle.org/0.8/docs/javadoc/index.html?org/gradle/api/tasks/Copy.html
>
> What you could do in your case:
>
> Properties props = new Props()
> props.load(...)
>
> copy {
>    from 'path_to_file_to_be_filtered'
>    into ...
>    props.each { key, value ->
>       filter(ReplaceTokens, tokens: props) // It depends on you set up
> if this is exactly what you want.
>    }
> }
>
> - Hans
>
> --
> Hans Dockter
> Gradle Project Manager
> http://www.gradle.org
I haven't tried this, but I think the ReplaceTokens filter can read from a
properties file all by itself so you can do:
copy {
     from 'path_to_file_to_be_filtered'
     into ...
     filter(ReplaceTokens, propertiesfile: 'mysettings.properties')
}


>
>>>
>>> Regards,
>>>   Levi
>>>
>>> On Wed, Nov 4, 2009 at 7:46 AM, Jason Porter <
>>> <http://lightguard.jp/>lightguard.jp <http://lightguard.jp/>@
>>> <http://gmail.com/>gmail.com <http://gmail.com/>> wrote:
>>>
>>>     In a war I've got I'd like to filter a file that ultimately ends
>>>     up in
>>>     the WEB-INF directory (chances are I'll just put it here under
>>>     webapp/WEB-INF anyway), but I want to replace some tokens in it
>>>     (preferably with items that exist in a properties file).  I know how
>>>     I'd do this in ant, but what's the gradle way of doing it?
>>>
>>>     --
>>>     Jason Porter
>>>     Real Programmers think better when playing Adventure or Rogue.
>>>
>>>     PGP key id: 926CCFF5
>>>     PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
>>>     PGP key available at: <http://keyserver.net/>keyserver.net
>>>     <http://keyserver.net/>, <http://pgp.mit.edu/>pgp.mit.edu
>>>     <http://pgp.mit.edu/>
>>>
>>>     ---------------------------------------------------------------------
>>>     To unsubscribe from this list, please visit:
>>>
>>>        
>>>     <http://xircles.codehaus.org/manage_email>http://xircles.codehaus.org/manage_email
>>>
>>>
>>>
>>
>> That would work fine, but I don't want to list the tokens and their
>> values in the build file. I'd rather have them pulled from a
>> properties file (so it can change from box / environment). Think stuff
>> like user names and passwords, external locations, etc.
>

--
Steve Appling
Automated Logic Research Team

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

Steve Appling
Sorry, I had only looked at the ant ReplaceTokens documentation and not at the
source.  It does not support a setPropertiesfile method to allow access to this
feature :(

But (again without having tried this myself) perhaps this is sufficient:

  Properties props = new Props()
  props.load(...)

  copy {
     from 'path_to_file_to_be_filtered'
     into ...
     filter(ReplaceTokens, tokens: props)
  }

I'm not clear why Hans had a props.each surrounding the filter in his example.

Narco wrote:

> on gradle0.8 filter(ReplaceTokens, propertiesfile: 'mysettings.properties')
> gives:
> Cause: Error - Invalid filter specification for
> org.apache.tools.ant.filters.ReplaceTokens
>
>
> Steve Appling wrote:
>>
>>
>> Hans Dockter wrote:
>>> On Nov 4, 2009, at 3:04 PM, Jason Porter wrote:
>>>
>>>> Sent from my iPhone
>>>>
>>>> On Nov 4, 2009, at 4:43, Levi Hoogenberg <[hidden email]
>>>> <mailto:[hidden email]>> wrote:
>>>>
>>>>> Hi Jason,
>>>>>
>>>>> I don't know if it's the Gradle way, but in one of my projects'
>>>>> build.gradle I have the following:
>>>>>
>>>>> processResources {
>>>>>     filter(org.apache.tools.ant.filters.ReplaceTokens, tokens:
>>>>> [version: project.version])
>>>>> }
>>>>>
>>>>> This replaces @version@ in a property file, so that it can be read
>>>>> from the code.
>>> The processResources task is of type Copy.
>>>
>>> See
>>> Javadoc:
>>> http://gradle.org/0.8/docs/javadoc/index.html?org/gradle/api/tasks/Copy.html
>>>
>>> What you could do in your case:
>>>
>>> Properties props = new Props()
>>> props.load(...)
>>>
>>> copy {
>>>    from 'path_to_file_to_be_filtered'
>>>    into ...
>>>    props.each { key, value ->
>>>       filter(ReplaceTokens, tokens: props) // It depends on you set up
>>> if this is exactly what you want.
>>>    }
>>> }
>>>
>>> - Hans
>>>
>>> --
>>> Hans Dockter
>>> Gradle Project Manager
>>> http://www.gradle.org
>> I haven't tried this, but I think the ReplaceTokens filter can read from a
>> properties file all by itself so you can do:
>> copy {
>>      from 'path_to_file_to_be_filtered'
>>      into ...
>>      filter(ReplaceTokens, propertiesfile: 'mysettings.properties')
>> }
>>
>>
>>>>> Regards,
>>>>>   Levi
>>>>>
>>>>> On Wed, Nov 4, 2009 at 7:46 AM, Jason Porter <
>>>>> <http://lightguard.jp/>lightguard.jp <http://lightguard.jp/>@
>>>>> <http://gmail.com/>gmail.com <http://gmail.com/>> wrote:
>>>>>
>>>>>     In a war I've got I'd like to filter a file that ultimately ends
>>>>>     up in
>>>>>     the WEB-INF directory (chances are I'll just put it here under
>>>>>     webapp/WEB-INF anyway), but I want to replace some tokens in it
>>>>>     (preferably with items that exist in a properties file).  I know
>>>>> how
>>>>>     I'd do this in ant, but what's the gradle way of doing it?
>>>>>
>>>>>     --
>>>>>     Jason Porter
>>>>>     Real Programmers think better when playing Adventure or Rogue.
>>>>>
>>>>>     PGP key id: 926CCFF5
>>>>>     PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
>>>>>     PGP key available at: <http://keyserver.net/>keyserver.net
>>>>>     <http://keyserver.net/>, <http://pgp.mit.edu/>pgp.mit.edu
>>>>>     <http://pgp.mit.edu/>
>>>>>
>>>>>    
>>>>> ---------------------------------------------------------------------
>>>>>     To unsubscribe from this list, please visit:
>>>>>
>>>>>        
>>>>>    
>>>>> <http://xircles.codehaus.org/manage_email>http://xircles.codehaus.org/manage_email
>>>>>
>>>>>
>>>>>
>>>> That would work fine, but I don't want to list the tokens and their
>>>> values in the build file. I'd rather have them pulled from a
>>>> properties file (so it can change from box / environment). Think stuff
>>>> like user names and passwords, external locations, etc.
>> --
>> Steve Appling
>> Automated Logic Research Team
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>>
>>
>

--
Steve Appling
Automated Logic Research Team

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

Narco
Yes, it works. However, I don`t see any improvements of copying task from gradle. It doesn`t support even filtersfile and overwrite attributes. I`m going to use normal project.ant instead... Why not?
What is not working for me is replacing tokens in target folder without copying. "Copy" seems simply skipping task when source and target is the same. If Gradle could do that it will give performance and simpler scripts.

Steve Appling wrote
Sorry, I had only looked at the ant ReplaceTokens documentation and not at the
source.  It does not support a setPropertiesfile method to allow access to this
feature :(

But (again without having tried this myself) perhaps this is sufficient:

  Properties props = new Props()
  props.load(...)

  copy {
     from 'path_to_file_to_be_filtered'
     into ...
     filter(ReplaceTokens, tokens: props)
  }

I'm not clear why Hans had a props.each surrounding the filter in his example.

Narco wrote:
> on gradle0.8 filter(ReplaceTokens, propertiesfile: 'mysettings.properties')
> gives:
> Cause: Error - Invalid filter specification for
> org.apache.tools.ant.filters.ReplaceTokens
>
>
> Steve Appling wrote:
>>
>>
>> Hans Dockter wrote:
>>> On Nov 4, 2009, at 3:04 PM, Jason Porter wrote:
>>>
>>>> Sent from my iPhone
>>>>
>>>> On Nov 4, 2009, at 4:43, Levi Hoogenberg <levihoogenberg@gmail.com
>>>> <mailto:levihoogenberg@gmail.com>> wrote:
>>>>
>>>>> Hi Jason,
>>>>>
>>>>> I don't know if it's the Gradle way, but in one of my projects'
>>>>> build.gradle I have the following:
>>>>>
>>>>> processResources {
>>>>>     filter(org.apache.tools.ant.filters.ReplaceTokens, tokens:
>>>>> [version: project.version])
>>>>> }
>>>>>
>>>>> This replaces @version@ in a property file, so that it can be read
>>>>> from the code.
>>> The processResources task is of type Copy.
>>>
>>> See
>>> Javadoc:
>>> http://gradle.org/0.8/docs/javadoc/index.html?org/gradle/api/tasks/Copy.html
>>>
>>> What you could do in your case:
>>>
>>> Properties props = new Props()
>>> props.load(...)
>>>
>>> copy {
>>>    from 'path_to_file_to_be_filtered'
>>>    into ...
>>>    props.each { key, value ->
>>>       filter(ReplaceTokens, tokens: props) // It depends on you set up
>>> if this is exactly what you want.
>>>    }
>>> }
>>>
>>> - Hans
>>>
>>> --
>>> Hans Dockter
>>> Gradle Project Manager
>>> http://www.gradle.org
>> I haven't tried this, but I think the ReplaceTokens filter can read from a
>> properties file all by itself so you can do:
>> copy {
>>      from 'path_to_file_to_be_filtered'
>>      into ...
>>      filter(ReplaceTokens, propertiesfile: 'mysettings.properties')
>> }
>>
>>
>>>>> Regards,
>>>>>   Levi
>>>>>
>>>>> On Wed, Nov 4, 2009 at 7:46 AM, Jason Porter <
>>>>> <http://lightguard.jp/>lightguard.jp <http://lightguard.jp/>@
>>>>> <http://gmail.com/>gmail.com <http://gmail.com/>> wrote:
>>>>>
>>>>>     In a war I've got I'd like to filter a file that ultimately ends
>>>>>     up in
>>>>>     the WEB-INF directory (chances are I'll just put it here under
>>>>>     webapp/WEB-INF anyway), but I want to replace some tokens in it
>>>>>     (preferably with items that exist in a properties file).  I know
>>>>> how
>>>>>     I'd do this in ant, but what's the gradle way of doing it?
>>>>>
>>>>>     --
>>>>>     Jason Porter
>>>>>     Real Programmers think better when playing Adventure or Rogue.
>>>>>
>>>>>     PGP key id: 926CCFF5
>>>>>     PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
>>>>>     PGP key available at: <http://keyserver.net/>keyserver.net
>>>>>     <http://keyserver.net/>, <http://pgp.mit.edu/>pgp.mit.edu
>>>>>     <http://pgp.mit.edu/>
>>>>>
>>>>>    
>>>>> ---------------------------------------------------------------------
>>>>>     To unsubscribe from this list, please visit:
>>>>>
>>>>>        
>>>>>    
>>>>> <http://xircles.codehaus.org/manage_email>http://xircles.codehaus.org/manage_email
>>>>>
>>>>>
>>>>>
>>>> That would work fine, but I don't want to list the tokens and their
>>>> values in the build file. I'd rather have them pulled from a
>>>> properties file (so it can change from box / environment). Think stuff
>>>> like user names and passwords, external locations, etc.
>> --
>> Steve Appling
>> Automated Logic Research Team
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>>
>>
>

--
Steve Appling
Automated Logic Research Team

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

hans_d
Administrator

On Nov 10, 2009, at 3:01 PM, Narco wrote:

>
> Yes, it works. However, I don`t see any improvements of copying task  
> from
> gradle. It doesn`t support even filtersfile and overwrite  
> attributes. I`m
> going to use normal project.ant instead... Why not?

Ant is our friend. I don't see fundamental issues with using it. But  
Gradle's copy has important advantages depending on your use case.

- It can accept Gradle's file system abstractions:

copy {
    from configurations.runtime
}

- I really like the nested way of doing things and the syntax.
- You can copy subsets from archive and the archives will be never be  
temporarily unpacked but only streamed.
- You can set file permissions (depending on the context)
- It is an common pattern used for copying into the file system as  
well as filling an archive (in 0.9).
- We will listen to our user's and add the missing bits soon ;)

> What is not working for me is replacing tokens in target folder  
> without
> copying. "Copy" seems simply skipping task when source and target is  
> the
> same.

Could you file a Jira?

- Hans

--
Hans Dockter
Gradle Project Manager
http://www.gradle.org

> If Gradle could do that it will give performance and simpler scripts.
>
>
> Steve Appling wrote:
>>
>> Sorry, I had only looked at the ant ReplaceTokens documentation and  
>> not at
>> the
>> source.  It does not support a setPropertiesfile method to allow  
>> access to
>> this
>> feature :(
>>
>> But (again without having tried this myself) perhaps this is  
>> sufficient:
>>
>>  Properties props = new Props()
>>  props.load(...)
>>
>>  copy {
>>     from 'path_to_file_to_be_filtered'
>>     into ...
>>     filter(ReplaceTokens, tokens: props)
>>  }
>>
>> I'm not clear why Hans had a props.each surrounding the filter in his
>> example.
>>
>> Narco wrote:
>>> on gradle0.8 filter(ReplaceTokens, propertiesfile:
>>> 'mysettings.properties')
>>> gives:
>>> Cause: Error - Invalid filter specification for
>>> org.apache.tools.ant.filters.ReplaceTokens
>>>
>>>
>>> Steve Appling wrote:
>>>>
>>>>
>>>> Hans Dockter wrote:
>>>>> On Nov 4, 2009, at 3:04 PM, Jason Porter wrote:
>>>>>
>>>>>> Sent from my iPhone
>>>>>>
>>>>>> On Nov 4, 2009, at 4:43, Levi Hoogenberg  
>>>>>> <[hidden email]
>>>>>> <mailto:[hidden email]>> wrote:
>>>>>>
>>>>>>> Hi Jason,
>>>>>>>
>>>>>>> I don't know if it's the Gradle way, but in one of my projects'
>>>>>>> build.gradle I have the following:
>>>>>>>
>>>>>>> processResources {
>>>>>>>    filter(org.apache.tools.ant.filters.ReplaceTokens, tokens:
>>>>>>> [version: project.version])
>>>>>>> }
>>>>>>>
>>>>>>> This replaces @version@ in a property file, so that it can be  
>>>>>>> read
>>>>>>> from the code.
>>>>> The processResources task is of type Copy.
>>>>>
>>>>> See
>>>>> Javadoc:
>>>>> http://gradle.org/0.8/docs/javadoc/index.html?org/gradle/api/tasks/Copy.html
>>>>>
>>>>> What you could do in your case:
>>>>>
>>>>> Properties props = new Props()
>>>>> props.load(...)
>>>>>
>>>>> copy {
>>>>>   from 'path_to_file_to_be_filtered'
>>>>>   into ...
>>>>>   props.each { key, value ->
>>>>>      filter(ReplaceTokens, tokens: props) // It depends on you  
>>>>> set up
>>>>> if this is exactly what you want.
>>>>>   }
>>>>> }
>>>>>
>>>>> - Hans
>>>>>
>>>>> --
>>>>> Hans Dockter
>>>>> Gradle Project Manager
>>>>> http://www.gradle.org
>>>> I haven't tried this, but I think the ReplaceTokens filter can  
>>>> read from
>>>> a
>>>> properties file all by itself so you can do:
>>>> copy {
>>>>     from 'path_to_file_to_be_filtered'
>>>>     into ...
>>>>     filter(ReplaceTokens, propertiesfile: 'mysettings.properties')
>>>> }
>>>>
>>>>
>>>>>>> Regards,
>>>>>>>  Levi
>>>>>>>
>>>>>>> On Wed, Nov 4, 2009 at 7:46 AM, Jason Porter <
>>>>>>> <http://lightguard.jp/>lightguard.jp <http://lightguard.jp/>@
>>>>>>> <http://gmail.com/>gmail.com <http://gmail.com/>> wrote:
>>>>>>>
>>>>>>>    In a war I've got I'd like to filter a file that ultimately  
>>>>>>> ends
>>>>>>>    up in
>>>>>>>    the WEB-INF directory (chances are I'll just put it here  
>>>>>>> under
>>>>>>>    webapp/WEB-INF anyway), but I want to replace some tokens  
>>>>>>> in it
>>>>>>>    (preferably with items that exist in a properties file).  I  
>>>>>>> know
>>>>>>> how
>>>>>>>    I'd do this in ant, but what's the gradle way of doing it?
>>>>>>>
>>>>>>>    --
>>>>>>>    Jason Porter
>>>>>>>    Real Programmers think better when playing Adventure or  
>>>>>>> Rogue.
>>>>>>>
>>>>>>>    PGP key id: 926CCFF5
>>>>>>>    PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C
>>>>>>> CFF5
>>>>>>>    PGP key available at: <http://keyserver.net/>keyserver.net
>>>>>>>    <http://keyserver.net/>, <http://pgp.mit.edu/>pgp.mit.edu
>>>>>>>    <http://pgp.mit.edu/>
>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>>    To unsubscribe from this list, please visit:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> <http://xircles.codehaus.org/manage_email>http://
>>>>>>> xircles.codehaus.org/manage_email
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> That would work fine, but I don't want to list the tokens and  
>>>>>> their
>>>>>> values in the build file. I'd rather have them pulled from a
>>>>>> properties file (so it can change from box / environment).  
>>>>>> Think stuff
>>>>>> like user names and passwords, external locations, etc.
>>>> --
>>>> Steve Appling
>>>> Automated Logic Research Team
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe from this list, please visit:
>>>>
>>>>    http://xircles.codehaus.org/manage_email
>>>>
>>>>
>>>>
>>>>
>>>
>>
>> --
>> Steve Appling
>> Automated Logic Research Team
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/How-to-do-a-copy-filter-the-gradle-way--tp26191753p26283890.html
> Sent from the gradle-user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

Narco
Ok - http://jira.codehaus.org/browse/GRADLE-737

hdockter wrote
On Nov 10, 2009, at 3:01 PM, Narco wrote:

>
> Yes, it works. However, I don`t see any improvements of copying task  
> from
> gradle. It doesn`t support even filtersfile and overwrite  
> attributes. I`m
> going to use normal project.ant instead... Why not?

Ant is our friend. I don't see fundamental issues with using it. But  
Gradle's copy has important advantages depending on your use case.

- It can accept Gradle's file system abstractions:

copy {
    from configurations.runtime
}

- I really like the nested way of doing things and the syntax.
- You can copy subsets from archive and the archives will be never be  
temporarily unpacked but only streamed.
- You can set file permissions (depending on the context)
- It is an common pattern used for copying into the file system as  
well as filling an archive (in 0.9).
- We will listen to our user's and add the missing bits soon ;)

> What is not working for me is replacing tokens in target folder  
> without
> copying. "Copy" seems simply skipping task when source and target is  
> the
> same.

Could you file a Jira?

- Hans

--
Hans Dockter
Gradle Project Manager
http://www.gradle.org

> If Gradle could do that it will give performance and simpler scripts.
>
>
> Steve Appling wrote:
>>
>> Sorry, I had only looked at the ant ReplaceTokens documentation and  
>> not at
>> the
>> source.  It does not support a setPropertiesfile method to allow  
>> access to
>> this
>> feature :(
>>
>> But (again without having tried this myself) perhaps this is  
>> sufficient:
>>
>>  Properties props = new Props()
>>  props.load(...)
>>
>>  copy {
>>     from 'path_to_file_to_be_filtered'
>>     into ...
>>     filter(ReplaceTokens, tokens: props)
>>  }
>>
>> I'm not clear why Hans had a props.each surrounding the filter in his
>> example.
>>
>> Narco wrote:
>>> on gradle0.8 filter(ReplaceTokens, propertiesfile:
>>> 'mysettings.properties')
>>> gives:
>>> Cause: Error - Invalid filter specification for
>>> org.apache.tools.ant.filters.ReplaceTokens
>>>
>>>
>>> Steve Appling wrote:
>>>>
>>>>
>>>> Hans Dockter wrote:
>>>>> On Nov 4, 2009, at 3:04 PM, Jason Porter wrote:
>>>>>
>>>>>> Sent from my iPhone
>>>>>>
>>>>>> On Nov 4, 2009, at 4:43, Levi Hoogenberg  
>>>>>> <levihoogenberg@gmail.com
>>>>>> <mailto:levihoogenberg@gmail.com>> wrote:
>>>>>>
>>>>>>> Hi Jason,
>>>>>>>
>>>>>>> I don't know if it's the Gradle way, but in one of my projects'
>>>>>>> build.gradle I have the following:
>>>>>>>
>>>>>>> processResources {
>>>>>>>    filter(org.apache.tools.ant.filters.ReplaceTokens, tokens:
>>>>>>> [version: project.version])
>>>>>>> }
>>>>>>>
>>>>>>> This replaces @version@ in a property file, so that it can be  
>>>>>>> read
>>>>>>> from the code.
>>>>> The processResources task is of type Copy.
>>>>>
>>>>> See
>>>>> Javadoc:
>>>>> http://gradle.org/0.8/docs/javadoc/index.html?org/gradle/api/tasks/Copy.html
>>>>>
>>>>> What you could do in your case:
>>>>>
>>>>> Properties props = new Props()
>>>>> props.load(...)
>>>>>
>>>>> copy {
>>>>>   from 'path_to_file_to_be_filtered'
>>>>>   into ...
>>>>>   props.each { key, value ->
>>>>>      filter(ReplaceTokens, tokens: props) // It depends on you  
>>>>> set up
>>>>> if this is exactly what you want.
>>>>>   }
>>>>> }
>>>>>
>>>>> - Hans
>>>>>
>>>>> --
>>>>> Hans Dockter
>>>>> Gradle Project Manager
>>>>> http://www.gradle.org
>>>> I haven't tried this, but I think the ReplaceTokens filter can  
>>>> read from
>>>> a
>>>> properties file all by itself so you can do:
>>>> copy {
>>>>     from 'path_to_file_to_be_filtered'
>>>>     into ...
>>>>     filter(ReplaceTokens, propertiesfile: 'mysettings.properties')
>>>> }
>>>>
>>>>
>>>>>>> Regards,
>>>>>>>  Levi
>>>>>>>
>>>>>>> On Wed, Nov 4, 2009 at 7:46 AM, Jason Porter <
>>>>>>> <http://lightguard.jp/>lightguard.jp <http://lightguard.jp/>@
>>>>>>> <http://gmail.com/>gmail.com <http://gmail.com/>> wrote:
>>>>>>>
>>>>>>>    In a war I've got I'd like to filter a file that ultimately  
>>>>>>> ends
>>>>>>>    up in
>>>>>>>    the WEB-INF directory (chances are I'll just put it here  
>>>>>>> under
>>>>>>>    webapp/WEB-INF anyway), but I want to replace some tokens  
>>>>>>> in it
>>>>>>>    (preferably with items that exist in a properties file).  I  
>>>>>>> know
>>>>>>> how
>>>>>>>    I'd do this in ant, but what's the gradle way of doing it?
>>>>>>>
>>>>>>>    --
>>>>>>>    Jason Porter
>>>>>>>    Real Programmers think better when playing Adventure or  
>>>>>>> Rogue.
>>>>>>>
>>>>>>>    PGP key id: 926CCFF5
>>>>>>>    PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C
>>>>>>> CFF5
>>>>>>>    PGP key available at: <http://keyserver.net/>keyserver.net
>>>>>>>    <http://keyserver.net/>, <http://pgp.mit.edu/>pgp.mit.edu
>>>>>>>    <http://pgp.mit.edu/>
>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>>    To unsubscribe from this list, please visit:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> <http://xircles.codehaus.org/manage_email>http://
>>>>>>> xircles.codehaus.org/manage_email
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> That would work fine, but I don't want to list the tokens and  
>>>>>> their
>>>>>> values in the build file. I'd rather have them pulled from a
>>>>>> properties file (so it can change from box / environment).  
>>>>>> Think stuff
>>>>>> like user names and passwords, external locations, etc.
>>>> --
>>>> Steve Appling
>>>> Automated Logic Research Team
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe from this list, please visit:
>>>>
>>>>    http://xircles.codehaus.org/manage_email
>>>>
>>>>
>>>>
>>>>
>>>
>>
>> --
>> Steve Appling
>> Automated Logic Research Team
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/How-to-do-a-copy-filter-the-gradle-way--tp26191753p26283890.html
> Sent from the gradle-user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

bakersemail
In reply to this post by Jason Porter
If you want separate files to supply property values from, try using the Maven plugin maven-replacer-plugin within your gradle build. http://code.google.com/p/maven-replacer-plugin/

LightGuard wrote
In a war I've got I'd like to filter a file that ultimately ends up in
the WEB-INF directory (chances are I'll just put it here under
webapp/WEB-INF anyway), but I want to replace some tokens in it
(preferably with items that exist in a properties file).  I know how
I'd do this in ant, but what's the gradle way of doing it?

--
Jason Porter
Real Programmers think better when playing Adventure or Rogue.

PGP key id: 926CCFF5
PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
PGP key available at: keyserver.net, pgp.mit.edu

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

richardm
Using the examples above I get the error:  unable to resolve class Props

I can't see this in the API docs for 0.9-rc-3.  What import do I need to use the Props class?

    Properties props = new Props()
    props.load(new FileInputStream("$rootDir/build.properties"))
   
    copy {
       from 'GUI/src/BuildVersionTemplate'
       into 'GUI/src/BuildVersion.properties'
       props.each { key, value ->
          filter(ReplaceTokens, tokens: props) // It depends on you set up if this is exactly what you want.
       }
    }
Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

Adam Murdoch-3

On 19/11/2010, at 2:04 AM, richardm wrote:


Using the examples above I get the error:  unable to resolve class Props

I can't see this in the API docs for 0.9-rc-3.  What import do I need to use
the Props class?

There's no Props class. You probably want a java.util.Properties.


   Properties props = new Props()
   props.load(new FileInputStream("$rootDir/build.properties"))

   copy {
      from 'GUI/src/BuildVersionTemplate'
      into 'GUI/src/BuildVersion.properties'

The into() method specifies a directory to copy into. So, you'll end up with a file called 'GUI/src/BuildVersion.properties/BuildVersionTemplate'. We do want to add some way for you to specify the final file name, but we haven't done so yet.

You might do something like this as a work around:

into 'GUI/src'
rename 'BuildVersionTemplate', 'BuildVersion.properties'


      props.each { key, value ->
         filter(ReplaceTokens, tokens: props) // It depends on you set up
if this is exactly what you want.
      }


You can replace the above with something like (ie get rid of the each { } loop)

filter(ReplaceTokens, tokens: props)


--
Adam Murdoch
Gradle Developer
http://www.gradle.org
CTO, Gradle Inc. - Gradle Training, Support, Consulting
http://www.gradle.biz

Reply | Threaded
Open this post in threaded view
|

Re: How to do a copy filter the gradle way?

Ken Tanaka
Adam,

Thanks for the example of filtering using properties. I was looking for
this before as well, but didn't find it. Can I suggest the online
documentation at
http://www.gradle.org/0.9-rc-3/docs/userguide/userguide_single.html#filterOnCopy 
be expanded to include an example using a properties file to contain the
replacements?

-Ken

Adam Murdoch wrote:

>
> On 19/11/2010, at 2:04 AM, richardm wrote:
>
>>
>> Using the examples above I get the error:  unable to resolve class Props
>>
>> I can't see this in the API docs for 0.9-rc-3.  What import do I need
>> to use
>> the Props class?
>
> There's no Props class. You probably want a java.util.Properties.
>
>>
>>    Properties props = new Props()
>>    props.load(new FileInputStream("$rootDir/build.properties"))
>>
>>    copy {
>>       from 'GUI/src/BuildVersionTemplate'
>>       into 'GUI/src/BuildVersion.properties'
>
> The into() method specifies a directory to copy into. So, you'll end
> up with a file called
> 'GUI/src/BuildVersion.properties/BuildVersionTemplate'. We do want to
> add some way for you to specify the final file name, but we haven't
> done so yet.
>
> You might do something like this as a work around:
>
> into 'GUI/src'
> rename 'BuildVersionTemplate', 'BuildVersion.properties'
>
>
>>       props.each { key, value ->
>>          filter(ReplaceTokens, tokens: props) // It depends on you set up
>> if this is exactly what you want.
>>       }
>
>
> You can replace the above with something like (ie get rid of the each
> { } loop)
>
> filter(ReplaceTokens, tokens: props)
>
>
> --
> Adam Murdoch
> Gradle Developer
> http://www.gradle.org
> CTO, Gradle Inc. - Gradle Training, Support, Consulting
> http://www.gradle.biz
>

--
= Enterprise Data Services Division ===============
| CIRES, National Geophysical Data Center / NOAA  |
= Ken.Tanaka&noaa.gov =============================


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email