harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r786083 - in /harmony/enhanced/classlib/trunk/modules/pack200/src: main/java/org/apache/harmony/pack200/ test/java/org/apache/harmony/pack200/tests/
Date Thu, 18 Jun 2009 14:33:42 GMT
Author: sjanuary
Date: Thu Jun 18 14:33:42 2009
New Revision: 786083

URL: http://svn.apache.org/viewvc?rev=786083&view=rev
Log:
Pack200 - Test and a bug fix for pass files option (-p)

Modified:
    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/PackingOptions.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java

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=786083&r1=786082&r2=786083&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
Thu Jun 18 14:33:42 2009
@@ -41,7 +41,7 @@
     private final byte[][] file_bits;
 
     public FileBands(CpBands cpBands, SegmentHeader segmentHeader,
-            List files, List classes, int effort) {
+            PackingOptions options, List files, List classes, int effort) {
         super(effort, segmentHeader);
         int size =  files.size();
         fileName = new CPUTF8[size];
@@ -61,7 +61,7 @@
         for (int i = 0; i < files.size(); i++) {
              File file = (File)files.get(i);
              String name = file.getName();
-             if(name.endsWith(".class")) {
+             if(name.endsWith(".class") && !options.isPassFile(name)) {
                  file_options[i] |= (1 << 1);
                  if(classNames.contains(name.substring(0, name.length() - 6))) {
                      fileName[i] = emptyString;

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingOptions.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingOptions.java?rev=786083&r1=786082&r2=786083&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingOptions.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingOptions.java
Thu Jun 18 14:33:42 2009
@@ -167,7 +167,12 @@
         if(passFiles == null) {
             passFiles = new ArrayList();
         }
-        passFileName.replaceAll(System.getProperty("file.separator"), "/");
+        String fileSeparator = System.getProperty("file.separator");
+        if(fileSeparator.equals("\\")) {
+            // Need to escape backslashes for replaceAll(), which uses regex
+            fileSeparator += "\\";
+        }
+        passFileName.replaceAll(fileSeparator, "/");
         passFiles.add(passFileName);
     }
 

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=786083&r1=786082&r2=786083&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
Thu Jun 18 14:33:42 2009
@@ -83,7 +83,7 @@
         icBands = new IcBands(segmentHeader, cpBands, effort);
         classBands = new ClassBands(this, classes.size(), effort, stripDebug);
         bcBands = new BcBands(cpBands, this, effort);
-        fileBands = new FileBands(cpBands, segmentHeader, files, classes, effort);
+        fileBands = new FileBands(cpBands, segmentHeader, options, files, classes, effort);
 
         processClasses(classes, files);
 

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java?rev=786083&r1=786082&r2=786083&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
Thu Jun 18 14:33:42 2009
@@ -245,6 +245,78 @@
         compareFiles(jarFile, jarFile2);
     }
 
+    public void testPassFiles() throws IOException, URISyntaxException, Pack200Exception
{
+        // Don't pass any
+        in = new JarFile(new File(Archive.class
+                .getResource("/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI()));
+        File file0 = File.createTempFile("sql", ".pack");
+        out = new FileOutputStream(file0);
+        PackingOptions options = new PackingOptions();
+        options.setGzip(false);
+        Archive archive = new Archive(in, out, options);
+        archive.pack();
+        in.close();
+        out.close();
+
+        // Pass one file
+        in = new JarFile(new File(Archive.class
+                .getResource("/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI()));
+        file = File.createTempFile("sql", ".pack");
+        out = new FileOutputStream(file);
+        options = new PackingOptions();
+        options.setGzip(false);
+        options.addPassFile("bin/test/org/apache/harmony/sql/tests/java/sql/DatabaseMetaDataTest.class");
+        assertTrue(options.isPassFile("bin/test/org/apache/harmony/sql/tests/java/sql/DatabaseMetaDataTest.class"));
+        archive = new Archive(in, out, options);
+        archive.pack();
+        in.close();
+        out.close();
+
+        // Pass a whole directory
+        in = new JarFile(new File(Archive.class
+                .getResource("/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI()));
+        File file2 = File.createTempFile("sql", ".pack");
+        out = new FileOutputStream(file2);
+        options = new PackingOptions();
+        options.setGzip(false);
+        options.addPassFile("bin/test/org/apache/harmony/sql/tests/java/sql");
+        assertTrue(options.isPassFile("bin/test/org/apache/harmony/sql/tests/java/sql/DatabaseMetaDataTest.class"));
+        assertFalse(options.isPassFile("bin/test/org/apache/harmony/sql/tests/java/sqldata/SqlData.class"));
+        archive = new Archive(in, out, options);
+        archive.pack();
+        in.close();
+        out.close();
+
+        assertTrue("If files are passed then the pack file should be larger", file.length()
> file0.length());
+        assertTrue("If more files are passed then the pack file should be larger", file2.length()
> file.length());
+
+        // now unpack
+        InputStream in2 = new FileInputStream(file);
+        File file3 = File.createTempFile("sql", ".jar");
+        JarOutputStream out2 = new JarOutputStream(new FileOutputStream(file3));
+        org.apache.harmony.unpack200.Archive u2archive = new org.apache.harmony.unpack200.Archive(in2,
out2);
+        u2archive.unpack();
+
+        File compareFile = new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI());
+        JarFile jarFile = new JarFile(file3);
+        file2.deleteOnExit();
+
+        JarFile jarFile2 = new JarFile(compareFile);
+        // Check that both jars have the same entries
+        compareJarEntries(jarFile, jarFile2);
+
+        // now unpack the file with lots of passed files
+        InputStream in3 = new FileInputStream(file2);
+        File file4 = File.createTempFile("sql", ".jar");
+        JarOutputStream out3 = new JarOutputStream(new FileOutputStream(file4));
+        u2archive = new org.apache.harmony.unpack200.Archive(in3, out3);
+        u2archive.unpack();
+        jarFile = new JarFile(file4);
+        jarFile2 = new JarFile(compareFile);
+        compareJarEntries(jarFile, jarFile2);
+    }
+
     public void testAnnotations() throws IOException, Pack200Exception,
             URISyntaxException {
         in = new JarFile(new File(Archive.class.getResource(
@@ -325,6 +397,20 @@
 		}
     }
 
+    private void compareJarEntries(JarFile jarFile, JarFile jarFile2)
+            throws IOException {
+        Enumeration entries = jarFile.entries();
+        while (entries.hasMoreElements()) {
+
+            JarEntry entry = (JarEntry) entries.nextElement();
+            assertNotNull(entry);
+
+            String name = entry.getName();
+            JarEntry entry2 = jarFile2.getJarEntry(name);
+            assertNotNull("Missing Entry: " + name, entry2);
+        }
+    }
+
     private void compareFiles(JarFile jarFile, JarFile jarFile2)
             throws IOException {
         Enumeration entries = jarFile.entries();



Mime
View raw message