On Sun, Nov 21, 2010 at 10:22 PM, ritchie <ganesh.devaraj...@baml.com> wrote:
>
> I am trying to add new attributes to a xml file using classes available in
> com.oopsconsultancy.xmltask.ant.XmlTask classes but not able to write to the
> file because it is write protected. Is it possible to edit a write protected
> xml file using ant script?

First question in my mind is why is this file write protected? Ant is
mainly used in CM purposes, and a write protected file is usually
write protected for good reasons. Some systems, like Perforce, want
you to put the file in "Edit" mode, so they can track which files were
changed. Other times, a locked file is due to a commit deadlock that
needs to be resolved.

As Antoine wrote, you can use "chmod" or "attrib" tasks to change the
permissions on this file, but unfortunately, these tasks are operating
system specific which makes them problematic to use. You might as well
run "exec" on the chmod command or "attrib" command in Unix or
Windows. To me, Ant scripts should be as portable as possible. I don't
know why Ant itself comes with two separate versions of a command to
change the read/write attribute of a file which ends up making Ant
scripts operating system dependent.

What might be better is to use a "copy" task. You can copy the
original file over, make the changes there, then copy it back to where
it should be. With
the copy task, you can specify the force parameter that will overwrite
copy protected files. Plus, you can make sure that all changes in this
file have been completed before replacing the file.  This can make it
easier to restore your system in case something causes your Ant script
to fail.

Remember Ant scripts can fail for reasons not related to the logic of
your Ant script. You could end up with a JVM error or run out of
memory. A half written file could cause problems. Plus, you also want
to understand the implications if you have this Ant script being
executed simultaneously as two separate processes.

-- 
David Weintraub
qazw...@gmail.com

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

Reply via email to