harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhouke...@apache.org
Subject svn commit: r790837 - in /harmony/enhanced: classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ jdktools/trunk/modules/jretools/src/main/java/org/apache/harmony/jretools/pack200/
Date Fri, 03 Jul 2009 09:44:51 GMT
Author: zhoukevin
Date: Fri Jul  3 09:44:50 2009
New Revision: 790837

URL: http://svn.apache.org/viewvc?rev=790837&view=rev
Log:
Implement -m 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/FileBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.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=790837&r1=790836&r2=790837&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
Fri Jul  3 09:44:50 2009
@@ -113,7 +113,7 @@
                     PackingUtils.log("Pack META-INF/MANIFEST.MF");
                     ByteArrayOutputStream baos = new ByteArrayOutputStream();
                     manifest.write(baos);
-                    files.add(new File("META-INF/MANIFEST.MF", baos.toByteArray(), 0));
+                    files.add(new PackingFile("META-INF/MANIFEST.MF", baos.toByteArray(),
0));
                 }
                 JarEntry jarEntry = inputStream.getNextJarEntry();
                 while (jarEntry != null) {
@@ -274,7 +274,7 @@
             javaClasses.add(classParser);
             bytes = new byte[0];
         }
-        files.add(new File(name, bytes, jarEntry.getTime()));
+        files.add(new PackingFile(name, bytes, jarEntry.getTime()));
         return true;
     }
 
@@ -313,9 +313,9 @@
                 byteAmount += classReader.b.length;
             }
 
-            File file;
+            PackingFile file;
             for (Iterator iterator = fileList.iterator(); iterator.hasNext();) {
-                file = (File) iterator.next();
+                file = (PackingFile) iterator.next();
                 byteAmount += file.contents.length;
             }
         }
@@ -349,13 +349,13 @@
         }
     }
 
