Filterchain's LineContains on LoadProperties is blocking the reading of properties

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

Filterchain's LineContains on LoadProperties is blocking the reading of properties

Anuerin Diaz
Hi,

  I am trying to selectively load properties using the LoadProperties and
FilterChain+LineContains tasks. However based on my test if the Filterchain
starts to contain any "<contains/>" element then it will start discarding
all contents of the property file being read. This was tested  using  ant
1.10.1 adn 1.10.3 in a Java 1.8 VM hosted in a Windows 10 64-bit machine.

  Below is my build xml and sample.properties file. The initialize target
has different variations that I tried to do to isolate the problem. What
could be the problem in this instance? Thanks.

-- build.xml  ---

<project name="MyProject" basedir=".">
  <target name="initialize">
    <echo>Starting load...</echo>
    <loadproperties srcFile="${basedir}/01_PropertyFiles/sample.properties">

      <filterchain>
        <linecontains>
          <contains value="ws.user" />
          <contains value="ws.password" />
          <contains value="wl.user" />
          <contains value="wl.password" />
        </linecontains>
      </filterchain>

      <!--filterchain>

      <filterreader classname="org.apache.tools.ant.filters.LineContains">
        <param type="contains" value="user"/>
        <param type="contains" value="password"/>
      </filterreader>


      </filterchain-->


    </loadproperties>
    <echo>${ws.user} - ${ws.password}</echo>
    <echo>${wl.user} - ${wl.password}</echo>

    <echo>${placebo.prop} should be printed as a literal. </echo>

  </target>

</project>


-- end of build.xml  ---

---- sample.properties ----
placebo.prop=dontprintme
ws.user=dilbert
ws.password=washere
wl.user=felix
wl.password=lantern

ps.xser=dummy
---- end of sample.properties ----


--
"Programming, an artform that fights back"

Anuerin G. Diaz
Registered Linux User #246176
http://ramfree17.net/capsule , when you absolutely have nothing else better
to do
Reply | Threaded
Open this post in threaded view
|

Re: Filterchain's LineContains on LoadProperties is blocking the reading of properties

Jaikiran Pai
Hi Anuerin,

Ifthere are more than one"contains" elements of the "linecontains", then
as noted in the documentation[1]"and" will be used toevaluate whether
the line contains those strings. So in the exampleyou pasted, the
properties file will be looked for lines containing ws.user AND
ws.password AND wl.user AND wl.password, which obviously won't be
satisfied for the sample.properties.

[1] https://ant.apache.org/manual/Types/filterchain.html#linecontains

-Jaikiran
On 19/04/18 7:28 AM, Anuerin Diaz wrote:

> Hi,
>
>    I am trying to selectively load properties using the LoadProperties and
> FilterChain+LineContains tasks. However based on my test if the Filterchain
> starts to contain any "<contains/>" element then it will start discarding
> all contents of the property file being read. This was tested  using  ant
> 1.10.1 adn 1.10.3 in a Java 1.8 VM hosted in a Windows 10 64-bit machine.
>
>    Below is my build xml and sample.properties file. The initialize target
> has different variations that I tried to do to isolate the problem. What
> could be the problem in this instance? Thanks.
>
> -- build.xml  ---
>
> <project name="MyProject" basedir=".">
>    <target name="initialize">
>      <echo>Starting load...</echo>
>      <loadproperties srcFile="${basedir}/01_PropertyFiles/sample.properties">
>
>        <filterchain>
>          <linecontains>
>            <contains value="ws.user" />
>            <contains value="ws.password" />
>            <contains value="wl.user" />
>            <contains value="wl.password" />
>          </linecontains>
>        </filterchain>
>
>        <!--filterchain>
>
>        <filterreader classname="org.apache.tools.ant.filters.LineContains">
>          <param type="contains" value="user"/>
>          <param type="contains" value="password"/>
>        </filterreader>
>
>
>        </filterchain-->
>
>
>      </loadproperties>
>      <echo>${ws.user} - ${ws.password}</echo>
>      <echo>${wl.user} - ${wl.password}</echo>
>
>      <echo>${placebo.prop} should be printed as a literal. </echo>
>
>    </target>
>
> </project>
>
>
> -- end of build.xml  ---
>
> ---- sample.properties ----
> placebo.prop=dontprintme
> ws.user=dilbert
> ws.password=washere
> wl.user=felix
> wl.password=lantern
>
> ps.xser=dummy
> ---- end of sample.properties ----
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Filterchain's LineContains on LoadProperties is blocking the reading of properties

Anuerin Diaz
Thanks Jaikiran. That is a very subtle behavior. I will try switching it
to LineContainsRegExp.  Is there another alternative of switching the
behavior to OR?

On Thu, Apr 19, 2018 at 12:21 PM, Jaikiran Pai <[hidden email]>
wrote:

