ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/tar TarEntry.java
Date Sun, 04 Feb 2001 13:58:17 GMT
conor       01/02/04 05:58:17

  Modified:    .        build.xml
               src/main/org/apache/tools/ant/taskdefs Tar.java
               src/main/org/apache/tools/ant/types FileSet.java
               src/main/org/apache/tools/tar TarEntry.java
  Log:
  Add nested filesets to tar through which file permissions can be set.
  This is done through an octal mode attribute. The groupname and username
  may also be set. See build.xml for an example usage.
  
  Revision  Changes    Path
  1.129     +26 -8     jakarta-ant/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/build.xml,v
  retrieving revision 1.128
  retrieving revision 1.129
  diff -u -r1.128 -r1.129
  --- build.xml	2001/02/03 14:23:47	1.128
  +++ build.xml	2001/02/04 13:58:16	1.129
  @@ -68,10 +68,11 @@
     -->
     <property name="dist.name" value="jakarta-${name}-${version}"/>
     <property name="dist.base" value="distribution"/>
  +  <property name="defaultdist.dir" value="dist"/>
   
     <target name="setup-distproperties">
   
  -    <property name="dist.dir" value="dist"/>
  +    <property name="dist.dir" value="${defaultdist.dir}"/>
       <property name="dist.bin" value="${dist.dir}/bin"/>
       <property name="dist.lib" value="${dist.dir}/lib"/>
       <property name="dist.docs" value="${dist.dir}/docs"/>
  @@ -397,10 +398,18 @@
            includes="${dist.name}/**"
            excludes="${dist.name}/lib/optional.jar"/>
       <tar longfile="gnu"
  -         tarfile="${dist.base}/${dist.name}-bin.tar" 
  -         basedir="${dist.name}/.." 
  -         includes="${dist.name}/**"
  -         excludes="${dist.name}/lib/optional.jar"/>
  +         tarfile="${dist.base}/${dist.name}-bin.tar">
  +      <fileset dir="${dist.name}/.." mode="755" username="ant" group="ant">
  +        <include name="${dist.name}/bin/ant"/>
  +        <include name="${dist.name}/bin/antRun"/>
  +      </fileset> 
  +      <fileset dir="${dist.name}/.." username="ant" group="ant"> 
  +        <include name="${dist.name}/**"/>
  +        <exclude name="${dist.name}/bin/ant"/>
  +        <exclude name="${dist.name}/bin/antRun"/>
  +        <exclude name="${dist.name}/lib/optional.jar"/>
  +      </fileset> 
  +    </tar>
       <gzip zipfile="${dist.base}/${dist.name}-bin.tar.gz" 
             src="${dist.base}/${dist.name}-bin.tar"/>
       <delete file="${dist.base}/${dist.name}-bin.tar"/>
  @@ -415,9 +424,17 @@
            basedir="${dist.name}/.." 
            includes="${dist.name}/**"/>
       <tar longfile="gnu"
  -         tarfile="${dist.base}/${dist.name}-src.tar" 
  -         basedir="${dist.name}/.." 
  -         includes="${dist.name}/**"/>
  +         tarfile="${dist.base}/${dist.name}-src.tar" >
  +      <fileset dir="${dist.name}/.." mode="755" username="ant" group="ant">
  +        <include name="${dist.name}/bootstrap.sh"/>
  +        <include name="${dist.name}/build.sh"/>
  +      </fileset> 
  +      <fileset dir="${dist.name}/.." username="ant" group="ant"> 
  +        <include name="${dist.name}/**"/>
  +        <exclude name="${dist.name}/bootstrap.sh"/>
  +        <exclude name="${dist.name}/build.sh"/>
  +      </fileset>
  +    </tar> 
       <gzip zipfile="${dist.base}/${dist.name}-src.tar.gz" 
             src="${dist.base}/${dist.name}-src.tar"/>
       <delete file="${dist.base}/${dist.name}-src.tar"/>
  @@ -432,6 +449,7 @@
     <target name="clean">
       <delete dir="${build.dir}" />
       <delete dir="${dist.base}" />
  +    <delete dir="${defaultdist.dir}" />
       <delete> 
         <fileset dir="." includes="**/*~" defaultexcludes="no"/>
       </delete>
  
  
  
  1.10      +104 -16   jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java
  
  Index: Tar.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Tar.java	2001/02/01 15:46:28	1.9
  +++ Tar.java	2001/02/04 13:58:16	1.10
  @@ -55,9 +55,11 @@
   package org.apache.tools.ant.taskdefs;
   
   import java.io.*;
  +import java.util.*;
   import org.apache.tools.ant.*;
   import org.apache.tools.ant.util.*;
   import org.apache.tools.tar.*;
  +import org.apache.tools.ant.types.*;
   
   /**
    * Creates a TAR archive.
  @@ -76,6 +78,16 @@
       
       String longFileMode = null;
       
  +    Vector filesets = new Vector();
  +    Vector fileSetFiles = new Vector();
  +
  +    public TarFileSet createFileSet() {
  +        TarFileSet fileset = new TarFileSet();
  +        filesets.addElement(fileset);
  +        return fileset;
  +    }
  +    
  +    
       /**
        * This is the name/location of where to create the tar file.
        */
  @@ -107,19 +119,32 @@
                                        location);
           }
   
  -        if (baseDir == null) {
  -            throw new BuildException("basedir attribute must be set!", 
  -                                     location);
  -        }
  -        if (!baseDir.exists()) {
  -            throw new BuildException("basedir does not exist!", location);
  +        if (baseDir != null) {
  +            if (!baseDir.exists()) {
  +                throw new BuildException("basedir does not exist!", location);
  +            }
  +            
  +            // add the main fileset to the list of filesets to process.
  +            TarFileSet mainFileSet = new TarFileSet(fileset);
  +            mainFileSet.setDir(baseDir);
  +            mainFileSet.setDefaultexcludes(useDefaultExcludes);
  +            filesets.addElement(mainFileSet);
           }
  -
  -        DirectoryScanner ds = super.getDirectoryScanner(baseDir);
   
  -        String[] files = ds.getIncludedFiles();
  +        // check if tr is out of date with respect to each
  +        // fileset
  +        boolean upToDate = true;
  +        for (Enumeration e = filesets.elements(); e.hasMoreElements();) {
  +            TarFileSet fs = (TarFileSet)e.nextElement();
  +            String[] files = fs.getFiles(project);
  +            
  +            if (!archiveIsUpToDate(files)) {
  +                upToDate = false;
  +                break;
  +            }
  +        }
   
  -        if (archiveIsUpToDate(files)) {
  +        if (upToDate) {
               log("Nothing to do: "+tarFile.getAbsolutePath()+" is up to date.",
                   Project.MSG_INFO);
               return;
  @@ -140,11 +165,15 @@
               else if (longFileMode.equalsIgnoreCase(GNU)) {
                   tOut.setLongFileMode(TarOutputStream.LONGFILE_GNU);
               }
  -
  -            for (int i = 0; i < files.length; i++) {
  -                File f = new File(baseDir,files[i]);
  -                String name = files[i].replace(File.separatorChar,'/');
  -                tarFile(f, tOut, name);
  +        
  +            for (Enumeration e = filesets.elements(); e.hasMoreElements();) {
  +                TarFileSet fs = (TarFileSet)e.nextElement();
  +                String[] files = fs.getFiles(project);
  +                for (int i = 0; i < files.length; i++) {
  +                    File f = new File(baseDir,files[i]);
  +                    String name = files[i].replace(File.separatorChar,'/');
  +                    tarFile(f, tOut, name, fs);
  +                }
               }
           } catch (IOException ioe) {
               String msg = "Problem creating TAR: " + ioe.getMessage();
  @@ -160,7 +189,8 @@
           }
       }
   
  -    protected void tarFile(File file, TarOutputStream tOut, String vPath)
  +    protected void tarFile(File file, TarOutputStream tOut, String vPath,
  +                           TarFileSet tarFileSet)
           throws IOException
       {
           FileInputStream fIn = new FileInputStream(file);
  @@ -169,6 +199,12 @@
               TarEntry te = new TarEntry(vPath);
               te.setSize(file.length());
               te.setModTime(file.lastModified());
  +            if (!file.isDirectory()) {
  +                te.setMode(tarFileSet.getMode());
  +            }
  +            te.setUserName(tarFileSet.getUserName());
  +            te.setGroupName(tarFileSet.getGroup());
  +            
               tOut.putNextEntry(te);
               
               byte[] buffer = new byte[8 * 1024];
  @@ -189,5 +225,57 @@
           MergingMapper mm = new MergingMapper();
           mm.setTo(tarFile.getAbsolutePath());
           return sfs.restrict(files, baseDir, null, mm).length == 0;
  +    }
  +
  +    static public class TarFileSet extends FileSet {
  +        private String[] files = null;
  +        
  +        private int mode = 0100644;
  +        
  +        private String userName = "";
  +        private String groupName = "";
  +        
  +           
  +        public TarFileSet(FileSet fileset) {
  +            super(fileset);
  +        }
  +        
  +        public TarFileSet() {
  +            super();
  +        }
  +        
  +        public String[] getFiles(Project p) {
  +            if (files == null) {
  +                DirectoryScanner ds = getDirectoryScanner(p);
  +                files = ds.getIncludedFiles();
  +            }
  +            
  +            return files;
  +        }
  +        
  +        public void setMode(String octalString) {
  +            this.mode = 0100000 | Integer.parseInt(octalString, 8);
  +        }
  +            
  +        public int getMode() {
  +            return mode;
  +        }
  +        
  +        public void setUserName(String userName) {
  +            this.userName = userName;
  +        }
  +        
  +        public String getUserName() {
  +            return userName;
  +        }
  +        
  +        public void setGroup(String groupName) {
  +            this.groupName = groupName;
  +        }
  +        
  +        public String getGroup() {
  +            return groupName;
  +        }
  +        
       }
   }
  
  
  
  1.14      +9 -0      jakarta-ant/src/main/org/apache/tools/ant/types/FileSet.java
  
  Index: FileSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/FileSet.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- FileSet.java	2001/02/01 17:14:05	1.13
  +++ FileSet.java	2001/02/04 13:58:17	1.14
  @@ -85,6 +85,15 @@
           super();
       }
   
  +    protected FileSet(FileSet fileset) {
  +        this.dir = fileset.dir;
  +        this.defaultPatterns = fileset.defaultPatterns;
  +        this.additionalPatterns = fileset.additionalPatterns;
  +        this.useDefaultExcludes = fileset.useDefaultExcludes;
  +    }
  +    
  +    
  +
       /**
        * Makes this instance in effect a reference to another PatternSet
        * instance.
  
  
  
  1.6       +9 -1      jakarta-ant/src/main/org/apache/tools/tar/TarEntry.java
  
  Index: TarEntry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/tar/TarEntry.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TarEntry.java	2001/02/03 14:24:43	1.5
  +++ TarEntry.java	2001/02/04 13:58:17	1.6
  @@ -305,6 +305,14 @@
       public void setName(String name) {
           this.name = new StringBuffer(name);
       }   
  +
  +    /**
  +     * Set the mode for this entry
  +     */
  +    public void setMode(int mode) {
  +        this.mode = mode;
  +    }
  +    
           
       /** 
        * Get this entry's user id.
  @@ -580,5 +588,5 @@
           this.devMajor = (int) TarUtils.parseOctal(header, offset, DEVLEN);
           offset += DEVLEN;
           this.devMinor = (int) TarUtils.parseOctal(header, offset, DEVLEN);
  -    }        
  +    }
   }       
  
  
  

Mime
View raw message