-    static class File {
+    static class PackingFile {
 
         private final String name;
         private byte[] contents;
         private final long modtime;
 
-        public File(String name, byte[] contents, long modtime) {
+        public PackingFile(String name, byte[] contents, long modtime) {
             this.name = name;
             this.contents = contents;
             this.modtime = modtime;

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java?rev=790837&r1=790836&r2=790837&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java
Fri Jul  3 09:44:50 2009
@@ -22,8 +22,9 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
+import java.util.TimeZone;
 
-import org.apache.harmony.pack200.Archive.File;
+import org.apache.harmony.pack200.Archive.PackingFile;
 import org.apache.harmony.pack200.Archive.SegmentUnit;
 import org.objectweb.asm.ClassReader;
 
@@ -45,7 +46,7 @@
             PackingOptions options, SegmentUnit segmentUnit, int effort) {
         super(effort, segmentHeader);
         List fileList = segmentUnit.getFileList();
-        int size =  fileList.size();
+        int size = fileList.size();
         fileName = new CPUTF8[size];
         file_modtime = new int[size];
         file_size = new long[size];
@@ -55,30 +56,48 @@
         int archiveModtime = segmentHeader.getArchive_modtime();
 
         Set classNames = new HashSet();
-        for (Iterator iterator = segmentUnit.getClassList().iterator(); iterator.hasNext();)
{
+        for (Iterator iterator = segmentUnit.getClassList().iterator(); iterator
+                .hasNext();) {
             ClassReader reader = (ClassReader) iterator.next();
             classNames.add(reader.getClassName());
         }
         CPUTF8 emptyString = cpBands.getCPUtf8("");
+        long modtime;
+        int latestModtime = Integer.MIN_VALUE;
+        boolean isLatest = !PackingOptions.KEEP.equals(options
+                .getModificationTime());
         for (int i = 0; i < size; i++) {
-             File file = (File)fileList.get(i);
-             String name = file.getName();
-             if(name.endsWith(".class") && !options.isPassFile(name)) {
-                 file_options[i] |= (1 << 1);
-                 if(classNames.contains(name.substring(0, name.length() - 6))) {
-                     fileName[i] = emptyString;
-                 } else {
-                     fileName[i] = cpBands.getCPUtf8(name);
-                 }
-             } else {
-                 fileName[i] = cpBands.getCPUtf8(name);
-             }
-             byte[] bytes = file.getContents();
-             file_size[i] = bytes.length;
-             totalSize += file_size[i];
-             file_modtime[i] = (int)(file.getModtime() - archiveModtime);
-             file_bits[i] = file.getContents();
-         }
+            PackingFile file = (PackingFile) fileList.get(i);
+            String name = file.getName();
+            if (name.endsWith(".class") && !options.isPassFile(name)) {
+                file_options[i] |= (1 << 1);
+                if (classNames.contains(name.substring(0, name.length() - 6))) {
+                    fileName[i] = emptyString;
+                } else {
+                    fileName[i] = cpBands.getCPUtf8(name);
+                }
+            } else {
+                fileName[i] = cpBands.getCPUtf8(name);
+            }
+            byte[] bytes = file.getContents();
+            file_size[i] = bytes.length;
+            totalSize += file_size[i];
+
+            // update modification time
+            modtime = (file.getModtime() + TimeZone.getDefault().getRawOffset()) / 1000L;
+            file_modtime[i] = (int) (modtime - archiveModtime);
+            if (isLatest && latestModtime < file_modtime[i]) {
+                latestModtime = file_modtime[i];
+            }
+
+            file_bits[i] = file.getContents();
+        }
+
+        if (isLatest) {
+            for (int index = 0; index < size; index++) {
+                file_modtime[index] = latestModtime;
+            }
+        }
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java?rev=790837&r1=790836&r2=790837&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
Fri Jul  3 09:44:50 2009
@@ -23,7 +23,7 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.harmony.pack200.Archive.File;
+import org.apache.harmony.pack200.Archive.PackingFile;
 import org.apache.harmony.pack200.Archive.SegmentUnit;
 import org.objectweb.asm.AnnotationVisitor;
 import org.objectweb.asm.Attribute;
@@ -163,7 +163,7 @@
                 boolean found = false;
                 for (Iterator iterator2 = segmentUnit.getFileList().iterator(); iterator2
                         .hasNext();) {
-                    File file = (File) iterator2.next();
+                    PackingFile file = (PackingFile) iterator2.next();
                     if(file.getName().equals(name)) {
                         found = true;
                         file.setContents(classReader.b);

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=790837&r1=790836&r2=790837&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
Fri Jul  3 09:44:50 2009
@@ -25,7 +25,7 @@
 import java.io.OutputStream;
 import java.util.Enumeration;
 import java.util.Properties;
-import java.util.jar.JarInputStream;
+import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
 
 import org.apache.harmony.pack200.PackingOptions;
@@ -318,12 +318,11 @@
             return;
         }
 
-        JarInputStream inputStream = new JarInputStream(new FileInputStream(
-                inputFileName));
+        JarFile jarFile = new JarFile(inputFileName);
         OutputStream outputStream = new BufferedOutputStream(
                 new FileOutputStream(outputFileName));
         org.apache.harmony.pack200.Archive archive = new org.apache.harmony.pack200.Archive(
-                inputStream, outputStream, options);
+                jarFile, outputStream, options);
         archive.pack();
     }
 
@@ -341,19 +340,27 @@
             inputFileName = outputFileName;
         }
 
+        // packing
+        JarFile jarFile = new JarFile(inputFileName);
         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-        JarInputStream jarInputStream = new JarInputStream(new FileInputStream(
-                inputFileName));
         org.apache.harmony.pack200.Archive packer = new org.apache.harmony.pack200.Archive(
-                jarInputStream, outputStream, options);
+                jarFile, outputStream, options);
         packer.pack();
 
+        // unpacking
         ByteArrayInputStream inputStream = new ByteArrayInputStream(
                 outputStream.toByteArray());
         JarOutputStream jarOutputStream = new JarOutputStream(
                 new FileOutputStream(outputFileName));
         org.apache.harmony.unpack200.Archive unpacker = new org.apache.harmony.unpack200.Archive(
                 inputStream, jarOutputStream);
+        unpacker.setVerbose(options.isVerbose());
+        unpacker.setQuiet(options.isQuiet());
+        String deflateHint = options.getDeflateHint();
+        if(!"keep".equals(deflateHint)) {
+            unpacker.setDeflateHint("true".equals(deflateHint));
+        }
+        //TODO: log file config should be handled
         unpacker.unpack();
     }
 



Mime
View raw message