Changeset 4bb902a


Ignore:
Timestamp:
Oct 24, 2010 4:49:20 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
b1f17255
Parents:
ed399a07
Message:
  • FileUtil?: Make it easier to compile without Pack200, or with

Apache Harmony's Pack200, add unzip to main()

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • build.xml

    red399a07 r4bb902a  
    66    <!--
    77        <property name="javac.compilerargs" value="-warn:-unchecked,raw,unused,serial" />
     8    -->
     9    <!-- Add Apache Harmony's Pack200 library if you don't have java.util.jar.Pack200
     10         See core/java/src/net/i2p/util/FileUtil.java for code changes required
     11         to use this library instead of Sun's version.
     12         Or to comment it all out if you don't have either.
     13    -->
     14    <!--
     15        <property name="javac.classpath" value="/PATH/TO/pack200.jar" />
    816    -->
    917
  • core/java/build.xml

    red399a07 r4bb902a  
    1818    <!-- only used if not set by a higher build.xml -->
    1919    <property name="javac.compilerargs" value="" />
     20    <property name="javac.classpath" value="" />
    2021    <target name="compile" depends="depend">
    2122        <mkdir dir="./build" />
    2223        <mkdir dir="./build/obj" />
    23         <javac srcdir="./src" debug="true" source="1.5" target="1.5" deprecation="on" destdir="./build/obj" >
     24        <javac srcdir="./src" debug="true" source="1.5" target="1.5" deprecation="on" destdir="./build/obj" classpath="${javac.classpath}" >
    2425            <compilerarg line="${javac.compilerargs}" />
    2526        </javac>
  • core/java/src/net/i2p/util/FileUtil.java

    red399a07 r4bb902a  
    1414import java.util.List;
    1515import java.util.jar.JarOutputStream;
    16 import java.util.jar.Pack200;
    1716import java.util.zip.ZipEntry;
    1817import java.util.zip.ZipFile;
    1918
     19// Pack200 import
     20// you must also uncomment the correct line in unpack() below
     21// For gcj, gij, etc., comment both out
     22//
     23// For Sun, OpenJDK, IcedTea, etc, use this
     24import java.util.jar.Pack200;
     25
     26// For Apache Harmony or if you put its pack200.jar in your library directory use this
     27//import org.apache.harmony.unpack200.Archive;
    2028
    2129/**
     
    120128                            target = new File(targetDir, entry.getName().substring(0, entry.getName().length() - ".pack".length()));
    121129                            JarOutputStream fos = new JarOutputStream(new FileOutputStream(target));
    122                             Pack200.newUnpacker().unpack(in, fos);
     130                            unpack(in, fos);
    123131                            fos.close();
    124132                            System.err.println("INFO: File [" + entry.getName() + "] extracted and unpacked");
     
    190198                    if (p200TestRequired &&
    191199                        (entry.getName().endsWith(".jar.pack") || entry.getName().endsWith(".war.pack"))) {
    192                         try {
    193                             Class.forName("java.util.jar.Pack200", false, ClassLoader.getSystemClassLoader());
    194                         } catch (Exception e) {  // ClassNotFoundException but compiler not happy with that
     200                        if (!isPack200Supported()) {
    195201                            System.err.println("ERROR: Zip verify failed, your JVM does not support unpack200");
    196202                            return false;
     
    226232   
    227233    /**
     234     * This won't work right if one of the two options in unpack() is commented out.
     235     * @since 0.8.1
     236     */
     237    private static boolean isPack200Supported() {
     238        try {
     239            Class.forName("java.util.jar.Pack200", false, ClassLoader.getSystemClassLoader());
     240            return true;
     241        } catch (Exception e) {}
     242        try {
     243            Class.forName("org.apache.harmony.pack200.Archive", false, ClassLoader.getSystemClassLoader());
     244            return true;
     245        } catch (Exception e) {}
     246        return false;
     247    }
     248
     249    /**
     250     * Caller must close streams
     251     * @since 0.8.1
     252     */
     253    private static void unpack(InputStream in, JarOutputStream out) throws Exception {
     254        // For Sun, OpenJDK, IcedTea, etc, use this
     255        Pack200.newUnpacker().unpack(in, out);
     256
     257        // ------------------
     258        // For Apache Harmony or if you put its pack200.jar in your library directory use this
     259        //(new Archive(in, out)).unpack();
     260
     261
     262        // ------------------
     263        // For gcj, gij, etc., use this
     264        //throw new IOException("Pack200 not supported");
     265    }
     266
     267    /**
    228268     * Read in the last few lines of a (newline delimited) textfile, or null if
    229269     * the file doesn't exist. 
     
    353393            if (!copied)
    354394                System.err.println("Error copying [" + args[1] + "] to [" + args[2] + "]");
     395        } else if ("unzip".equals(args[0])) {
     396            File f = new File(args[1]);
     397            File to = new File("tmp");
     398            to.mkdir();
     399            boolean copied = verifyZip(f);
     400            if (!copied)
     401                System.err.println("Error verifying " + args[1]);
     402            copied = extractZip(f,  to);
     403            if (copied)
     404                System.err.println("Unzipped [" + args[1] + "] to [" + to + "]");
     405            else
     406                System.err.println("Error unzipping [" + args[1] + "] to [" + to + "]");
    355407        }
    356408    }
Note: See TracChangeset for help on using the changeset viewer.