You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Júlio Cesar Bueno Cotta <ju...@gmail.com> on 2009/07/29 22:21:24 UTC

compare files line by line

Hello good people
I am here again needing some help
now I need to do a I script to compare two ".properties"..like

First file Name: dev.properties
@var1@=test1

@var2@=test2
@var3@=test3

Secund fiel Name: prd.properties
# comment
@var1@=test1

@var2@=test1037

@var4@=test4


I need to compare these two files and so fail the build if then have some
differences..
The files need to have the same numer of lines and each line must to have
the same variable declared or to be a empty line or a comment.
The variables declared in dev.properties must by declared ( in the same
order ) in prd.properties and the variables in prd.properties must by in
dev.properties, but the values of these variables can be different.
So..the files should be like this to don't fail the build:

dev.properties
# comment
@var1@=test1

@var2@=test2

@var3@=test3

@var4@=test4

prd.properties
# comment
@var1@=test1

@var2@=test1037

@var3@=test3

@var4@=test4123

That seens to be a idiot thing to do..but when I do a compare between these
files
I was trying to find something here
http://ant.apache.org/manual/CoreTypes/filterchain.html#linecontainsregexp

but I didn't find I way to compare line by line and I way to get the piece
of each line before the "=" signal.
the linecontainsregexp return all the line ..is there a "split method" in
Ant ?
Thanks all!

-- 
  Júlio Cesar Bueno Cotta
Graduando em ciência da computação
   Universidade Federal de Viçosa

RE: compare files line by line

Posted by Felix Dorner <FD...@zed.com>.
> I am here again needing some help
> now I need to do a I script to compare two ".properties"..like

I'd just write a custom task for these kind of things. Then you're done within an hour, taking Hofstadters law into account.
If you've never written a custom task, your objective sounds like a good exercise.

Cheers,
Felix.


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


Re: compare files line by line

Posted by David Weintraub <qa...@gmail.com>.
Take a look at this task: <
http://ant.apache.org/manual/OptionalTasks/replaceregexp.html>

And, then take a look at this: <
http://ant.apache.org/manual/CoreTypes/regexp.html>

It appears that the two might be related. If that's the case, you might be
able to use the <replaceregexp> somehow in the <regexp>.

Also take a look at TokenFilters <
http://ant.apache.org/manual/CoreTypes/filterchain.html#tokenfilter>. These
also work in filter chains.

I'll take a look at this, and see if I can figure out how to do a
comparison. I suspect that you have to do two loadreferences to get the file
contents into two properties and then do a compare among the properties.

2009/7/29 Júlio Cesar Bueno Cotta <ju...@gmail.com>

> Hello good people
> I am here again needing some help
> now I need to do a I script to compare two ".properties"..like
>
> First file Name: dev.properties
> @var1@=test1
>
> @var2@=test2
> @var3@=test3
>
> Secund fiel Name: prd.properties
> # comment
> @var1@=test1
>
> @var2@=test1037
>
> @var4@=test4
>
>
> I need to compare these two files and so fail the build if then have some
> differences..
> The files need to have the same numer of lines and each line must to have
> the same variable declared or to be a empty line or a comment.
> The variables declared in dev.properties must by declared ( in the same
> order ) in prd.properties and the variables in prd.properties must by in
> dev.properties, but the values of these variables can be different.
> So..the files should be like this to don't fail the build:
>
> dev.properties
> # comment
> @var1@=test1
>
> @var2@=test2
>
> @var3@=test3
>
> @var4@=test4
>
> prd.properties
> # comment
> @var1@=test1
>
> @var2@=test1037
>
> @var3@=test3
>
> @var4@=test4123
>
> That seens to be a idiot thing to do..but when I do a compare between these
> files
> I was trying to find something here
> http://ant.apache.org/manual/CoreTypes/filterchain.html#linecontainsregexp
>
> but I didn't find I way to compare line by line and I way to get the piece
> of each line before the "=" signal.
> the linecontainsregexp return all the line ..is there a "split method" in
> Ant ?
> Thanks all!
>
> --
>  Júlio Cesar Bueno Cotta
> Graduando em ciência da computação
>   Universidade Federal de Viçosa
>



-- 
David Weintraub
qazwart@gmail.com

RE: compare files line by line

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 

-----Original Message-----
From: Júlio Cesar Bueno Cotta [mailto:juliocbcotta@gmail.com] 
Sent: Wednesday, July 29, 2009 10:21 PM
To: Ant Users List
Subject: compare files line by line
/*
Hello good people
I am here again needing some help
now I need to do a I script to compare two ".properties"..like

[...]

I need to compare these two files and so fail the build if then have some
differences..
[...]
*/

for a simple check, whether files are equal use
condition / filesmatch, example =

<condition property="propsrequal">
  <filesmatch file1=".." file2=".."/>
</condition>

<target name="foo" if="propsrequal">
  <echo> Files are equal ..</echo>
 </target>


Regards, Gilbert



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