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...@apache.org on 2002/07/04 13:24:10 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs ManifestTask.java Manifest.java defaults.properties

bodewig     2002/07/04 04:24:10

  Modified:    .        Tag: ANT_15_BRANCH WHATSNEW
               src/main/org/apache/tools/ant/taskdefs Tag: ANT_15_BRANCH
                        Manifest.java defaults.properties
  Added:       src/main/org/apache/tools/ant/taskdefs Tag: ANT_15_BRANCH
                        ManifestTask.java
  Log:
  Make the manifest task a class of its own to decouple it from the
  manifest data storage and validation.
  
  The current situation would cause Manifest#hashCode to return
  different values before and after the task was executed (it now still
  does, but nobody wants to know ;-).  This made XmlLogger crash.
  
  PR: 10445
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.263.2.55 +2 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.263.2.54
  retrieving revision 1.263.2.55
  diff -u -r1.263.2.54 -r1.263.2.55
  --- WHATSNEW	4 Jul 2002 06:41:48 -0000	1.263.2.54
  +++ WHATSNEW	4 Jul 2002 11:24:10 -0000	1.263.2.55
  @@ -12,6 +12,8 @@
     string, unless the new 'setonempty' attribute is set to false|no|off
     (default is "true").
   
  +* The manifest task would crash XmlLogger
  +
   Other changes:
   --------------
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.33.2.4  +2 -123    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Manifest.java
  
  Index: Manifest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Manifest.java,v
  retrieving revision 1.33.2.3
  retrieving revision 1.33.2.4
  diff -u -r1.33.2.3 -r1.33.2.4
  --- Manifest.java	27 Jun 2002 06:46:44 -0000	1.33.2.3
  +++ Manifest.java	4 Jul 2002 11:24:10 -0000	1.33.2.4
  @@ -58,9 +58,6 @@
   import java.util.Hashtable;
   import java.util.Enumeration;
   import java.io.BufferedReader;
  -import java.io.File;
  -import java.io.FileReader;
  -import java.io.FileWriter;
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.InputStreamReader;
  @@ -70,16 +67,11 @@
   import java.io.UnsupportedEncodingException;
   
   import org.apache.tools.ant.BuildException;
  -import org.apache.tools.ant.Project;
  -import org.apache.tools.ant.Task;
  -import org.apache.tools.ant.types.EnumeratedAttribute;
   import org.apache.tools.ant.util.CollectionUtils;
   
   /**
  + * Holds the data of a jar manifest.
    *
  - * Creates a manifest file for inclusion in a JAR.
  - * This task can be used to write a Manifest file, optionally
  - *  replacing or updating an existing file.
    * Manifests are processed according to the
    * {@link <a href="http://java.sun.com/j2se/1.4/docs/guide/jar/jar.html">Jar
    * file specification.</a>}.
  @@ -95,10 +87,8 @@
    * @author <a href="mailto:j_a_fernandez@yahoo.com">Jose Alberto Fernandez</a>
    *
    * @since Ant 1.4
  - *
  - * @ant.task category="java"
    */
  -public class Manifest extends Task {
  +public class Manifest {
       /** The standard manifest version header */
       public static final String ATTRIBUTE_MANIFEST_VERSION
           = "Manifest-Version";
  @@ -132,20 +122,6 @@
       public static final String EOL = "\r\n";
   
       /**
  -     * Helper class for Manifest's mode attribute.
  -     */
  -    public static class Mode extends EnumeratedAttribute {
  -        /**
  -         * Get Allowed values for the mode attribute.
  -         *
  -         * @return a String array of the allowed values.
  -         */
  -        public String[] getValues() {
  -            return new String[] {"update", "replace"};
  -        }
  -    }
  -
  -    /**
        * An attribute for the manifest.
        * Those attributes that are not nested into a section will be added to the "Main" section.
        */
  @@ -722,16 +698,6 @@
       private Vector sectionIndex = new Vector();
   
       /**
  -     * The file to which the manifest should be written when used as a task
  -     */
  -    private File manifestFile;
  -
  -    /**
  -     * The mode with which the manifest file is written
  -     */
  -    private Mode mode;
  -
  -    /**
        * Construct a manifest from Ant's default manifest file.
        *
        * @return the default manifest.
  @@ -760,8 +726,6 @@
   
       /** Construct an empty manifest */
       public Manifest() {
  -        mode = new Mode();
  -        mode.setValue("replace");
           manifestVersion = null;
       }
   
  @@ -1028,23 +992,6 @@
       }
   
       /**
  -     * The name of the manifest file to create/update.
  -     * Required if used as a task.
  -     * @param f the Manifest file to be written
  -     */
  -    public void setFile(File f) {
  -        manifestFile = f;
  -    }
  -
  -    /**
  -     * Update policy: either "update" or "replace"; default is "replace".
  -     * @param m the mode value - update or replace.
  -     */
  -    public void setMode(Mode m) {
  -        mode = m;
  -    }
  -
  -    /**
        * Get the version of the manifest
        *
        * @return the manifest's version string
  @@ -1080,74 +1027,6 @@
        */
       public Enumeration getSectionNames() {
           return sectionIndex.elements();
  -    }
  -
  -    /**
  -     * Create or update the Manifest when used as a task.
  -     *
  -     * @throws BuildException if the manifest cannot be written.
  -     */
  -    public void execute() throws BuildException {
  -        if (manifestFile == null) {
  -            throw new BuildException("the file attribute is required");
  -        }
  -
  -        Manifest toWrite = getDefaultManifest();
  -        Manifest current = null;
  -        BuildException error = null;
  -
  -        if (manifestFile.exists()) {
  -            FileReader f = null;
  -            try {
  -                f = new FileReader(manifestFile);
  -                current = new Manifest(f);
  -            } catch (ManifestException m) {
  -                error = new BuildException("Existing manifest " + manifestFile
  -                                           + " is invalid", m, location);
  -            } catch (IOException e) {
  -                error = new BuildException("Failed to read " + manifestFile,
  -                                           e, location);
  -            } finally {
  -                if (f != null) {
  -                    try {
  -                        f.close();
  -                    } catch (IOException e) {}
  -                }
  -            }
  -        }
  -
  -        try {
  -            if (mode.getValue().equals("update") && manifestFile.exists()) {
  -                if (current != null) {
  -                    toWrite.merge(current);
  -                } else if (error != null) {
  -                    throw error;
  -                }
  -            }
  -
  -            toWrite.merge(this);
  -        } catch (ManifestException m) {
  -            throw new BuildException("Manifest is invalid", m, location);
  -        }
  -
  -        if (toWrite.equals(current)) {
  -            log("Manifest has not changed, do not recreate",
  -                Project.MSG_VERBOSE);
  -            return;
  -        }
  -
  -        PrintWriter w = null;
  -        try {
  -            w = new PrintWriter(new FileWriter(manifestFile));
  -            toWrite.write(w);
  -        } catch (IOException e) {
  -            throw new BuildException("Failed to write " + manifestFile,
  -                                     e, location);
  -        } finally {
  -            if (w != null) {
  -                w.close();
  -            }
  -        }
       }
   
   }
  
  
  
  1.128.2.5 +1 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
  retrieving revision 1.128.2.4
  retrieving revision 1.128.2.5
  diff -u -r1.128.2.4 -r1.128.2.5
  --- defaults.properties	25 Jun 2002 16:21:56 -0000	1.128.2.4
  +++ defaults.properties	4 Jul 2002 11:24:10 -0000	1.128.2.5
  @@ -61,7 +61,7 @@
   waitfor=org.apache.tools.ant.taskdefs.WaitFor
   input=org.apache.tools.ant.taskdefs.Input
   loadfile=org.apache.tools.ant.taskdefs.LoadFile
  -manifest=org.apache.tools.ant.taskdefs.Manifest
  +manifest=org.apache.tools.ant.taskdefs.ManifestTask
   loadproperties=org.apache.tools.ant.taskdefs.LoadProperties
   basename=org.apache.tools.ant.taskdefs.Basename
   dirname=org.apache.tools.ant.taskdefs.Dirname
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +226 -0    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Attic/ManifestTask.java
  
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>