Re: newbie - if-then-else task?
I tried the other way, using depends and targets. It is REALLY long, not succinct, and IMHO can lead to severe maintenance problems in the long run - therefore, I advocate leaving the available tag just the way it is. To do what I wanted using depends and targets, it roughly works like this (without too much correctness on the syntactical details): start of code // This sets a property, localfile.exists=true, if the file // exists locally target name=check.local available file=my_local_path/file property=localfile.exists/ /target // This calls the target that sets localfile.exists, then // if localfile.exists is true, it copies the file from the local // spot. target name=copy.from.local depends=check.local if=localfile.exists // copy from my_local_path/file to my_destination_dir /target // In the event that a local file does not exist, this target // goes to a system directory and fetches the file there. target name=copy.from.system depends=check.local unless=localfile.exists // copy from my_system_path/file to my_destination_dir /target // We need a dummy target to exercise the depends line and force // needed copying to occur. Try copying from local first, then // try copying from the system. target name=copyfile depends=copy.from.local, copy.from.system/ end of code This I believe is what you mean by the depends/unless method. If so, this is verbose, and prone to maintenance error. For instance, I have to maintain a copy of the local file in two separate tags. Also, where do I set a property that tells what file I want to copy? I would have potentially hundreds of files I want to copy, and it would be insane to have hundreds of targets, one per file. What would I do? I might end up setting a property, file.from, and then have to override it when I want to copy a different file - but that would run against the idea of having set-once (is this what is meant by 'immutable?') properties. Now that I'm standing on a soapbox, I would like to point out that if we wish to have a suitable build system replacement for Make, then it should support at least a basis vector of functionality from Make, to include among other things the ability to easily make choices at compile time depending on environment variables, tag names, and so on. Digging in deeper, I strongly suggest supporting in-line Java calls, in the form of an XML tag, that would be similar to how Make supports in-line shell script constructs (how Make executes shell code... well, that's all it does, actually). This would give some power to the build process, and should be fairly easy to implement - just compile all the inline java first, then include these classes in the VM when invoking ant. This would give me powerful file copying capabilities, decision making, pattern replacement, user-interface prompts (popup dialog boxes), string manipulation, and more. At least leave the available tag the way it is. Thanks for your help, Russ Okay - I think I understand. If I have 'dirs.orig' pointing to the global area, and dirs.local pointing to the local modified area, and want to put the file into 'dest', I can do the following: property name=frompath value=${dirs.orig}/foo/ available file=${dirs.local}/foo property=frompath value=${dirs.local}/foo/ copy file=${frompath} todir=${dirs.base}/dest/ I thought for sure Erik would reply to this, since it's using available in the very way he's currently trying to disallow, but... Anyway, yes, you -could- do it this way, but only because available allowed resetting the value of a property, which (according to Ant's immutable properties stance) it shouldn't really have been doing, and will now bark at you should you try to use it this way (and may well at some point not allow it at all). (This is still a little more work than I indended, [...] Well, Ant is exactly known for being all that succinct :) And if you think the above is a bit roundabout, you'll probably be not at all fond of how you should really be doing it, which would involve several targets, using depends and unless. Diane _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: newbie - if-then-else task?
--- Russ Fink [EMAIL PROTECTED] wrote: I tried the other way, using depends and targets. It is REALLY long, not succinct, Well, the way you did it is a bit more roundabout than you really need. For example (this one assumes the file is required): target name=copyFile depends=noFile copy file=${filename} todir=${dest.dir}/ /target target name=chkLocal available property=filename value=${local.dir}/foo.txt file=${local.dir}/foo.txt/ /target target name=chkSys depends=chkLocal unless=filename available property=filename value=${sys.dir}/foo.txt file=${sys.dir}/foo.txt/ /target target name=noFile depends=chkSys unless=filename echo message= Error:/ echo message= Couldn't find a foo.txt to copy.../ fail message=Exiting.../ /target I would have potentially hundreds of files I want to copy, If where you copy from depends on whether the local directory exists (as opposed to checking for specific files in that directory), you can change the available to check for the directory -- just add the type attribute, set to dir (and adjust your property-setting and copy accordingly). Digging in deeper, I strongly suggest supporting in-line Java calls, You can use script, or you can use in-house tasks. Diane = ([EMAIL PROTECTED]) __ Do You Yahoo!? Buy the perfect holiday gifts at Yahoo! Shopping. http://shopping.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: newbie - if-then-else task?
- Original Message - From: Russ Fink [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, December 04, 2001 7:19 PM Subject: Re: newbie - if-then-else task? I tried the other way, using depends and targets. It is REALLY long, not succinct, and IMHO can lead to severe maintenance problems in the long run - therefore, I advocate leaving the available tag just the way it is. To do what I wanted using depends and targets, it roughly works like this (without too much correctness on the syntactical details): start of code // This sets a property, localfile.exists=true, if the file // exists locally target name=check.local available file=my_local_path/file property=localfile.exists/ /target // This calls the target that sets localfile.exists, then // if localfile.exists is true, it copies the file from the local // spot. target name=copy.from.local depends=check.local if=localfile.exists // copy from my_local_path/file to my_destination_dir /target // In the event that a local file does not exist, this target // goes to a system directory and fetches the file there. target name=copy.from.system depends=check.local unless=localfile.exists // copy from my_system_path/file to my_destination_dir /target // We need a dummy target to exercise the depends line and force // needed copying to occur. Try copying from local first, then // try copying from the system. target name=copyfile depends=copy.from.local, copy.from.system/ 1. given copyfile does date based copying, I am not sure that you need to jump through these hoops. A copyfile on its own *usually* suffices. 2. you dont need the dummy target to get the dependences, just glue the two paths together and rely on them being skipped if the conditions are broken. target name=check.local available file=my_local_path/file property=localfile.exists/ /target target name=copy.from.local depends=check.local if=localfile.exists // copy from my_local_path/file to my_destination_dir /target // In the event that a local file does not exist, this target // goes to a system directory and fetches the file there. target name=copy-files depends=copy.from.local unless=localfile.exists // copy from my_system_path/file to my_destination_dir /target The other optimisation is just to have a probe target which checks for everything in one place; files, java classes, remote servers, executables on the path, etc. The advantage of that strategy is that all your dependencies are listed in one place, which can help maintainers. 3. But in this case I would use immutability to my own ends, along with the knowledge that copy doesnt copy onto itself property name=destfile location=my_local_path/file/ available file=${destfile} property=srcfile value==${destfile} / property name=srcfile location=my_system_path/file/ copy file=${srcfile} tofile=${destfile} / one target. one test. one action. four lines. Three if you skip the initial property declaration, but that is bad engineering. This I believe is what you mean by the depends/unless method. If so, this is verbose, and prone to maintenance error. For instance, I have to maintain a copy of the local file in two separate tags. Also, where do I set a property that tells what file I want to copy? I would have potentially hundreds of files I want to copy, and it would be insane to have hundreds of targets, one per file. What would I do? I might end up setting a property, file.from, and then have to override it when I want to copy a different file - but that would run against the idea of having set-once (is this what is meant by 'immutable?') properties. you can use antcall to call a target with a different set of properties. However, I agree that it doesnt scale. In that situation I would probably modify the copy task to have a new 'onlyifdestmissing' tag or equivalent; eight lines of code, plus 1 minute to rebuild ant. Now that I'm standing on a soapbox, I would like to point out that if we wish to have a suitable build system replacement for Make, then it should support at least a basis vector of functionality from Make, to include among other things the ability to easily make choices at compile time depending on environment variables, tag names, and so on. We have a condition tag to do these things, it now does more than make ever did; such as letting you probe for a TCP port on a remote server being available. What is still complex is acting on conditional values; the 'many targets' solution seems ungainly, but it is a simple model. It may be that a better conditional execution model can be designed, but it should be through Digging in deeper, I strongly suggest supporting in-line Java calls, in the form of an XML tag, that would be similar to how Make supports in-line shell script constructs (how Make executes shell code... well, that's all it does, actually). This would give some power to the build
newbie - if-then-else task?
Hello, I'm new at Ant and I will describe what I want to do -- followed with how I hope to do it. I'm trying to copy files from two sources, a system directory followed by a local directory. This is prior to a build, and I'm modifying an existing build file. What I want is to copy a file from a system directory, and if a file exists in a similar local structure, I want to copy that version. Both destinations are the same, i.e., a generated directory. I tried using the copy target to copy from the system location first, then the local directory second, and the problem is that the build fails if it doesn't find the file in the local directory. How I want to do this is to use conditional logic. Basically, if the local file exists, I want to use it, but if it doesn't exist, I want to use the system copy. Questions. Is this how you would do it? If so, what is the method for if-then-else or what can I use? I can't easily do this with available, since all that does is set a flag, which apparently can only be used in the target line. What I want is within a target, being able to evaluate a tag and take some action. I'm open to suggestions - Thanks, Russ PS: the manual is very good, but it would be much better if there were an index in it somewhat similar to Javadocs. _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: newbie - if-then-else task?
You can use available. It doesn't just set a flag -- you can assign any value to the property it's (potentially) setting, so have the value be the path to the file it finds, then reference that property in your copy task. If you can use a nightly build rather than a release, you can do this more easily, since, if the local file was found and therefore the filename-property was set to that, the second check (the one for the system file) won't (now) overwrite the value of the filename-property. If you need to use a release, you'll need to do it in a couple of more steps, but it's still quite doable. Diane --- Russ Fink [EMAIL PROTECTED] wrote: Hello, I'm new at Ant and I will describe what I want to do -- followed with how I hope to do it. I'm trying to copy files from two sources, a system directory followed by a local directory. This is prior to a build, and I'm modifying an existing build file. What I want is to copy a file from a system directory, and if a file exists in a similar local structure, I want to copy that version. Both destinations are the same, i.e., a generated directory. I tried using the copy target to copy from the system location first, then the local directory second, and the problem is that the build fails if it doesn't find the file in the local directory. How I want to do this is to use conditional logic. Basically, if the local file exists, I want to use it, but if it doesn't exist, I want to use the system copy. Questions. Is this how you would do it? If so, what is the method for if-then-else or what can I use? I can't easily do this with available, since all that does is set a flag, which apparently can only be used in the target line. What I want is within a target, being able to evaluate a tag and take some action. I'm open to suggestions - Thanks, Russ PS: the manual is very good, but it would be much better if there were an index in it somewhat similar to Javadocs. _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] = ([EMAIL PROTECTED]) __ Do You Yahoo!? Buy the perfect holiday gifts at Yahoo! Shopping. http://shopping.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: newbie - if-then-else task?
Ha! I knew I'd find a way to get a correction on Diane if I waited long enough :) Actually the back-door hack for available is being left in (just with a nasty message if you overwrite a propertys value using it) - that was the curreent consensus, unfortunately. This may change before the release of 1.5, but thats how it exists in the nightly builds now though. Erik crossing my fingers that I got this answer right - Original Message - From: Diane Holt [EMAIL PROTECTED] To: Ant Users List [EMAIL PROTECTED] Sent: Monday, December 03, 2001 2:58 PM Subject: Re: newbie - if-then-else task? You can use available. It doesn't just set a flag -- you can assign any value to the property it's (potentially) setting, so have the value be the path to the file it finds, then reference that property in your copy task. If you can use a nightly build rather than a release, you can do this more easily, since, if the local file was found and therefore the filename-property was set to that, the second check (the one for the system file) won't (now) overwrite the value of the filename-property. If you need to use a release, you'll need to do it in a couple of more steps, but it's still quite doable. Diane --- Russ Fink [EMAIL PROTECTED] wrote: Hello, I'm new at Ant and I will describe what I want to do -- followed with how I hope to do it. I'm trying to copy files from two sources, a system directory followed by a local directory. This is prior to a build, and I'm modifying an existing build file. What I want is to copy a file from a system directory, and if a file exists in a similar local structure, I want to copy that version. Both destinations are the same, i.e., a generated directory. I tried using the copy target to copy from the system location first, then the local directory second, and the problem is that the build fails if it doesn't find the file in the local directory. How I want to do this is to use conditional logic. Basically, if the local file exists, I want to use it, but if it doesn't exist, I want to use the system copy. Questions. Is this how you would do it? If so, what is the method for if-then-else or what can I use? I can't easily do this with available, since all that does is set a flag, which apparently can only be used in the target line. What I want is within a target, being able to evaluate a tag and take some action. I'm open to suggestions - Thanks, Russ PS: the manual is very good, but it would be much better if there were an index in it somewhat similar to Javadocs. _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] = ([EMAIL PROTECTED]) __ Do You Yahoo!? Buy the perfect holiday gifts at Yahoo! Shopping. http://shopping.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: newbie - if-then-else task?
Okay - I think I understand. If I have 'dirs.orig' pointing to the global area, and dirs.local pointing to the local modified area, and want to put the file into 'dest', I can do the following: property name=frompath value=${dirs.orig}/foo/ available file=${dirs.local}/foo property=frompath value=${dirs.local}/foo/ copy file=${frompath} todir=${dirs.base}/dest/ The first line sets the default to the orig directory; the second line overrides the value of 'frompath' if there exists a file in the .local directory, and the last line does the copy with whatever the value of the variable happens to be. (This is still a little more work than I indended, but I guess that's why there's Perl/Awk to add these lines into my customizations on build.xml.) Thanks for the help, Russ _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]