Redefining things which aren't properties

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

Redefining things which aren't properties

Christopher Schultz
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

All,

I've been using ant for ... ever. And I just got caught by something
that I didn't expect.

I've come to expect that property values cannot be changed after they
have been set; that is, they are write-once and then they are constants.

Due to a mistake in a somewhat complicated build file, I discovered
that pattern sets can be redefined in a way that is fairly surprising
to this seasoned ant user.

For example:

  <target name="foo">
    <echo>${toString:property.file.pattern}</echo>
    <patternset id="property.file.pattern" includes="**/*.properties" />
    <echo>${toString:property.file.pattern}</echo>
    <patternset id="property.file.pattern" includes="**/*.xml" />
    <echo>${toString:property.file.pattern}</echo>
  </target>

Running this target will produce the following output:

foo:
     [echo] ${toString:property.file.pattern}
     [echo] patternSet{ includes: [**/*.properties] excludes: [] }
     [echo] patternSet{ includes: [**/*.xml] excludes: [] }

Surprised? I definitely was.

My problem was that I had a target somewhere with something similar to:

  <copy toDir="{dir}">
    <fileset dir="${properties.dir}">
      <patternset id="property.file.pattern" />
    </fileset>
  </copy>

Without realizing it, the above lines will redefine the patternset
called "property.file.pattern" to contain *nothing*. Oops. Definitely
my mistake, but ... I didn't really expect that ant would allow me to
override the previous definition of the patternset.

Is this intentional? Or should patternset definitions also be
immutable similar to property values?

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl5ISnEACgkQHPApP6U8
pFhKIg/+Lz9O0+CziqHFQ1+3cV9BAaMGiSRE2iDTRlxEPW9bDYie1cVwbrs6/NPm
UZZguCBKyna/qUoym+nGf3DqCoop79DFGacajIde35K2bCClZx2p3m6VCDvrFB8j
LCYcT2AgJrZYxvMIVVMMY5h1B9hzXCJol5VnjHLCakrwJtG4pLWxbkJ1ZlOUh7wM
qO39f6prH+4hpRdBKpFEG8UEg66Ywm33o9TNDy07qPpIyIJu8Zn/Fs3ttY6TVhfW
e4oav1aG+15nLi8QYpNQiMwoOzyWwb8rhJr2yLfTwBoynYfZMvbb4UsWDHaAIrjF
5LelZuOCVAyo/GMTkyrKddTZ4irBqa5X0Oxma2Lh7TJyzZtU3zpKak+aYhsfJ9/e
cvr11srZxpyj66CTOUEM16FAzujEqrRiV5kxs/oFisEMYgESm2qgib5+JBxeBQ6D
AI3K2JoscF958fGqphFCaYrk4KhOVoCFV4twz19xdJWyMvTjo01mxXKivrh3Aptm
9mS/PGt7VRIr8XSVhkRPvZq7adJxvfKinB1Y4NT2bGb1RmWHcVACwVVqRTbLRoAM
Z/NmMHDCf3YjA4+PwgbrrD5eG53rF0JBLBvOlQQ3sAJF16+pc+CKm4ZahWuO4Nii
cv42PVm2bhrAfXDC54ACHZqVs/EPrKCsppLy2FwSsqa5xk3UAPE=
=Zkat
-----END PGP SIGNATURE-----

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

Reply | Threaded
Open this post in threaded view
|

Re: Redefining things which aren't properties

Stefan Bodewig
On 2020-02-15, Christopher Schultz wrote:

> Due to a mistake in a somewhat complicated build file, I discovered
> that pattern sets can be redefined in a way that is fairly surprising
> to this seasoned ant user.

Yes, you references can be re-assigned. I'm not sure whether we have
this documented properly, anywhere, probably not. At least you should
see a warning.

Historically properties became immutable (pre Ant 1.1) by accident and
then we thought this was neat and kept it that way. References OTOH have
never been immutable and I know a few build processes that rely on this
behavior.

Stefan

signature.asc (186 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Redefining things which aren't properties

Christopher Schultz
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Stefan,

On 2/21/20 11:44, Stefan Bodewig wrote:

> On 2020-02-15, Christopher Schultz wrote:
>
>> Due to a mistake in a somewhat complicated build file, I
>> discovered that pattern sets can be redefined in a way that is
>> fairly surprising to this seasoned ant user.
>
> Yes, you references can be re-assigned. I'm not sure whether we
> have this documented properly, anywhere, probably not. At least you
> should see a warning.
>
> Historically properties became immutable (pre Ant 1.1) by accident
> and then we thought this was neat and kept it that way. References
> OTOH have never been immutable and I know a few build processes
> that rely on this behavior.

Aha, okay. I was mostly wondering if this was a bug or intended
behavior. "Most likely ?? intended behavior" is a reasonable response :)

It would be a good idea to explicitly document the intended behavior,
here. If properties are immutable, we should say so (I'm sure that's
there already). If reference names are *mutable*, then *that* should
be explicitly noted and I'm almost positive it's nowhere in the
documentation.

Thanks!
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl5QDykACgkQHPApP6U8
pFja+Q/+PwOHj4zOBrxm18DXcRZ9PmzGHO/RmnQolUrIQASDjBhJJyggA2dpybjq
tPVwKM1ESKhdOGqsSaZpccUlcQhSMo2RzfXGcU4QJPvxD1aahDzsMr2Meha/MjNJ
11vQfX2Tg34LbFO0y1xmcGTBB5V3XEg7GLtu9N0LmQHdcftxLh/HplBLbhHOIx3R
g5s3sNi03joBq0lXdmhx6U+L7VAlnVyd4So8leATo2Qr0+9hUENGITkqstO6vFjc
WOCDT6ZiAX5l8Ne2KIkuWANlk4J3k5Oy3Z4axyJM98Xg48Zm5KdN0IQenS93PV0r
8CvHdw5xbBcpKTTXZB3JplcdXf2s3wfWl/R5ioXMuB37Gjxxijbexa2XQmpyklLp
N1nqxUWH8478mTz+Cj8bsWor+bKtvidLYXtniFjux5BFEwvmmDJg30ALpubSEgqD
XKGaP6NlliqdP/MARL//9P23sMADEUnfUlbdTxnBiob0RxR5lp3CIg3WyytqwGbk
em40kXCOtvkUH5OZFgJK3CvGzvSZE1OLoG/FGUS6BCVy9a5V5OYaIkA1uf/K5Itz
C48e/v0gUqtkQSBDnEm15iZpNd0sqSzbXjDotWoer18hqJ8R92C4BJvQYKXcxNcL
4pOdzMbPuidZgAJeZzMzQVWjcnT8r/ZC3TsTyHN27j50VA/fV+c=
=N9rk
-----END PGP SIGNATURE-----

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