You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by michael sorens <ms...@myrealbox.com> on 2005/01/29 22:13:34 UTC

manipulating property strings

Is there a way to manipulate the contents of a multi-line property string as if it were a file?
Right now I collect stderr of an exec to a temp-file (error="filename") then read the temp-file and manipulate via filterchain, storing into a property, as in:

<exec executable="perl" dir="${mirror.bin}"
	outputproperty="null.storage"
	error="${mirror.bin}/temp.out">
...
</exec>

<loadfile srcfile="${mirror.bin}/temp.out" property="run.error">
	<filterchain>
		<linecontains>
			<contains value="*** ERROR"/>
		</linecontains>
	</filterchain>
</loadfile>

...then deleting the temp-file.

I'm looking for a more elegant solution.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: manipulating property strings

Posted by michael sorens <ms...@myrealbox.com>.
Ahhh... thanks for that refinement; that handles what I need.

On Wed, 2 Feb 2005 09:48:06 -0800 (PST), Matt Benson <gu...@yahoo.com> wrote:

> --- michael sorens <ms...@myrealbox.com> wrote:
>
>> With the pointer to the <redirector>, I was able to
>> rewrite the task to avoid a temp file. However, that
>> introduced a different problem.
>
> [SNIP]
>
> Instead of <fail if="whatever" message="foo" /> you
> can use (since Ant 1.6.2):
> <fail message="foo">
>   <condition>
>     <and>
>       <isset property="whatever" />
>       <not>
>         <equals arg1="${whatever}" arg2=""
>                 trim="true" />
>       </not>
>     </and>
>   </condition>
> </fail>
>
> HTH,
> Matt
>
>
> 		
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - Helps protect you from nasty viruses.
> http://promotions.yahoo.com/new_mail
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: manipulating property strings

Posted by Matt Benson <gu...@yahoo.com>.
--- michael sorens <ms...@myrealbox.com> wrote:

> With the pointer to the <redirector>, I was able to
> rewrite the task to avoid a temp file. However, that
> introduced a different problem.

[SNIP]

Instead of <fail if="whatever" message="foo" /> you
can use (since Ant 1.6.2):
<fail message="foo">
  <condition>
    <and>
      <isset property="whatever" />
      <not>
        <equals arg1="${whatever}" arg2=""
                trim="true" />
      </not>
    </and>
  </condition>
</fail>

HTH,
Matt


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Helps protect you from nasty viruses. 
http://promotions.yahoo.com/new_mail

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: manipulating property strings

Posted by michael sorens <ms...@myrealbox.com>.
With the pointer to the <redirector>, I was able to rewrite the task to avoid a temp file. However, that introduced a different problem.

When I do this sequence (i.e. *with* a temp file):
CASE 1:
	<exec error="tempfile"...
	<loadfile srcfile="tempfile" property="errors.present"><filterchain>...
	<fail if "errors.present">...
and there are NO errors (i.e. the filterchain that greps for error messages left errors.present unset), the fail is not executed. (This is the desired behavior.)

However, when I do this (without a temp file):
CASE 2:
	<exec...><redirector errorproperty="errors.present"><errorfilterchain>...
	<fail if "errors.present">...
then the fail *is* executed even when there are NO error messages collected by the errorfilterchain.

The problem, of course, is that the property is being set (albeit to an empty value) which, to ant, means it is true.

So: any way to make CASE 2 behave like CASE 1? Or, failing that, is there anyway to examine a property with "higher" resolution, i.e. to notice that it has an empty string or a non-empty string?

Here's a concrete example. As shown, two lines contain error messages, so the fail is executed showing those two lines. If you delete the "ERR" from both lines, the "fail" is still executed.

     <target name="redirect-test">
		<property name="testfile" value="/usr/tmp/test.dat"/>
		<echo file="${testfile}">
line one
ERR line two
line three
line ERR four
		</echo>
		<exec executable="perl" dir=".">
			<arg line="-ne 'print' ${testfile}"/>
			<redirector outputproperty="redirector.out">
				<outputfilterchain>
					<linecontains>
						<contains value="ERR"/>
					</linecontains>
				</outputfilterchain>
			</redirector>
		</exec>
		<delete file="${testfile}"/>
		<fail message="[[${redirector.out}]]" if="redirector.out"/>
     </target>



On Mon, 31 Jan 2005 08:17:52 -0800 (PST), Matt Benson <gu...@yahoo.com> wrote:

> --- michael sorens <ms...@myrealbox.com> wrote:
>
>> Is there a way to manipulate the contents of a
>> multi-line property string as if it were a file?
>> Right now I collect stderr of an exec to a temp-file
>> (error="filename") then read the temp-file and
>> manipulate via filterchain, storing into a property,
> [SNIP]
>> ...then deleting the temp-file.
>>
>> I'm looking for a more elegant solution.
>
> Jan's example on redirector is not quite cut & paste
> but it should give you the idea.  If you can't get it
> working after reading the manual and playing around
> for a while let us know.
>
> Thanks,
> Matt
>
>
>
>
> 		
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - Easier than ever with enhanced search. Learn more.
> http://info.mail.yahoo.com/mail_250
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: manipulating property strings

Posted by Matt Benson <gu...@yahoo.com>.
--- michael sorens <ms...@myrealbox.com> wrote:

> Is there a way to manipulate the contents of a
> multi-line property string as if it were a file?
> Right now I collect stderr of an exec to a temp-file
> (error="filename") then read the temp-file and
> manipulate via filterchain, storing into a property,
[SNIP]
> ...then deleting the temp-file.
> 
> I'm looking for a more elegant solution.

Jan's example on redirector is not quite cut & paste
but it should give you the idea.  If you can't get it
working after reading the manual and playing around
for a while let us know.

Thanks,
Matt




		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org