bodewig     2005/03/11 00:41:41

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/taskdefs Jar.java Zip.java
               src/main/org/apache/tools/zip ExtraFieldUtils.java
  Added:       src/main/org/apache/tools/zip JarMarker.java
  Log:
  Make Solaris detect Ant jar files as jar files, PR: 32649
  
  Revision  Changes    Path
  1.771     +3 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.770
  retrieving revision 1.771
  diff -u -r1.770 -r1.771
  --- WHATSNEW  10 Mar 2005 21:16:07 -0000      1.770
  +++ WHATSNEW  11 Mar 2005 08:41:41 -0000      1.771
  @@ -253,6 +253,9 @@
   * Add else attribute to the condition task, which specifies an
     optional alternate value to set the property to if the nested
     condition evaluates to false. Bugzilla report 33074.
  +
  +* Ant generated jar files should now be detected as jar files by
  +  Solaris.  Bugzilla Report 32649.
     
   Fixed bugs:
   -----------
  
  
  
  1.89      +14 -2     ant/src/main/org/apache/tools/ant/taskdefs/Jar.java
  
  Index: Jar.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Jar.java,v
  retrieving revision 1.88
  retrieving revision 1.89
  diff -u -r1.88 -r1.89
  --- Jar.java  22 Nov 2004 09:23:27 -0000      1.88
  +++ Jar.java  11 Mar 2005 08:41:41 -0000      1.89
  @@ -1,5 +1,5 @@
   /*
  - * Copyright  2000-2004 The Apache Software Foundation
  + * Copyright  2000-2005 The Apache Software Foundation
    *
    *  Licensed under the Apache License, Version 2.0 (the "License");
    *  you may not use this file except in compliance with the License.
  @@ -47,6 +47,8 @@
   import org.apache.tools.ant.types.FileSet;
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.types.ZipFileSet;
  +import org.apache.tools.zip.JarMarker;
  +import org.apache.tools.zip.ZipExtraField;
   import org.apache.tools.zip.ZipOutputStream;
   
   /**
  @@ -130,6 +132,15 @@
        */
       private Path indexJars;
   
  +    /**
  +     * Extra fields needed to make Solaris recognize the archive as a jar 
file.
  +     *
  +     * @since Ant 1.6.3
  +     */
  +    private ZipExtraField[] JAR_MARKER = new ZipExtraField[] {
  +        JarMarker.getInstance()
  +    };
  +
       /** constructor */
       public Jar() {
           super();
  @@ -382,7 +393,8 @@
                   Project.MSG_WARN);
           }
   
  -        zipDir(null, zOut, "META-INF/", ZipFileSet.DEFAULT_DIR_MODE);
  +        zipDir(null, zOut, "META-INF/", ZipFileSet.DEFAULT_DIR_MODE,
  +               JAR_MARKER);
           // time to write the manifest
           ByteArrayOutputStream baos = new ByteArrayOutputStream();
           OutputStreamWriter osw = new OutputStreamWriter(baos, "UTF-8");
  
  
  
  1.139     +22 -1     ant/src/main/org/apache/tools/ant/taskdefs/Zip.java
  
  Index: Zip.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Zip.java,v
  retrieving revision 1.138
  retrieving revision 1.139
  diff -u -r1.138 -r1.139
  --- Zip.java  1 Mar 2005 09:48:36 -0000       1.138
  +++ Zip.java  11 Mar 2005 08:41:41 -0000      1.139
  @@ -47,6 +47,7 @@
   import org.apache.tools.ant.util.MergingMapper;
   import org.apache.tools.ant.util.ResourceUtils;
   import org.apache.tools.zip.ZipEntry;
  +import org.apache.tools.zip.ZipExtraField;
   import org.apache.tools.zip.ZipFile;
   import org.apache.tools.zip.ZipOutputStream;
   
  @@ -1030,6 +1031,22 @@
       protected void zipDir(File dir, ZipOutputStream zOut, String vPath,
                             int mode)
           throws IOException {
  +        zipDir(dir, zOut, vPath, mode, null);
  +    }
  +
  +    /**
  +     * Add a directory to the zip stream.
  +     * @param dir  the directort to add to the archive
  +     * @param zOut the stream to write to
  +     * @param vPath the name this entry shall have in the archive
  +     * @param mode the Unix permissions to set.
  +     * @param extra ZipExtraFields to add
  +     * @throws IOException on error
  +     * @since Ant 1.6.3
  +     */
  +    protected void zipDir(File dir, ZipOutputStream zOut, String vPath,
  +                          int mode, ZipExtraField[] extra)
  +        throws IOException {
           if (addedDirs.get(vPath) != null) {
               // don't add directories we've already added.
               // no warning if we try, it is harmless in and of itself
  @@ -1054,7 +1071,11 @@
               ze.setCrc (EMPTY_CRC);
               ze.setUnixMode(mode);
   
  -            zOut.putNextEntry (ze);
  +            if (extra != null) {
  +                ze.setExtraFields(extra);
  +            }
  +
  +            zOut.putNextEntry(ze);
           }
       }
   
  
  
  
  1.13      +1 -0      ant/src/main/org/apache/tools/zip/ExtraFieldUtils.java
  
  Index: ExtraFieldUtils.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/zip/ExtraFieldUtils.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ExtraFieldUtils.java      9 Mar 2005 00:20:39 -0000       1.12
  +++ ExtraFieldUtils.java      11 Mar 2005 08:41:41 -0000      1.13
  @@ -37,6 +37,7 @@
       static {
           implementations = new Hashtable();
           register(AsiExtraField.class);
  +        register(JarMarker.class);
       }
   
       /**
  
  
  
  1.1                  ant/src/main/org/apache/tools/zip/JarMarker.java
  
  Index: JarMarker.java
  ===================================================================
  /*
   * Copyright  2005 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  
  package org.apache.tools.zip;
  
  import java.util.zip.ZipException;
  
  /**
   * If this extra field is added as the very first extra field of the
   * archive, Solaris will consider it an executable jar file.
   *
   * @since Ant 1.6.3
   */
  public final class JarMarker implements ZipExtraField {
  
      private static ZipShort ID = new ZipShort(0xCAFE);
      private static ZipShort NULL = new ZipShort(0);
      private static byte[] NO_BYTES = new byte[0];
      private static JarMarker DEFAULT = new JarMarker();
  
      public JarMarker() {
          // empty
      }
  
      /**
       * Since JarMarker is stateless we can always use the same instance.
       */
      public static JarMarker getInstance() {
          return DEFAULT;
      }
  
      /**
       * The Header-ID.
       * @return the header id
       */
      public ZipShort getHeaderId() {
          return ID;
      }
  
      /**
       * Length of the extra field in the local file data - without
       * Header-ID or length specifier.
       * @return 0
       */
      public ZipShort getLocalFileDataLength() {
          return NULL;
      }
  
      /**
       * Length of the extra field in the central directory - without
       * Header-ID or length specifier.
       * @return 0
       */
      public ZipShort getCentralDirectoryLength() {
          return NULL;
      }
  
      /**
       * The actual data to put into local file data - without Header-ID
       * or length specifier.
       * @return the data
       * @since 1.1
       */
      public byte[] getLocalFileDataData() {
          return NO_BYTES;
      }
  
      /**
       * The actual data to put central directory - without Header-ID or
       * length specifier.
       * @return the data
       */
      public byte[] getCentralDirectoryData() {
          return NO_BYTES;
      }
  
      /**
       * Populate data from this array as if it was in local file data.
       * @param data an array of bytes
       * @param offset the start offset
       * @param length the number of bytes in the array from offset
       *
       * @throws ZipException on error
       */
      public void parseFromLocalFileData(byte[] data, int offset, int length)
          throws ZipException {
          if (length != 0) {
              throw new ZipException("JarMarker doesn't expect any data");
          }
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to