Вы можете использовать что-то вроде следующего, чтобы запускать определенные цели, только если текущий пользователь имеет определенное имя, например, «root».
<condition property="rootTasksEnabled">
<equals arg1="${user.name}" arg2="root" />
</condition>
<target name="do-stuff-if-root" if="rootTasksEnabled">
<echo>Doing root stuff</echo>
</target>
Что касается запуска Ant от имени другого пользователя, вы могли быиспользуйте с командой su для запуска другого процесса Ant:
<target name="do-stuff" depends="do-stuff-if-root, do-other-stuff" />
<condition property="rootTasksEnabled">
<equals arg1="${user.name}" arg2="root" />
</condition>
<property name="targetToRunAsOtherUser" value="do-stuff-as-other-user" />
<property name="otherUser" value="johnny" />
<target name="do-stuff-if-root" if="rootTasksEnabled">
<echo>Doing root stuff</echo>
<exec executable="su">
<arg value="-c" />
<arg value="${ant.home}/bin/ant -buildfile ${ant.file} ${targetToRunAsOtherUser}" />
<arg value="${otherUser}" />
</exec>
</target>
<target name="do-other-stuff">
<echo>Doing normal build stuff</echo>
</target>
<target name="do-stuff-as-other-user">
<echo>I am running as ${user.name}</echo>
<echo>My home is ${user.home}</echo>
</target>
Этот пример работает только под Unix.Для этого в Windows вы, вероятно, могли бы использовать команду runas вместо su .