ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Baz" <ba...@goodconsultants.com>
Subject cp or <copy> in windows? and in unix like system
Date Wed, 17 Mar 2004 15:43:35 GMT
Jan, Jack and all,

Funny thing is... I wasted a day searching for a better solution such as
<chmod>, blah blah, but still going back to same implementation as Jan's :)

However, I am not using OS to switch between perm copy and nonperm copy. I
use the avaiilability of the command "uname". If you can do "uname" in the
environment, then it is "unixlike"... Perm copy is using "cp -rp" and its
for unix like system. Non perm copy is using <copy> and its for non unix
like system.

Here is the code and I hope that it is useful and please comment if it works
or not.

<target name="deploy"
    depends="check,pre-deploy, deploy-unix,deploy-dos,post-deploy"/>


<target name="pre-deploy">

    <delete dir="${serverdeploy.home}/bin"/>
    <delete dir="${serverdeploy.home}/certs"/>
    <delete dir="${serverdeploy.home}/conf"/>
    <delete dir="${serverdeploy.home}/webapps/${app.name}"/>
    <delete file="${serverdeploy.home}/webapps/${app.name}.war"/>

    <mkdir dir="${serverdeploy.home}"/>
    <mkdir dir="${serverdeploy.home}/lib"/>
    <mkdir dir="${serverdeploy.home}/logs"/>
    <mkdir dir="${serverdeploy.home}/temp"/>
    <mkdir dir="${serverdeploy.home}/uploads"/>
    <mkdir dir="${serverdeploy.home}/webapps"/>
    <mkdir dir="${serverdeploy.home}/bin"/>
    <mkdir dir="${serverdeploy.home}/conf"/>
    <mkdir dir="${serverdeploy.home}/certs"/>

</target>

<target name="check">

    <exec executable="uname" failifexecutionfails="false"
        errorproperty="is.UnixStyle"/>

    <condition property="is.DosStyle">
    <not>
    <isset property="is.UnixStyle"/>
    </not>
    </condition>

    <echo message="Style is ${is.UnixStyle}"/>
    <echo message="Style is ${is.DosStyle}"/>

</target>

<target name="deploy-unix" if="is.UnixStyle">

    <echo message="This is a unix style system."/>
    <exec executable="cp" >
        <arg value="-rp"/>
        <arg value="../bin"/>
        <arg value="${serverdeploy.home}"/>
    </exec>

    <exec executable="cp" >
        <arg value="-rp"/>
        <arg value="../certs"/>
        <arg value="${serverdeploy.home}"/>
    </exec>

    <exec executable="cp" >
        <arg value="-rp"/>
        <arg value="../conf"/>
        <arg value="${serverdeploy.home}"/>
    </exec>

</target>

<target name="deploy-dos" if="is.DosStyle">

    <echo message="This is a unix style system."/>
    <copy todir="${serverdeploy.home}/bin">
    <fileset dir="../bin"/>
    </copy>

    <chmod perm="a+rx" type="file">
    <fileset dir="${serverdeploy.home}/bin"/>
    </chmod>

    <copy todir="${serverdeploy.home}/certs">
    <fileset dir="../certs"/>
    </copy>

    <chmod perm="a+r" type="file">
    <fileset dir="${serverdeploy.home}/certs"/>
    </chmod>

    <copy todir="${serverdeploy.home}/conf">
    <fileset dir="../conf"/>
    </copy>

    <chmod perm="a+rx" type="file">
    <fileset dir="${serverdeploy.home}/conf"/>
    </chmod>

    <chmod perm="a-w" type="file">
    <fileset dir="${serverdeploy.home}/bin"/>
    <fileset dir="${serverdeploy.home}/conf"/>
    <fileset dir="${serverdeploy.home}/certs"/>
    </chmod>

</target>

<target name="post-deploy">

    <copy file="${dist.home}/${app.name}.war"
        todir="${serverdeploy.home}/webapps"/>

</target>



----- Original Message ----- 
From: <Jan.Materne@rzf.fin-nrw.de>
To: <user@ant.apache.org>
Sent: Monday, March 15, 2004 10:36 PM
Subject: RE: cp or <copy> in windows?


> Using <copy> you can copy the files in a cross platform manner.
>
> Setting the permissions the perms of the original files is another
> topic. <chmod> is used to set permission. But there is no easy way
> to "copy" the permissions from one fileset to a target. You can
> use <script> and <chmod>: iterate over a src-fileset, if the file exists
> in a target dir, get the file permissions from src and set them on target.
>
> If "cp" does the job you can use dependend targets for copying:
>
>   <target name="copy"
> depends="copy.check,copy.withPerms,copy.withoutPerms"/>
>
>   <taret name="copy.check">
>       <condition property="copy.withPerms">
>           <os family="unix"/>
>       </>
>   </>
>
>   <target name="copy.withoutPerms" unless="copy.withPerms">
>       <copy> ... </>
>   </>
>
>   <target name="copy.withPerms" if="copy.withPerms">
>       <exec executable="sh"><arg line="cp ..."/></>
>   </>
>
> (syntax not checked :)
>
>
> Jan
>
> > -----Original Message-----
> > From: Baz [mailto:barry@goodconsultants.com]
> > Sent: Tuesday, March 16, 2004 6:02 AM
> > To: Ant Users List
> > Subject: cp or <copy> in windows?
> >
> >
> > All,
> >
> > I am trying to support both Dos and cygwin in Windows  as
> > well as all Unix
> > platforms. I am trying to copy some files and was using
> > <copy>, and soon
> > enough, i found out from the manual that the <copy> does not preserve
> > permission and using "cp" is recommended.
> >
> > So my question is: How can copy files in a task that is cross
> > platform?
> >
> > Thanks.
> >
> > Barry
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
>



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


Mime
View raw message