> Hi Anuerin,
>
> Ifthere are more than one"contains" elements of the "linecontains", then
> as noted in the documentation[1]"and" will be used toevaluate whether the
> line contains those strings. So in the exampleyou pasted, the properties
> file will be looked for lines containing ws.user AND ws.password AND
> wl.user AND wl.password, which obviously won't be satisfied for the
> sample.properties.
>
> [1] https://ant.apache.org/manual/Types/filterchain.html#linecontains
>
> -Jaikiran
>
> On 19/04/18 7:28 AM, Anuerin Diaz wrote:
>
>> Hi,
>>
>>    I am trying to selectively load properties using the LoadProperties and
>> FilterChain+LineContains tasks. However based on my test if the
>> Filterchain
>> starts to contain any "<contains/>" element then it will start discarding
>> all contents of the property file being read. This was tested  using  ant
>> 1.10.1 adn 1.10.3 in a Java 1.8 VM hosted in a Windows 10 64-bit machine.
>>
>>    Below is my build xml and sample.properties file. The initialize target
>> has different variations that I tried to do to isolate the problem. What
>> could be the problem in this instance? Thanks.
>>
>> -- build.xml  ---
>>
>> <project name="MyProject" basedir=".">
>>    <target name="initialize">
>>      <echo>Starting load...</echo>
>>      <loadproperties srcFile="${basedir}/01_Propert
>> yFiles/sample.properties">
>>
>>        <filterchain>
>>          <linecontains>
>>            <contains value="ws.user" />
>>            <contains value="ws.password" />
>>            <contains value="wl.user" />
>>            <contains value="wl.password" />
>>          </linecontains>
>>        </filterchain>
>>
>>        <!--filterchain>
>>
>>        <filterreader classname="org.apache.tools.an
>> t.filters.LineContains">
>>          <param type="contains" value="user"/>
>>          <param type="contains" value="password"/>
>>        </filterreader>
>>
>>
>>        </filterchain-->
>>
>>
>>      </loadproperties>
>>      <echo>${ws.user} - ${ws.password}</echo>
>>      <echo>${wl.user} - ${wl.password}</echo>
>>
>>      <echo>${placebo.prop} should be printed as a literal. </echo>
>>
>>    </target>
>>
>> </project>
>>
>>
>> -- end of build.xml  ---
>>
>> ---- sample.properties ----
>> placebo.prop=dontprintme
>> ws.user=dilbert
>> ws.password=washere
>> wl.user=felix
>> wl.password=lantern
>>
>> ps.xser=dummy
>> ---- end of sample.properties ----
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
"Programming, an artform that fights back"

Anuerin G. Diaz
Registered Linux User #246176
http://ramfree17.net/capsule , when you absolutely have nothing else better
to do
Reply | Threaded
Open this post in threaded view
|

Re: Filterchain's LineContains on LoadProperties is blocking the reading of properties

Jaikiran Pai

On 19/04/18 10:03 AM, Anuerin Diaz wrote:
>   Is there another alternative of switching the
> behavior to OR?
Looking at the code, I don't see a way to switch it to OR. However, I do
think it might make a good enhancement to allow users to configure this
behaviour as an attribute of the "linecontains" filter (which will
default to AND). That way they aren't forced to use LineContainsRegExp
for something simple like this. Would you like to create a enhancement
request here[1], so that it can be tracked?


[1] https://bz.apache.org/bugzilla/enter_bug.cgi?product=Ant

-Jaikiran


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Filterchain's LineContains on LoadProperties is blocking the reading of properties

Anuerin Diaz
I will log the enhancement request as this can get messy if there are no
common properties and the option is multiple loading of the same file.

On Thu, Apr 19, 2018, 12:40 PM Jaikiran Pai <[hidden email]>
wrote:

>
> On 19/04/18 10:03 AM, Anuerin Diaz wrote:
> >   Is there another alternative of switching the
> > behavior to OR?
> Looking at the code, I don't see a way to switch it to OR. However, I do
> think it might make a good enhancement to allow users to configure this
> behaviour as an attribute of the "linecontains" filter (which will
> default to AND). That way they aren't forced to use LineContainsRegExp
> for something simple like this. Would you like to create a enhancement
> request here[1], so that it can be tracked?
>
>
> [1] https://bz.apache.org/bugzilla/enter_bug.cgi?product=Ant
>
> -Jaikiran
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Filterchain's LineContains on LoadProperties is blocking the reading of properties

Anuerin Diaz
https://bz.apache.org/bugzilla/show_bug.cgi?id=62313  has been logged.
Thanks!

On Thu, Apr 19, 2018 at 12:53 PM, Anuerin Diaz <[hidden email]> wrote:

> I will log the enhancement request as this can get messy if there are no
> common properties and the option is multiple loading of the same file.
>
> On Thu, Apr 19, 2018, 12:40 PM Jaikiran Pai <[hidden email]>
> wrote:
>
>>
>> On 19/04/18 10:03 AM, Anuerin Diaz wrote:
>> >   Is there another alternative of switching the
>> > behavior to OR?
>> Looking at the code, I don't see a way to switch it to OR. However, I do
>> think it might make a good enhancement to allow users to configure this
>> behaviour as an attribute of the "linecontains" filter (which will
>> default to AND). That way they aren't forced to use LineContainsRegExp
>> for something simple like this. Would you like to create a enhancement
>> request here[1], so that it can be tracked?
>>
>>
>> [1] https://bz.apache.org/bugzilla/enter_bug.cgi?product=Ant
>>
>> -Jaikiran
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>


--
"Programming, an artform that fights back"

Anuerin G. Diaz
Registered Linux User #246176
http://ramfree17.net/capsule , when you absolutely have nothing else better
to do