harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhouke...@apache.org
Subject svn commit: r792021 - in /harmony/enhanced: classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ jdktools/trunk/modules/jretools/src/main/java/org/apache/har...
Date Wed, 08 Jul 2009 03:06:18 GMT
Author: zhoukevin
Date: Wed Jul  8 03:06:17 2009
New Revision: 792021

URL: http://svn.apache.org/viewvc?rev=792021&view=rev
Log:
Implemented -O cmd line option for pack200

Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingUtils.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Archive.java
    harmony/enhanced/jdktools/trunk/modules/jretools/src/main/java/org/apache/harmony/jretools/pack200/Main.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java?rev=792021&r1=792020&r2=792021&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
Wed Jul  8 03:06:17 2009
@@ -16,21 +16,15 @@
  */
 package org.apache.harmony.pack200;
 
-import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
-import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.List;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.JarInputStream;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
 import java.util.zip.GZIPOutputStream;
 
 /**
@@ -41,7 +35,7 @@
  */
 public class Archive {
 
-    private final JarInputStream inputStream;
+    private final JarInputStream jarInputStream;
     private final OutputStream outputStream;
     private JarFile jarFile;
     private long currentSegmentSize;
@@ -57,8 +51,9 @@
      */
     public Archive(JarInputStream inputStream, OutputStream outputStream,
             PackingOptions options) throws IOException {
-        this.inputStream = inputStream;
-        if(options == null) { // use all defaults
+        jarInputStream = inputStream;
+        if(options == null) {
+            // use all defaults
             options = new PackingOptions();
         }
         this.options = options;
@@ -88,7 +83,7 @@
         }
         this.outputStream = new BufferedOutputStream(outputStream);
         this.jarFile = jarFile;
-        inputStream = null;
+        jarInputStream = null;
         PackingUtils.config(options);
     }
 
@@ -98,194 +93,126 @@
      * @throws IOException
      */
     public void pack() throws Pack200Exception, IOException {
-        int effort = options.getEffort();
-        if(effort == 0) {
+        if (0 == options.getEffort()) {
             doZeroEffortPack();
         } else {
-            List classes = new ArrayList();
-            List files = new ArrayList();
-            long segmentLimit = options.getSegmentLimit();
-            List segmentUnitList = new ArrayList();
-            if (inputStream != null) {
-                Manifest manifest = jarFile != null ? jarFile.getManifest()
-                        : inputStream.getManifest();
-                if (manifest != null) {
-                    PackingUtils.log("Pack META-INF/MANIFEST.MF");
-                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                    manifest.write(baos);
-                    files.add(new PackingFile("META-INF/MANIFEST.MF", baos.toByteArray(),
0));
-                }
-                JarEntry jarEntry = inputStream.getNextJarEntry();
-                while (jarEntry != null) {
-                    if(jarEntry.getName().startsWith("META-INF")) {
-                        PackingUtils.log("Pack " + jarEntry.getName());
-                    }
-                    boolean added = addJarEntry(jarEntry,
-                            new BufferedInputStream(inputStream), classes,
-                            files);
-                    if (!added) { // not added because segment has reached
-                        // maximum size
-                        if(classes.size() > 0 || files.size() > 0) {
-                            segmentUnitList.add(new SegmentUnit(classes, files));
-                            classes = new ArrayList();
-                            files = new ArrayList();
-                            currentSegmentSize = 0;
-                            addJarEntry(jarEntry, new BufferedInputStream(inputStream), classes,
files);
-                            currentSegmentSize = 0; // ignore the size of the first entry
for compatibility with the RI
-                        }
-                    } else if (segmentLimit == 0 && estimateSize(jarEntry) > 0)
{
-                        // create a new segment for each class unless size = 0
-                        segmentUnitList.add(new SegmentUnit(classes, files));
-                        classes = new ArrayList();
-                        files = new ArrayList();
-                    }
-                    jarEntry = inputStream.getNextJarEntry();
-                }
-            } else {
-                Enumeration jarEntries = jarFile.entries();
-                while (jarEntries.hasMoreElements()) {
-                    JarEntry jarEntry = (JarEntry) jarEntries.nextElement();
-                    boolean added = addJarEntry(jarEntry, new BufferedInputStream(
-                            jarFile.getInputStream(jarEntry)), classes, files);
-                    if (!added) { // not added because segment has reached maximum
-                        // size
-                        segmentUnitList.add(new SegmentUnit(classes, files));
-                        classes = new ArrayList();
-                        files = new ArrayList();
-                        currentSegmentSize = 0;
-                        addJarEntry(jarEntry, new BufferedInputStream(jarFile
-                                .getInputStream(jarEntry)), classes, files);
-                        currentSegmentSize = 0; // ignore the size of the first entry for
compatibility with the RI
-                    } else if (segmentLimit == 0 && estimateSize(jarEntry) > 0)
{
-                        // create a new segment for each class unless size = 0
-                        segmentUnitList.add(new SegmentUnit(classes, files));
-                        classes = new ArrayList();
-                        files = new ArrayList();
-                    }
-                }
-            }
-            if(classes.size() > 0 || files.size() > 0) {
-                segmentUnitList.add(new SegmentUnit(classes, files));
-            }
-
-            int size = segmentUnitList.size();
-            int classFileAmount = 0;
-            int fileAmount = 0;
-            int totalByteAmount = 0;
-            int totalPackedByteAmount = 0;
-            SegmentUnit segmentUnit = null;
-            for (int index = 0; index < size; index++) {
-                segmentUnit = (SegmentUnit) segmentUnitList.get(index);
-                classFileAmount += segmentUnit.classList.size();
-                fileAmount += segmentUnit.fileList.size();
-                new Segment().pack(segmentUnit, outputStream, options);
-                totalByteAmount += segmentUnit.getByteAmount();
-                totalPackedByteAmount += segmentUnit.getPackedByteAmount();
-            }
-            PackingUtils.log("Total: Packed " + fileAmount + " files including "
-                    + classFileAmount + " classes of " + totalByteAmount
-                    + " input bytes into " + totalPackedByteAmount + " bytes");
-
-            outputStream.close();
+            doNormalPack();
         }
     }
 
     private void doZeroEffortPack() throws IOException, Pack200Exception {
         PackingUtils.log("Start to perform a zero-effort packing");
-        JarOutputStream jarOutputStream = new JarOutputStream(outputStream);
-        if(inputStream != null) {
-            Manifest manifest = inputStream.getManifest();
-            if (manifest != null) {
-                jarOutputStream.putNextEntry(new JarEntry("META-INF/"));
-                jarOutputStream.closeEntry();
-                PackingUtils.log("Packed \"META-INF\" folder");
-                
-                ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                manifest.write(baos);
-                jarOutputStream.putNextEntry(new JarEntry("META-INF/MANIFEST.MF"));
-                jarOutputStream.write(baos.toByteArray());
-                jarOutputStream.closeEntry();
-                PackingUtils.log("Packed META-INF/MANIFEST.MF");
-            }
-            BufferedInputStream buff = new BufferedInputStream(inputStream);
-            JarEntry jarEntry;
-            while ((jarEntry = inputStream.getNextJarEntry()) != null) {
-                jarOutputStream.putNextEntry(jarEntry);
-                byte[] bytes = new byte[(int) jarEntry.getSize()];
-                int bytesRead = buff.read(bytes);
-                if(bytesRead != jarEntry.getSize()) {
-                    throw new Pack200Exception("Error reading from input jar file");
-                }
-                jarOutputStream.write(bytes, 0, bytesRead);
-                jarOutputStream.closeEntry();
-                PackingUtils.log("Packed " + jarEntry.getName());
-            }
-            jarOutputStream.close();
+        if (jarInputStream != null) {
+            PackingUtils.copyThroughJar(jarInputStream, outputStream);
         } else {
-            Enumeration jarEntries = jarFile.entries();
-            while (jarEntries.hasMoreElements()) {
-                JarEntry jarEntry = (JarEntry) jarEntries.nextElement();
-                InputStream inStream = new BufferedInputStream(
-                        jarFile.getInputStream(jarEntry));
-                jarOutputStream.putNextEntry(jarEntry);
-                byte[] bytes = new byte[16384];
-                int bytesRead = inStream.read(bytes);
-                while (bytesRead != -1) {
-                    jarOutputStream.write(bytes, 0, bytesRead);
-                    bytesRead = inStream.read(bytes);
-                }
-                jarOutputStream.closeEntry();
-                PackingUtils.log("Packed " + jarEntry.getName());
-            }
-            jarOutputStream.close();
+            PackingUtils.copyThroughJar(jarFile, outputStream);
         }
     }
 
-    private boolean addJarEntry(JarEntry jarEntry, InputStream stream,
-            List javaClasses, List files) throws IOException, Pack200Exception {
+    private void doNormalPack() throws IOException, Pack200Exception {
+        PackingUtils.log("Start to perform a normal packing");
+        List packingFileList;
+        if (jarInputStream != null) {
+            packingFileList = PackingUtils.getPackingFileListFromJar(
+                    jarInputStream, options.isKeepFileOrder());
+        } else {
+            packingFileList = PackingUtils.getPackingFileListFromJar(jarFile,
+                    options.isKeepFileOrder());
+        }
+
+        List segmentUnitList = splitIntoSegments(packingFileList);
+        int previousByteAmount = 0;
+        int packedByteAmount = 0;
+
+        int segmentSize = segmentUnitList.size();
+        SegmentUnit segmentUnit;
+        for (int index = 0; index < segmentSize; index++) {
+            segmentUnit = (SegmentUnit) segmentUnitList.get(index);
+            new Segment().pack(segmentUnit, outputStream, options);
+            previousByteAmount += segmentUnit.getByteAmount();
+            packedByteAmount += segmentUnit.getPackedByteAmount();
+        }
+
+        PackingUtils.log("Total: Packed " + previousByteAmount
+                + " input bytes of " + packingFileList.size() + " files into "
+                + packedByteAmount + " bytes in " + segmentSize + " segments");
+
+        outputStream.close();
+    }
+
+    private List splitIntoSegments(List packingFileList) throws IOException,
+            Pack200Exception {
+        List segmentUnitList = new ArrayList();
+        List classes = new ArrayList();
+        List files = new ArrayList();
         long segmentLimit = options.getSegmentLimit();
-        String name = jarEntry.getName();
-        long size = jarEntry.getSize();
-        if (size > Integer.MAX_VALUE) {
-            throw new RuntimeException("Large Class!"); // TODO: Should probably allow this
-        } else if (size < 0) {
-            size = 0;
-//            throw new RuntimeException("Error: size for " + name + " is " + size);
+        
+        int size = packingFileList.size();
+        PackingFile packingFile;
+        for (int index = 0; index < size; index++) {
+            packingFile = (PackingFile) packingFileList.get(index);
+            if (!addJarEntry(packingFile, classes, files)) {
+                // not added because segment has reached maximum size
+                segmentUnitList.add(new SegmentUnit(classes, files));
+                classes = new ArrayList();
+                files = new ArrayList();
+                currentSegmentSize = 0;
+                // add the jar to a new segment
+                addJarEntry(packingFile, classes, files);
+                // ignore the size of first entry for compatibility with RI
+                currentSegmentSize = 0;
+            } else if (segmentLimit == 0 && estimateSize(packingFile) > 0) {
+                // create a new segment for each class unless size is 0
+                segmentUnitList.add(new SegmentUnit(classes, files));
+                classes = new ArrayList();
+                files = new ArrayList();
+            }
         }
-        if(segmentLimit != -1 && segmentLimit != 0) {
-            // -1 is a special case where only one segment is created and
-            // 0 is a special case where one segment is created for each file except for
files in "META-INF"
+        if (classes.size() > 0 && files.size() > 0) {
+            segmentUnitList.add(new SegmentUnit(classes, files));
+        }
+        return segmentUnitList;
+    }
 
-            long packedSize = estimateSize(jarEntry);
-            if (packedSize + currentSegmentSize > segmentLimit && currentSegmentSize
> 0) {
-                return false; // don't add this JarEntry to the current segment
+    private boolean addJarEntry(PackingFile packingFile, List javaClasses,
+            List files) throws IOException, Pack200Exception {
+        long segmentLimit = options.getSegmentLimit();
+        if (segmentLimit != -1 && segmentLimit != 0) {
+            // -1 is a special case where only one segment is created and
+            // 0 is a special case where one segment is created for each file
+            // except for files in "META-INF"
+            long packedSize = estimateSize(packingFile);
+            if (packedSize + currentSegmentSize > segmentLimit
+                    && currentSegmentSize > 0) {
+                // don't add this JarEntry to the current segment
+                return false;
             } else {
-                currentSegmentSize += packedSize; // do add this JarEntry
+                // do add this JarEntry
+                currentSegmentSize += packedSize;
             }
         }
-        byte[] bytes = new byte[(int) size];
-        int read = stream.read(bytes);
-        if (read != size) {
-            throw new RuntimeException("Error reading from stream");
-        }
+
+        String name = packingFile.getName();
         if (name.endsWith(".class") && !options.isPassFile(name)) {
-            Pack200ClassReader classParser = new Pack200ClassReader(bytes);
+            Pack200ClassReader classParser = new Pack200ClassReader(
+                    packingFile.contents);
             classParser.setFileName(name);
             javaClasses.add(classParser);
-            bytes = new byte[0];
+            packingFile.contents = new byte[0];
         }
-        files.add(new PackingFile(name, bytes, jarEntry));
+        files.add(packingFile);
         return true;
     }
 
-    private long estimateSize(JarEntry jarEntry) {
-        // The heuristic used here is for compatibility with the RI and should not be changed
-        String name = jarEntry.getName();
-        if(name.startsWith("META-INF") || name.startsWith("/META-INF")) {
+    private long estimateSize(PackingFile packingFile) {
+        // The heuristic used here is for compatibility with the RI and should
+        // not be changed
+        String name = packingFile.getName();
+        if (name.startsWith("META-INF") || name.startsWith("/META-INF")) {
             return 0;
         } else {
-            long fileSize = jarEntry.getSize();
-            if(fileSize < 0) {
+            long fileSize = packingFile.contents.length;
+            if (fileSize < 0) {
                 fileSize = 0;
             }
             return name.length() + fileSize + 5;
@@ -355,19 +282,22 @@
         private byte[] contents;
         private final long modtime;
         private final boolean deflateHint;
+        private final boolean isDirectory;
 
         public PackingFile(String name, byte[] contents, long modtime) {
             this.name = name;
             this.contents = contents;
             this.modtime = modtime;
             deflateHint = false;
+            isDirectory = false;
         }
 
-        public PackingFile(String name, byte[] contents, JarEntry jarEntry) {
-            this.name = name;
-            this.contents = contents;
+        public PackingFile(byte[] bytes, JarEntry jarEntry) {
+            name = jarEntry.getName();
+            contents = bytes;
             modtime = jarEntry.getTime();
-            deflateHint = (jarEntry.getMethod() == JarEntry.DEFLATED);
+            deflateHint = jarEntry.getMethod() == JarEntry.DEFLATED;
+            isDirectory = jarEntry.isDirectory();
         }
 
         public byte[] getContents() {
@@ -382,10 +312,6 @@
             return modtime;
         }
 
-        public String toString() {
-            return name;
-        }
-
         public void setContents(byte[] contents) {
             this.contents = contents;
         }
@@ -393,6 +319,10 @@
         public boolean isDefalteHint() {
             return deflateHint;
         }
+
+        public boolean isDirectory(){
+            return isDirectory;
+        }
     }
 
 }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingUtils.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingUtils.java?rev=792021&r1=792020&r2=792021&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingUtils.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingUtils.java
Wed Jul  8 03:06:17 2009
@@ -16,7 +16,22 @@
  */
 package org.apache.harmony.pack200;
 
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
 import java.util.logging.FileHandler;
 import java.util.logging.Level;
 import java.util.logging.LogManager;
@@ -24,6 +39,8 @@
 import java.util.logging.Logger;
 import java.util.logging.SimpleFormatter;
 
+import org.apache.harmony.pack200.Archive.PackingFile;
+
 public class PackingUtils {
 
     private static PackingLogger packingLogger;
@@ -68,4 +85,166 @@
         packingLogger.log(Level.INFO, message);
     }
 
+    /**
+     * When effort is 0, the packer copys through the original jar input stream
+     * without compression
+     * 
+     * @param jarInputStream
+     *            the jar input stream
+     * @param jarOutputStream
+     *            the jar output stream
+     * @throws IOException
+     */
+    public static void copyThroughJar(JarInputStream jarInputStream,
+            OutputStream outputStream) throws IOException {
+        Manifest manifest = jarInputStream.getManifest();
+        JarOutputStream jarOutputStream = new JarOutputStream(outputStream,
+                manifest);
+        jarOutputStream.setComment("PACK200");
+        log("Packed " + JarFile.MANIFEST_NAME);
+
+        byte[] bytes = new byte[16384];
+        JarEntry jarEntry;
+        int bytesRead;
+        while ((jarEntry = jarInputStream.getNextJarEntry()) != null) {
+            jarOutputStream.putNextEntry(jarEntry);
+            while ((bytesRead = jarInputStream.read(bytes)) != -1) {
+                jarOutputStream.write(bytes, 0, bytesRead);
+            }
+            log("Packed " + jarEntry.getName());
+        }
+        jarInputStream.close();
+        jarOutputStream.close();
+    }
+
+    /**
+     * When effort is 0, the packer copys through the original jar file without
+     * compression
+     * 
+     * @param jarFile
+     *            the input jar file
+     * @param jarOutputStream
+     *            the jar output stream
+     * @throws IOException
+     */
+    public static void copyThroughJar(JarFile jarFile, OutputStream outputStream)
+            throws IOException {
+        JarOutputStream jarOutputStream = new JarOutputStream(outputStream);
+        jarOutputStream.setComment("PACK200");
+        byte[] bytes = new byte[16384];
+        Enumeration entries = jarFile.entries();
+        InputStream inputStream;
+        JarEntry jarEntry;
+        int bytesRead;
+        while (entries.hasMoreElements()) {
+            jarEntry = (JarEntry) entries.nextElement();
+            jarOutputStream.putNextEntry(jarEntry);
+            inputStream = jarFile.getInputStream(jarEntry);
+            while ((bytesRead = inputStream.read(bytes)) != -1) {
+                jarOutputStream.write(bytes, 0, bytesRead);
+            }
+            jarOutputStream.closeEntry();
+            log("Packed " + jarEntry.getName());
+        }
+        jarFile.close();
+        jarOutputStream.close();
+    }
+
+    public static List getPackingFileListFromJar(JarInputStream jarInputStream,
+            boolean keepFileOrder) throws IOException {
+        List packingFileList = new ArrayList();
+
+        // add manifest file
+        Manifest manifest = jarInputStream.getManifest();
+        if (manifest != null) {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            manifest.write(baos);
+            packingFileList.add(new PackingFile(JarFile.MANIFEST_NAME, baos
+                    .toByteArray(), 0));
+        }
+
+        // add rest of entries in the jar
+        JarEntry jarEntry;
+        byte[] bytes;
+        while ((jarEntry = jarInputStream.getNextJarEntry()) != null) {
+            bytes = readJarEntry(jarEntry, new BufferedInputStream(
+                    jarInputStream));
+            packingFileList.add(new PackingFile(bytes, jarEntry));
+        }
+
+        // check whether it need reorder packing file list
+        if (!keepFileOrder) {
+            reorderPackingFiles(packingFileList);
+        }
+        return packingFileList;
+    }
+
+    public static List getPackingFileListFromJar(JarFile jarFile,
+            boolean keepFileOrder) throws IOException {
+        List packingFileList = new ArrayList();
+        Enumeration jarEntries = jarFile.entries();
+        JarEntry jarEntry;
+        byte[] bytes;
+        while (jarEntries.hasMoreElements()) {
+            jarEntry = (JarEntry) jarEntries.nextElement();
+            bytes = readJarEntry(jarEntry, new BufferedInputStream(jarFile
+                    .getInputStream(jarEntry)));
+            packingFileList.add(new PackingFile(bytes, jarEntry));
+        }
+
+        // check whether it need reorder packing file list
+        if (!keepFileOrder) {
+            reorderPackingFiles(packingFileList);
+        }
+        return packingFileList;
+    }
+
+    private static byte[] readJarEntry(JarEntry jarEntry,
+            InputStream inputStream) throws IOException {
+        long size = jarEntry.getSize();
+        if (size > Integer.MAX_VALUE) {
+            // TODO: Should probably allow this
+            throw new RuntimeException("Large Class!");
+        } else if (size < 0) {
+            size = 0;
+        }
+        byte[] bytes = new byte[(int) size];
+        if (inputStream.read(bytes) != size) {
+            throw new RuntimeException("Error reading from stream");
+        }
+        return bytes;
+    }
+
+    private static void reorderPackingFiles(List packingFileList) {
+        Iterator iterator = packingFileList.iterator();
+        PackingFile packingFile;
+        while (iterator.hasNext()) {
+            packingFile = (PackingFile) iterator.next();
+            if (packingFile.isDirectory()) {
+                // remove directory entries
+                iterator.remove();
+            }
+        }
+
+        // Sort files by name, "META-INF/MANIFEST.MF" should be put in the 1st
+        // position
+        Collections.sort(packingFileList, new Comparator() {
+            public int compare(Object arg0, Object arg1) {
+                if (arg0 instanceof PackingFile && arg1 instanceof PackingFile) {
+                    String fileName0 = ((PackingFile) arg0).getName();
+                    String fileName1 = ((PackingFile) arg1).getName();
+                    if (fileName0.equals(fileName1)) {
+                        return 0;
+                    } else if (JarFile.MANIFEST_NAME.equals(fileName0)) {
+                        return -1;
+                    } else if (JarFile.MANIFEST_NAME.equals(fileName1)) {
+                        return 1;
+                    }
+                    return fileName0.compareTo(fileName1);
+                }
+                throw new IllegalArgumentException();
+            }
+        });
+    }
+
 }
\ No newline at end of file

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Archive.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Archive.java?rev=792021&r1=792020&r2=792021&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Archive.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Archive.java
Wed Jul  8 03:06:17 2009
@@ -232,6 +232,11 @@
         this.logFile = new FileOutputStream(logFileName);
     }
 
+    public void setLogFile(String logFileName, boolean append)
+            throws FileNotFoundException {
+        logFile = new FileOutputStream(logFileName, true);
+    }
+
     public void setDeflateHint(boolean deflateHint) {
         overrideDeflateHint = true;
         this.deflateHint = deflateHint;

Modified: harmony/enhanced/jdktools/trunk/modules/jretools/src/main/java/org/apache/harmony/jretools/pack200/Main.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jretools/src/main/java/org/apache/harmony/jretools/pack200/Main.java?rev=792021&r1=792020&r2=792021&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jretools/src/main/java/org/apache/harmony/jretools/pack200/Main.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/jretools/src/main/java/org/apache/harmony/jretools/pack200/Main.java
Wed Jul  8 03:06:17 2009
@@ -26,6 +26,7 @@
 import java.util.Enumeration;
 import java.util.Properties;
 import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
 import java.util.jar.JarOutputStream;
 
 import org.apache.harmony.pack200.PackingOptions;
@@ -279,10 +280,10 @@
             PackingOptions options) throws IOException {
         Properties packProperties = new Properties();
         packProperties.load(new FileInputStream(packPropertyFileName));
-        Enumeration<?> enums = packProperties.propertyNames();
+        Enumeration propertyNames = packProperties.propertyNames();
         String propretyName, propretyValue;
-        while (enums.hasMoreElements()) {
-            propretyName = (String) enums.nextElement();
+        while (propertyNames.hasMoreElements()) {
+            propretyName = (String) propertyNames.nextElement();
             propretyValue = packProperties.getProperty(propretyName);
 
             if ("deflate.hint".equals(propretyName)) {
@@ -341,10 +342,16 @@
         }
 
         // packing
-        JarFile jarFile = new JarFile(inputFileName);
         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-        org.apache.harmony.pack200.Archive packer = new org.apache.harmony.pack200.Archive(
-                jarFile, outputStream, options);
+        org.apache.harmony.pack200.Archive packer;
+        // this is a workround for compatibility with RI
+        if (0 == options.getEffort()) {
+            packer = new org.apache.harmony.pack200.Archive(new JarInputStream(
+                    new FileInputStream(inputFileName)), outputStream, options);
+        } else {
+            packer = new org.apache.harmony.pack200.Archive(new JarFile(
+                    inputFileName), outputStream, options);
+        }
         packer.pack();
 
         // unpacking
@@ -360,7 +367,11 @@
         if (!options.isKeepDeflateHint()) {
             unpacker.setDeflateHint("true".equals(options.getDeflateHint()));
         }
-        //TODO: log file config should be handled
+        // set log file
+        String logFile = options.getLogFile();
+        if(logFile != null) {
+            unpacker.setLogFile(logFile, true);
+        }
         unpacker.unpack();
     }
 



Mime
View raw message