You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@locus.apache.org on 2000/07/04 11:30:29 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Chmod.java

bodewig     00/07/04 02:30:26

  Modified:    docs     index.html
               src/main/org/apache/tools/ant/taskdefs Chmod.java
  Log:
  Make Chmod a MatchingTask.
  Submitted by:	Mariusz Nowostawski <mn...@infoscience.otago.ac.nz>
  
  Revision  Changes    Path
  1.36      +62 -4     jakarta-ant/docs/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/index.html,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- index.html	2000/07/04 08:51:47	1.35
  +++ index.html	2000/07/04 09:30:05	1.36
  @@ -620,8 +620,18 @@
   <hr>
   <h2><a name="chmod">Chmod</a></h2>
   <h3>Description</h3>
  -<p>Changes the permissions of a file. Right now it has efect only under Unix.
  +<p>Changes the permissions of a file or all files inside a specified directory. Right now it has efect only under Unix.
   The permissions are also UNIX style, like the argument for the chmod command.</p>
  +<p>It is possible to refine the set of files whose permissions are changed. This can be
  +done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
  +attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
  +have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
  +the files you want to have excluded. This is also done with patterns. And
  +finally with the <i>defaultexcludes</i> attribute, you can specify whether you
  +want to use default exclusions or not. See the section on <a
  +href="#directorybasedtasks">directory based tasks</a>, on how the
  +inclusion/exclusion of files works, and how to write patterns. The patterns are
  +relative to the <i>dir</i> directory.</p>
   <h3>Parameters</h3>
   <table border="1" cellpadding="2" cellspacing="0">
     <tr>
  @@ -630,23 +640,71 @@
       <td align="center" valign="top"><b>Required</b></td>
     </tr>
     <tr>
  +    <td valign="top">file</td>
  +    <td valign="top">the file or single directory of which the permissions 
  +      must be changed.</td>
  +    <td valign="top" valign="middle" rowspan="2">exactly one of the two</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">dir</td>
  +    <td valign="top">the directory which holds the files whose permissions 
  +      must be changed.</td>
  +  </tr>
  +  <tr>
       <td valign="top">src</td>
  -    <td valign="top">the file of which the permissions must be changed.</td>
  -    <td valign="top" align="center">Yes</td>
  +    <td valign="top">the file or single directory of which the permissions 
  +      must be changed (<b>deprecated</b>, use <i>file</i> instead).</td>
  +    <td valign="top" align="center">No</td>
     </tr>
     <tr>
       <td valign="top">perm</td>
       <td valign="top">the new permissions.</td>
       <td valign="top" align="center">Yes</td>
     </tr>
  +  <tr>
  +    <td valign="top">includes</td>
  +    <td valign="top">comma separated list of patterns of files that must be
  +      included. All files are included when omitted.</td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">includesfile</td>
  +    <td valign="top">the name of a file. Each line of this file is
  +      taken to be an include pattern</td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">excludes</td>
  +    <td valign="top">comma separated list of patterns of files that must be
  +      excluded. No files (except default excludes) are excluded when omitted.</td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">excludesfile</td>
  +    <td valign="top">the name of a file. Each line of this file is
  +      taken to be an exclude pattern</td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">defaultexcludes</td>
  +    <td valign="top">indicates whether default excludes should be used or not
  +      (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
   </table>
   <h3>Examples</h3>
   <blockquote>
  -  <p><code>&lt;chmod src=&quot;${dist}/start.sh&quot; perm=&quot;ugo+rx&quot;
  +  <p><code>&lt;chmod file=&quot;${dist}/start.sh&quot; perm=&quot;ugo+rx&quot;
     /&gt;</code></p>
   </blockquote>
   <p>makes the &quot;start.sh&quot; file readable and executable for anyone on a
   UNIX system.</p>
  +<pre>
  +    &lt;chmod dir=&quot;${dist}/bin&quot; perm=&quot;ugo+rx&quot; includes="**/*.sh" /&gt;
  +</pre>
  +</blockquote>
  +<p>makes all &quot;.sh&quot; files below <code>${dist}/bin</code>
  +readable and executable for anyone on a UNIX system.</p>
   <hr>
   <h2><a name="copydir">Copydir</a></h2>
   <h3>Description</h3>
  
  
  
  1.3       +47 -14    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Chmod.java
  
  Index: Chmod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Chmod.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Chmod.java	2000/02/28 02:17:57	1.2
  +++ Chmod.java	2000/07/04 09:30:21	1.3
  @@ -60,33 +60,66 @@
   import java.util.*;
   
   /**
  + * Chmod equivalent for unix-like environments.
    *
  - *
    * @author costin@eng.sun.com
  + * @author Mariusz Nowostawski (Marni) <a href="mailto:mnowostawski@infoscience.otago.ac.nz">mnowostawski@infoscience.otago.ac.nz</a>
    */
   
  -public class Chmod extends Task {
  +public class Chmod extends MatchingTask {
   
  -    private File srcFile;
  +    private File srcFile; //if we want to chmod a single file or dir
  +    private File srcDir;  //if we want to chmod a list of files
       private String mod;
       
  +    public void setFile(String src) {
  +        srcFile = project.resolveFile(src);
  +    }
  +
  +    public void setDir(String src) {
  +        srcDir = project.resolveFile(src);
  +    }
  +
       public void setSrc(String src) {
  -	srcFile = project.resolveFile(src);
  +        project.log("The src attribute is deprecated. " +
  +                    "Please use the file attribute.",
  +                    Project.MSG_WARN);
  +        setFile(src);
       }
   
       public void setPerm(String perm) {
  -	mod=perm;
  +        mod=perm;
       }
   
       public void execute() throws BuildException {
  -	try {
  -	    // XXX if OS=unix
  -	    if (System.getProperty("path.separator").equals(":") &&
  -                    !System.getProperty("os.name").startsWith("Mac"))
  -		Runtime.getRuntime().exec("chmod " + mod + " " + srcFile );
  -	} catch (IOException ioe) {
  -	    // ignore, but warn
  -	    System.out.println("Error chmod" + ioe.toString() );
  -	}
  +        try {
  +            // XXX if OS=unix
  +            if (System.getProperty("path.separator").equals(":") &&
  +                !System.getProperty("os.name").startsWith("Mac")) {
  +        
  +                if (srcFile != null && srcDir == null) {
  +                    chmod(srcFile.toString());
  +                } else if(srcFile == null && srcDir == null) {
  +                    project.log("The attribute 'file' or 'dir' needs to be set.", Project.MSG_WARN);
  +                    throw new BuildException("Required attribute not set in Chmod", location);
  +                } else if(srcFile == null && srcDir != null) {
  +          
  +                    DirectoryScanner ds = getDirectoryScanner(srcDir);
  +                    String[] files = ds.getIncludedFiles();
  +          
  +                    for (int i = 0; i < files.length; i++) {
  +                        chmod(files[i]);
  +                    }
  +                }
  +            }
  +        } catch (IOException ioe) {
  +            // ignore, but warn
  +            project.log("Error in Chmod " + ioe.toString() , Project.MSG_WARN);
  +        }
  +    }
  +
  +
  +    private void chmod(String file) throws BuildException, IOException {
  +        Runtime.getRuntime().exec("chmod " + mod + " " + file);
       }
   }
  
  
  

Re: cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Chmod.java

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "CM" == Conor MacNeill <co...@m64.com> writes:

 CM> I assume you have left the deprecated form of the chmod
 CM> task in the build.xml file to avoid the nightly build problems?

Yes. I try to make mistakes once and only once 8^) - and fail of
course.

Stefan

RE: cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Chmod.java

Posted by Conor MacNeill <co...@m64.com>.
Stefan,

I assume you have left the deprecated form of the chmod task in the
build.xml file to avoid the nightly build problems?

Conor