ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs WhenEmpty.java Ear.java Jar.java War.java Zip.java
Date Sun, 13 Jan 2002 07:34:57 GMT
donaldp     02/01/12 23:34:57

  Modified:    proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs
                        Ear.java Jar.java War.java Zip.java
  Added:       proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs
                        WhenEmpty.java
  Log:
  Started to clean zip and friends
  
  Revision  Changes    Path
  1.8       +24 -35    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Ear.java
  
  Index: Ear.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Ear.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Ear.java	23 Dec 2001 14:21:50 -0000	1.7
  +++ Ear.java	13 Jan 2002 07:34:56 -0000	1.8
  @@ -21,30 +21,27 @@
    */
   public class Ear extends Jar
   {
  -
  -    private File deploymentDescriptor;
  -    private boolean descriptorAdded;
  +    private File m_appxml;
  +    private boolean m_descriptorAdded;
   
       public Ear()
       {
  -        super();
  -        archiveType = "ear";
  -        emptyBehavior = "create";
  +        m_archiveType = "ear";
  +        m_emptyBehavior = "create";
       }
   
  -    public void setAppxml( File descr )
  +    public void setAppxml( final File appxml )
           throws TaskException
       {
  -        deploymentDescriptor = descr;
  -        if( !deploymentDescriptor.exists() )
  -            throw new TaskException( "Deployment descriptor: " + deploymentDescriptor +
" does not exist." );
  -
  -        // Create a ZipFileSet for this file, and pass it up.
  -        ZipFileSet fs = new ZipFileSet();
  -        fs.setDir( new File( deploymentDescriptor.getParent() ) );
  -        fs.setIncludes( deploymentDescriptor.getName() );
  -        fs.setFullpath( "META-INF/application.xml" );
  -        super.addFileset( fs );
  +        m_appxml = appxml;
  +        if( !m_appxml.exists() )
  +        {
  +            final String message = "Deployment descriptor: " +
  +                m_appxml + " does not exist.";
  +            throw new TaskException( message );
  +        }
  +
  +        addFileAs( m_appxml, "META-INF/application.xml" );
       }
   
       public void addArchives( ZipFileSet fs )
  @@ -56,23 +53,13 @@
           super.addFileset( fs );
       }
   
  -    /**
  -     * Make sure we don't think we already have a web.xml next time this task
  -     * gets executed.
  -     */
  -    protected void cleanUp()
  -    {
  -        descriptorAdded = false;
  -        super.cleanUp();
  -    }
  -
  -    protected void initZipOutputStream( ZipOutputStream zOut )
  +    protected void initZipOutputStream( final ZipOutputStream zOut )
           throws IOException, TaskException
       {
  -        // If no webxml file is specified, it's an error.
  -        if( deploymentDescriptor == null && !isInUpdateMode() )
  +        if( m_appxml == null && !isInUpdateMode() )
           {
  -            throw new TaskException( "appxml attribute is required" );
  +            final String message = "appxml attribute is required";
  +            throw new TaskException( message );
           }
   
           super.initZipOutputStream( zOut );
  @@ -87,17 +74,19 @@
           // a <fileset> element.
           if( vPath.equalsIgnoreCase( "META-INF/aplication.xml" ) )
           {
  -            if( deploymentDescriptor == null || !deploymentDescriptor.equals( file ) ||
descriptorAdded )
  +            if( m_appxml == null ||
  +                !m_appxml.equals( file ) ||
  +                m_descriptorAdded )
               {
  -                final String message = "Warning: selected " + archiveType +
  +                final String message = "Warning: selected " + m_archiveType +
                       " files include a META-INF/application.xml which will be ignored "
+
  -                    "(please use appxml attribute to " + archiveType + " task)";
  +                    "(please use appxml attribute to " + m_archiveType + " task)";
                   getLogger().warn( message );
               }
               else
               {
                   super.zipFile( file, zOut, vPath );
  -                descriptorAdded = true;
  +                m_descriptorAdded = true;
               }
           }
           else
  
  
  
  1.10      +42 -48    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Jar.java
  
  Index: Jar.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Jar.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Jar.java	13 Jan 2002 00:00:15 -0000	1.9
  +++ Jar.java	13 Jan 2002 07:34:56 -0000	1.10
  @@ -29,7 +29,8 @@
    *
    * @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a>
    */
  -public class Jar extends Zip
  +public class Jar
  +    extends Zip
   {
       /**
        * The index file name.
  @@ -39,16 +40,15 @@
       /**
        * true if a manifest has been specified in the task
        */
  -    private boolean buildFileManifest = false;
  +    private boolean buildFileManifest;
   
       /**
        * jar index is JDK 1.3+ only
        */
  -    private boolean index = false;
  -    private Manifest execManifest;
  -    private Manifest manifest;
  -
  -    private File manifestFile;
  +    private boolean m_index;
  +    private Manifest m_execManifest;
  +    private Manifest m_manifest;
  +    private File m_manifestFile;
   
       /**
        * constructor
  @@ -56,8 +56,8 @@
       public Jar()
       {
           super();
  -        archiveType = "jar";
  -        emptyBehavior = "create";
  +        m_archiveType = "jar";
  +        m_emptyBehavior = "create";
           setEncoding( "UTF8" );
       }
   
  @@ -69,7 +69,7 @@
        */
       public void setIndex( boolean flag )
       {
  -        index = flag;
  +        m_index = flag;
       }
   
       public void setManifest( File manifestFile )
  @@ -77,30 +77,33 @@
       {
           if( !manifestFile.exists() )
           {
  -            throw new TaskException( "Manifest file: " + manifestFile + " does not exist."
);
  +            final String message = "Manifest file: " + manifestFile + " does not exist.";
  +            throw new TaskException( message );
           }
   
  -        this.manifestFile = manifestFile;
  +        this.m_manifestFile = manifestFile;
   
           Reader r = null;
           try
           {
               r = new FileReader( manifestFile );
               Manifest newManifest = new Manifest( r );
  -            if( manifest == null )
  +            if( m_manifest == null )
               {
  -                manifest = Manifest.getDefaultManifest();
  +                m_manifest = Manifest.getDefaultManifest();
               }
  -            manifest.merge( newManifest );
  +            m_manifest.merge( newManifest );
           }
           catch( ManifestException e )
           {
  -            getLogger().error( "Manifest is invalid: " + e.getMessage() );
  -            throw new TaskException( "Invalid Manifest: " + manifestFile, e );
  +            final String message = "Manifest " + manifestFile + " is invalid: " + e.getMessage();
  +            getLogger().error( message );
  +            throw new TaskException( message, e );
           }
           catch( IOException e )
           {
  -            throw new TaskException( "Unable to read manifest file: " + manifestFile, e
);
  +            final String message = "Unable to read manifest file: " + manifestFile;
  +            throw new TaskException( message, e );
           }
           finally
           {
  @@ -127,11 +130,11 @@
       public void addConfiguredManifest( Manifest newManifest )
           throws ManifestException, TaskException
       {
  -        if( manifest == null )
  +        if( m_manifest == null )
           {
  -            manifest = Manifest.getDefaultManifest();
  +            m_manifest = Manifest.getDefaultManifest();
           }
  -        manifest.merge( newManifest );
  +        m_manifest.merge( newManifest );
           buildFileManifest = true;
       }
   
  @@ -155,7 +158,7 @@
           throws TaskException
       {
           // need to handle manifest as a special check
  -        if( buildFileManifest || manifestFile == null )
  +        if( buildFileManifest || m_manifestFile == null )
           {
               java.util.zip.ZipFile theZipFile = null;
               try
  @@ -168,11 +171,11 @@
                       return false;
                   }
                   Manifest currentManifest = new Manifest( new InputStreamReader( theZipFile.getInputStream(
entry ) ) );
  -                if( manifest == null )
  +                if( m_manifest == null )
                   {
  -                    manifest = Manifest.getDefaultManifest();
  +                    m_manifest = Manifest.getDefaultManifest();
                   }
  -                if( !currentManifest.equals( manifest ) )
  +                if( !currentManifest.equals( m_manifest ) )
                   {
                       getLogger().debug( "Updating jar since jar manifest has changed" );
                       return false;
  @@ -199,22 +202,13 @@
                   }
               }
           }
  -        else if( manifestFile.lastModified() > zipFile.lastModified() )
  +        else if( m_manifestFile.lastModified() > zipFile.lastModified() )
           {
               return false;
           }
           return super.isUpToDate( scanners, zipFile );
       }
   
  -    /**
  -     * Make sure we don't think we already have a MANIFEST next time this task
  -     * gets executed.
  -     */
  -    protected void cleanUp()
  -    {
  -        super.cleanUp();
  -    }
  -
       protected boolean createEmptyZip( File zipFile )
       {
           // Jar files always contain a manifest and can never be empty
  @@ -224,7 +218,7 @@
       protected void finalizeZipOutputStream( ZipOutputStream zOut )
           throws IOException, TaskException
       {
  -        if( index )
  +        if( m_index )
           {
               createIndexList( zOut );
           }
  @@ -235,13 +229,13 @@
       {
           try
           {
  -            execManifest = Manifest.getDefaultManifest();
  +            m_execManifest = Manifest.getDefaultManifest();
   
  -            if( manifest != null )
  +            if( m_manifest != null )
               {
  -                execManifest.merge( manifest );
  +                m_execManifest.merge( m_manifest );
               }
  -            for( Iterator e = execManifest.getWarnings(); e.hasNext(); )
  +            for( Iterator e = m_execManifest.getWarnings(); e.hasNext(); )
               {
                   getLogger().warn( "Manifest warning: " + (String)e.next() );
               }
  @@ -250,7 +244,7 @@
               // time to write the manifest
               ByteArrayOutputStream baos = new ByteArrayOutputStream();
               PrintWriter writer = new PrintWriter( baos );
  -            execManifest.write( writer );
  +            m_execManifest.write( writer );
               writer.flush();
   
               ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
  @@ -273,9 +267,9 @@
           // a <fileset> element.
           if( vPath.equalsIgnoreCase( "META-INF/MANIFEST.MF" ) )
           {
  -            final String message = "Warning: selected " + archiveType +
  +            final String message = "Warning: selected " + m_archiveType +
                   " files include a META-INF/MANIFEST.MF which will be ignored " +
  -                "(please use manifest attribute to " + archiveType + " task)";
  +                "(please use manifest attribute to " + m_archiveType + " task)";
               getLogger().warn( message );
           }
           else
  @@ -328,12 +322,12 @@
           writer.println();
   
           // header newline
  -        writer.println( zipFile.getName() );
  +        writer.println( m_file.getName() );
   
           // JarIndex is sorting the directories by ascending order.
           // it's painful to do in JDK 1.1 and it has no value but cosmetic
           // since it will be read into a hashtable by the classloader.
  -        Enumeration enum = addedDirs.keys();
  +        Enumeration enum = m_addedDirs.keys();
           while( enum.hasMoreElements() )
           {
               String dir = (String)enum.nextElement();
  @@ -377,13 +371,13 @@
       {
           try
           {
  -            if( execManifest == null )
  +            if( m_execManifest == null )
               {
  -                execManifest = new Manifest( new InputStreamReader( is ) );
  +                m_execManifest = new Manifest( new InputStreamReader( is ) );
               }
               else if( isAddingNewFiles() )
               {
  -                execManifest.merge( new Manifest( new InputStreamReader( is ) ) );
  +                m_execManifest.merge( new Manifest( new InputStreamReader( is ) ) );
               }
           }
           catch( ManifestException e )
  
  
  
  1.8       +28 -37    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/War.java
  
  Index: War.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/War.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- War.java	23 Dec 2001 14:21:50 -0000	1.7
  +++ War.java	13 Jan 2002 07:34:56 -0000	1.8
  @@ -18,70 +18,59 @@
    *
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
    */
  -public class War extends Jar
  +public class War
  +    extends Jar
   {
  -
  -    private File deploymentDescriptor;
  -    private boolean descriptorAdded;
  +    private File m_webxml;
  +    private boolean m_descriptorAdded;
   
       public War()
       {
           super();
  -        archiveType = "war";
  -        emptyBehavior = "create";
  +        m_archiveType = "war";
  +        m_emptyBehavior = "create";
       }
   
  -    public void setWebxml( File descr )
  +    public void setWebxml( final File descr )
           throws TaskException
       {
  -        deploymentDescriptor = descr;
  -        if( !deploymentDescriptor.exists() )
  -            throw new TaskException( "Deployment descriptor: " + deploymentDescriptor +
" does not exist." );
  -
  -        // Create a ZipFileSet for this file, and pass it up.
  -        ZipFileSet fs = new ZipFileSet();
  -        fs.setDir( new File( deploymentDescriptor.getParent() ) );
  -        fs.setIncludes( deploymentDescriptor.getName() );
  -        fs.setFullpath( "WEB-INF/web.xml" );
  -        super.addFileset( fs );
  +        m_webxml = descr;
  +        if( !m_webxml.exists() )
  +        {
  +            final String message = "Deployment descriptor: " +
  +                m_webxml + " does not exist.";
  +            throw new TaskException( message );
  +        }
  +
  +        addFileAs(descr, "WEB-INF/web.xml" );
       }
   
  -    public void addClasses( ZipFileSet fs )
  +    public void addClasses( final ZipFileSet fs )
       {
           // We just set the prefix for this fileset, and pass it up.
           fs.setPrefix( "WEB-INF/classes/" );
           super.addFileset( fs );
       }
   
  -    public void addLib( ZipFileSet fs )
  +    public void addLib( final ZipFileSet fs )
       {
           // We just set the prefix for this fileset, and pass it up.
           fs.setPrefix( "WEB-INF/lib/" );
           super.addFileset( fs );
       }
   
  -    public void addWebinf( ZipFileSet fs )
  +    public void addWebinf( final ZipFileSet fs )
       {
           // We just set the prefix for this fileset, and pass it up.
           fs.setPrefix( "WEB-INF/" );
           super.addFileset( fs );
       }
   
  -    /**
  -     * Make sure we don't think we already have a web.xml next time this task
  -     * gets executed.
  -     */
  -    protected void cleanUp()
  -    {
  -        descriptorAdded = false;
  -        super.cleanUp();
  -    }
  -
  -    protected void initZipOutputStream( ZipOutputStream zOut )
  +    protected void initZipOutputStream( final ZipOutputStream zOut )
           throws IOException, TaskException
       {
           // If no webxml file is specified, it's an error.
  -        if( deploymentDescriptor == null && !isInUpdateMode() )
  +        if( m_webxml == null && !isInUpdateMode() )
           {
               throw new TaskException( "webxml attribute is required" );
           }
  @@ -89,7 +78,9 @@
           super.initZipOutputStream( zOut );
       }
   
  -    protected void zipFile( File file, ZipOutputStream zOut, String vPath )
  +    protected void zipFile( final File file,
  +                            final ZipOutputStream zOut,
  +                            final String vPath )
           throws IOException, TaskException
       {
           // If the file being added is WEB-INF/web.xml, we warn if it's not the
  @@ -98,17 +89,17 @@
           // a <fileset> element.
           if( vPath.equalsIgnoreCase( "WEB-INF/web.xml" ) )
           {
  -            if( deploymentDescriptor == null || !deploymentDescriptor.equals( file ) ||
descriptorAdded )
  +            if( m_webxml == null || !m_webxml.equals( file ) || m_descriptorAdded )
               {
  -                final String message = "Warning: selected " + archiveType +
  +                final String message = "Warning: selected " + m_archiveType +
                       " files include a WEB-INF/web.xml which will be ignored " +
  -                    "(please use webxml attribute to " + archiveType + " task)";
  +                    "(please use webxml attribute to " + m_archiveType + " task)";
                   getLogger().warn( message );
               }
               else
               {
                   super.zipFile( file, zOut, vPath );
  -                descriptorAdded = true;
  +                m_descriptorAdded = true;
               }
           }
           else
  
  
  
  1.15      +106 -130  jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Zip.java
  
  Index: Zip.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Zip.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Zip.java	13 Jan 2002 04:45:00 -0000	1.14
  +++ Zip.java	13 Jan 2002 07:34:56 -0000	1.15
  @@ -23,12 +23,11 @@
   import org.apache.myrmidon.api.TaskException;
   import org.apache.tools.ant.types.DirectoryScanner;
   import org.apache.tools.ant.types.FileScanner;
  -import org.apache.tools.ant.types.EnumeratedAttribute;
   import org.apache.tools.ant.types.FileSet;
  +import org.apache.tools.ant.types.SourceFileScanner;
   import org.apache.tools.ant.types.ZipFileSet;
   import org.apache.tools.ant.types.ZipScanner;
   import org.apache.tools.ant.util.mappers.MergingMapper;
  -import org.apache.tools.ant.types.SourceFileScanner;
   import org.apache.tools.zip.ZipEntry;
   import org.apache.tools.zip.ZipOutputStream;
   
  @@ -39,36 +38,35 @@
    * @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a>
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
    */
  -public class Zip extends MatchingTask
  +public class Zip
  +    extends MatchingTask
   {
  -
       // For directories:
       private final static long EMPTY_CRC = new CRC32().getValue();
  -    private boolean doCompress = true;
  -    private boolean doUpdate = false;
  -    private boolean doFilesonly = false;
  -    protected String archiveType = "zip";
  -    protected String emptyBehavior = "skip";
  -    private ArrayList filesets = new ArrayList();
  -    protected Hashtable addedDirs = new Hashtable();
  -    private ArrayList addedFiles = new ArrayList();
  -
  -    protected File zipFile;
  +    private boolean m_compress = true;
  +    private boolean m_update;
  +    private boolean m_filesonly;
  +    protected String m_archiveType = "zip";
  +    protected String m_emptyBehavior = "skip";
  +    private ArrayList m_filesets = new ArrayList();
  +    protected Hashtable m_addedDirs = new Hashtable();
  +    private ArrayList m_addedFiles = new ArrayList();
  +    protected File m_file;
   
       /**
        * true when we are adding new files into the Zip file, as opposed to adding
        * back the unchanged files
        */
  -    private boolean addingNewFiles;
  -    private File baseDir;
  +    private boolean m_addingNewFiles;
  +    private File m_baseDir;
   
       /**
        * Encoding to use for filenames, defaults to the platform's default
        * encoding.
        */
  -    private String encoding;
  +    private String m_encoding;
   
  -    protected static String[][] grabFileNames( FileScanner[] scanners )
  +    private static String[][] grabFileNames( final FileScanner[] scanners )
           throws TaskException
       {
           String[][] result = new String[ scanners.length ][];
  @@ -83,15 +81,17 @@
           return result;
       }
   
  -    protected static File[] grabFiles( FileScanner[] scanners,
  -                                       String[][] fileNames )
  +    private static File[] grabFiles( final FileScanner[] scanners,
  +                                     final String[][] filenames )
       {
  -        ArrayList files = new ArrayList();
  -        for( int i = 0; i < fileNames.length; i++ )
  +        final ArrayList files = new ArrayList();
  +        for( int i = 0; i < filenames.length; i++ )
           {
  -            File thisBaseDir = scanners[ i ].getBasedir();
  -            for( int j = 0; j < fileNames[ i ].length; j++ )
  -                files.add( new File( thisBaseDir, fileNames[ i ][ j ] ) );
  +            final File baseDir = scanners[ i ].getBasedir();
  +            for( int j = 0; j < filenames[ i ].length; j++ )
  +            {
  +                files.add( new File( baseDir, filenames[ i ][ j ] ) );
  +            }
           }
           final File[] toret = new File[ files.size() ];
           return (File[])files.toArray( toret );
  @@ -102,9 +102,9 @@
        *
        * @param baseDir The new Basedir value
        */
  -    public void setBasedir( File baseDir )
  +    public void setBasedir( final File baseDir )
       {
  -        this.baseDir = baseDir;
  +        m_baseDir = baseDir;
       }
   
       /**
  @@ -112,9 +112,9 @@
        *
        * @param c The new Compress value
        */
  -    public void setCompress( boolean c )
  +    public void setCompress( final boolean compress )
       {
  -        doCompress = c;
  +        m_compress = compress;
       }
   
       /**
  @@ -128,9 +128,9 @@
        *
        * @param encoding The new Encoding value
        */
  -    public void setEncoding( String encoding )
  +    public void setEncoding( final String encoding )
       {
  -        this.encoding = encoding;
  +        m_encoding = encoding;
       }
   
       /**
  @@ -138,9 +138,9 @@
        *
        * @param file The new File value
        */
  -    public void setFile( File file )
  +    public void setFile( final File file )
       {
  -        this.zipFile = file;
  +        m_file = file;
       }
   
       /**
  @@ -148,9 +148,9 @@
        *
        * @param f The new Filesonly value
        */
  -    public void setFilesonly( boolean f )
  +    public void setFilesonly( final boolean filesonly )
       {
  -        doFilesonly = f;
  +        m_filesonly = filesonly;
       }
   
       /**
  @@ -159,9 +159,9 @@
        *
        * @param c The new Update value
        */
  -    public void setUpdate( boolean c )
  +    public void setUpdate( final boolean update )
       {
  -        doUpdate = c;
  +        m_update = update;
       }
   
       /**
  @@ -173,9 +173,9 @@
        *
        * @param we The new Whenempty value
        */
  -    public void setWhenempty( WhenEmpty we )
  +    public void setWhenempty( final WhenEmpty we )
       {
  -        emptyBehavior = we.getValue();
  +        m_emptyBehavior = we.getValue();
       }
   
       /**
  @@ -183,19 +183,17 @@
        *
        * @return The InUpdateMode value
        */
  -    public boolean isInUpdateMode()
  +    protected final boolean isInUpdateMode()
       {
  -        return doUpdate;
  +        return m_update;
       }
   
       /**
        * Adds a set of files (nested fileset attribute).
  -     *
  -     * @param set The feature to be added to the Fileset attribute
        */
  -    public void addFileset( FileSet set )
  +    public void addFileset( final FileSet set )
       {
  -        filesets.add( set );
  +        m_filesets.add( set );
       }
   
       /**
  @@ -204,23 +202,27 @@
        *
        * @param set The feature to be added to the Zipfileset attribute
        */
  -    public void addZipfileset( ZipFileSet set )
  +    public void addZipfileset( final ZipFileSet set )
       {
  -        filesets.add( set );
  +        m_filesets.add( set );
       }
   
       public void execute()
           throws TaskException
       {
  -        if( baseDir == null && filesets.size() == 0 && "zip".equals( archiveType
) )
  +        if( m_baseDir == null && m_filesets.size() == 0 &&
  +            "zip".equals( m_archiveType ) )
           {
  -            throw new TaskException( "basedir attribute must be set, or at least " +
  -                                     "one fileset must be given!" );
  +            final String message = "basedir attribute must be set, or at least " +
  +                "one fileset must be given!";
  +            throw new TaskException( message );
           }
   
  -        if( zipFile == null )
  +        if( m_file == null )
           {
  -            throw new TaskException( "You must specify the " + archiveType + " file to
create!" );
  +            final String message = "You must specify the " +
  +                m_archiveType + " file to create!";
  +            throw new TaskException( message );
           }
   
           // Renamed version of original file, if it exists
  @@ -228,14 +230,14 @@
           // Whether or not an actual update is required -
           // we don't need to update if the original file doesn't exist
   
  -        addingNewFiles = true;
  -        doUpdate = doUpdate && zipFile.exists();
  -        if( doUpdate )
  +        m_addingNewFiles = true;
  +        m_update = m_update && m_file.exists();
  +        if( m_update )
           {
               try
               {
                   renamedFile = File.createTempFile( "zip", ".tmp",
  -                                                   zipFile.getParentFile() );
  +                                                   m_file.getParentFile() );
               }
               catch( final IOException ioe )
               {
  @@ -244,7 +246,7 @@
   
               try
               {
  -                if( !zipFile.renameTo( renamedFile ) )
  +                if( !m_file.renameTo( renamedFile ) )
                   {
                       throw new TaskException( "Unable to rename old file to temporary file"
);
                   }
  @@ -257,13 +259,13 @@
   
           // Create the scanners to pass to isUpToDate().
           ArrayList dss = new ArrayList();
  -        if( baseDir != null )
  +        if( m_baseDir != null )
           {
  -            dss.add( getDirectoryScanner( baseDir ) );
  +            dss.add( getDirectoryScanner( m_baseDir ) );
           }
  -        for( int i = 0; i < filesets.size(); i++ )
  +        for( int i = 0; i < m_filesets.size(); i++ )
           {
  -            FileSet fs = (FileSet)filesets.get( i );
  +            FileSet fs = (FileSet)m_filesets.get( i );
               dss.add( fs.getDirectoryScanner() );
           }
           int dssSize = dss.size();
  @@ -272,24 +274,24 @@
   
           // quick exit if the target is up to date
           // can also handle empty archives
  -        if( isUpToDate( scanners, zipFile ) )
  +        if( isUpToDate( scanners, m_file ) )
           {
               return;
           }
   
  -        String action = doUpdate ? "Updating " : "Building ";
  +        String action = m_update ? "Updating " : "Building ";
   
  -        getLogger().info( action + archiveType + ": " + zipFile.getAbsolutePath() );
  +        getLogger().info( action + m_archiveType + ": " + m_file.getAbsolutePath() );
   
           boolean success = false;
           try
           {
               ZipOutputStream zOut =
  -                new ZipOutputStream( new FileOutputStream( zipFile ) );
  -            zOut.setEncoding( encoding );
  +                new ZipOutputStream( new FileOutputStream( m_file ) );
  +            zOut.setEncoding( m_encoding );
               try
               {
  -                if( doCompress )
  +                if( m_compress )
                   {
                       zOut.setMethod( ZipOutputStream.DEFLATED );
                   }
  @@ -300,26 +302,26 @@
                   initZipOutputStream( zOut );
   
                   // Add the implicit fileset to the archive.
  -                if( baseDir != null )
  +                if( m_baseDir != null )
                   {
  -                    addFiles( getDirectoryScanner( baseDir ), zOut, "", "" );
  +                    addFiles( getDirectoryScanner( m_baseDir ), zOut, "", "" );
                   }
                   // Add the explicit filesets to the archive.
  -                addFiles( filesets, zOut );
  -                if( doUpdate )
  +                addFiles( m_filesets, zOut );
  +                if( m_update )
                   {
  -                    addingNewFiles = false;
  +                    m_addingNewFiles = false;
                       ZipFileSet oldFiles = new ZipFileSet();
                       oldFiles.setSrc( renamedFile );
   
                       StringBuffer exclusionPattern = new StringBuffer();
  -                    for( int i = 0; i < addedFiles.size(); i++ )
  +                    for( int i = 0; i < m_addedFiles.size(); i++ )
                       {
                           if( i != 0 )
                           {
                               exclusionPattern.append( "," );
                           }
  -                        exclusionPattern.append( (String)addedFiles.get( i ) );
  +                        exclusionPattern.append( (String)m_addedFiles.get( i ) );
                       }
                       oldFiles.setExcludes( exclusionPattern.toString() );
                       ArrayList tmp = new ArrayList();
  @@ -354,17 +356,17 @@
           }
           catch( IOException ioe )
           {
  -            String msg = "Problem creating " + archiveType + ": " + ioe.getMessage();
  +            String msg = "Problem creating " + m_archiveType + ": " + ioe.getMessage();
   
               // delete a bogus ZIP file
  -            if( !zipFile.delete() )
  +            if( !m_file.delete() )
               {
                   msg += " (and the archive is probably corrupt but I could not delete it)";
               }
   
  -            if( doUpdate )
  +            if( m_update )
               {
  -                if( !renamedFile.renameTo( zipFile ) )
  +                if( !renamedFile.renameTo( m_file ) )
                   {
                       msg += " (and I couldn't rename the temporary file " +
                           renamedFile.getName() + " back)";
  @@ -373,13 +375,9 @@
   
               throw new TaskException( msg, ioe );
           }
  -        finally
  -        {
  -            cleanUp();
  -        }
   
           // If we've been successful on an update, delete the temporary file
  -        if( success && doUpdate )
  +        if( success && m_update )
           {
               if( !renamedFile.delete() )
               {
  @@ -390,15 +388,26 @@
           }
       }
   
  +    protected void addFileAs( final File file, final String name )
  +        throws TaskException
  +    {
  +        // Create a ZipFileSet for this file, and pass it up.
  +        final ZipFileSet fs = new ZipFileSet();
  +        fs.setDir( file.getParentFile() );
  +        fs.setIncludes( file.getName() );
  +        fs.setFullpath( name );
  +        addFileset( fs );
  +    }
  +
       /**
        * Indicates if the task is adding new files into the archive as opposed to
        * copying back unchanged files from the backup copy
        *
        * @return The AddingNewFiles value
        */
  -    protected boolean isAddingNewFiles()
  +    protected final boolean isAddingNewFiles()
       {
  -        return addingNewFiles;
  +        return m_addingNewFiles;
       }
   
       /**
  @@ -418,16 +427,16 @@
           File[] files = grabFiles( scanners, fileNames );
           if( files.length == 0 )
           {
  -            if( emptyBehavior.equals( "skip" ) )
  +            if( m_emptyBehavior.equals( "skip" ) )
               {
  -                final String message = "Warning: skipping " + archiveType + " archive "
+ zipFile +
  +                final String message = "Warning: skipping " + m_archiveType + " archive
" + zipFile +
                       " because no files were included.";
                   getLogger().warn( message );
                   return true;
               }
  -            else if( emptyBehavior.equals( "fail" ) )
  +            else if( m_emptyBehavior.equals( "fail" ) )
               {
  -                throw new TaskException( "Cannot create " + archiveType + " archive " +
zipFile +
  +                throw new TaskException( "Cannot create " + m_archiveType + " archive "
+ zipFile +
                                            ": no files were included." );
               }
               else
  @@ -597,7 +606,7 @@
                                     ZipOutputStream zOut, String prefix )
           throws IOException
       {
  -        if( !doFilesonly )
  +        if( !m_filesonly )
           {
               Stack directories = new Stack();
               int slashPos = entry.length();
  @@ -605,7 +614,7 @@
               while( ( slashPos = entry.lastIndexOf( (int)'/', slashPos - 1 ) ) != -1 )
               {
                   String dir = entry.substring( 0, slashPos + 1 );
  -                if( addedDirs.get( prefix + dir ) != null )
  +                if( m_addedDirs.get( prefix + dir ) != null )
                   {
                       break;
                   }
  @@ -678,26 +687,6 @@
       }
   
       /**
  -     * Do any clean up necessary to allow this instance to be used again. <p>
  -     *
  -     * When we get here, the Zip file has been closed and all we need to do is
  -     * to reset some globals.</p>
  -     */
  -    protected void cleanUp()
  -    {
  -        addedDirs = new Hashtable();
  -        addedFiles = new ArrayList();
  -        filesets = new ArrayList();
  -        zipFile = null;
  -        baseDir = null;
  -        doCompress = true;
  -        doUpdate = false;
  -        doFilesonly = false;
  -        addingNewFiles = false;
  -        encoding = null;
  -    }
  -
  -    /**
        * Create an empty zip file
        *
        * @param zipFile Description of Parameter
  @@ -709,7 +698,7 @@
           // In this case using java.util.zip will not work
           // because it does not permit a zero-entry archive.
           // Must create it manually.
  -        getLogger().info( "Note: creating empty " + archiveType + " archive " + zipFile
);
  +        getLogger().info( "Note: creating empty " + m_archiveType + " archive " + zipFile
);
           try
           {
               OutputStream os = new FileOutputStream( zipFile );
  @@ -749,13 +738,13 @@
       protected void zipDir( File dir, ZipOutputStream zOut, String vPath )
           throws IOException
       {
  -        if( addedDirs.get( vPath ) != null )
  +        if( m_addedDirs.get( vPath ) != null )
           {
               // don't add directories we've already added.
               // no warning if we try, it is harmless in and of itself
               return;
           }
  -        addedDirs.put( vPath, vPath );
  +        m_addedDirs.put( vPath, vPath );
   
           ZipEntry ze = new ZipEntry( vPath );
           if( dir != null && dir.exists() )
  @@ -794,7 +783,7 @@
            * I couldn't find any documentation on this, just found out by try
            * and error.
            */
  -        if( !doCompress )
  +        if( !m_compress )
           {
               long size = 0;
               CRC32 cal = new CRC32();
  @@ -844,13 +833,13 @@
               }
               count = in.read( buffer, 0, buffer.length );
           } while( count != -1 );
  -        addedFiles.add( vPath );
  +        m_addedFiles.add( vPath );
       }
   
       protected void zipFile( File file, ZipOutputStream zOut, String vPath )
           throws IOException, TaskException
       {
  -        if( file.equals( zipFile ) )
  +        if( file.equals( m_file ) )
           {
               throw new TaskException( "A zip file cannot include itself" );
           }
  @@ -863,19 +852,6 @@
           finally
           {
               fIn.close();
  -        }
  -    }
  -
  -    /**
  -     * Possible behaviors when there are no matching files for the task.
  -     *
  -     * @author RT
  -     */
  -    public static class WhenEmpty extends EnumeratedAttribute
  -    {
  -        public String[] getValues()
  -        {
  -            return new String[]{"fail", "skip", "create"};
           }
       }
   }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/WhenEmpty.java
  
  Index: WhenEmpty.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.tools.ant.taskdefs;
  
  import org.apache.tools.ant.types.EnumeratedAttribute;
  
  /**
   * Possible behaviors when there are no matching files for the task.
   */
  public class WhenEmpty
      extends EnumeratedAttribute
  {
      public String[] getValues()
      {
          return new String[]{"fail", "skip", "create"};
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message