You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by od...@apache.org on 2009/04/29 14:38:21 UTC

svn commit: r769773 - in /harmony/enhanced/jdktools/trunk/modules: jdktools/src/main/java/org/apache/harmony/tools/jar/ jdktools/src/main/java/org/apache/harmony/tools/jar/Main.java samsa/build.xml

Author: odeakin
Date: Wed Apr 29 12:38:19 2009
New Revision: 769773

URL: http://svn.apache.org/viewvc?rev=769773&view=rev
Log:
Add jar tool with simple jar listing capability

Added:
    harmony/enhanced/jdktools/trunk/modules/jdktools/src/main/java/org/apache/harmony/tools/jar/
    harmony/enhanced/jdktools/trunk/modules/jdktools/src/main/java/org/apache/harmony/tools/jar/Main.java   (with props)
Modified:
    harmony/enhanced/jdktools/trunk/modules/samsa/build.xml

Added: harmony/enhanced/jdktools/trunk/modules/jdktools/src/main/java/org/apache/harmony/tools/jar/Main.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jdktools/src/main/java/org/apache/harmony/tools/jar/Main.java?rev=769773&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jdktools/src/main/java/org/apache/harmony/tools/jar/Main.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jdktools/src/main/java/org/apache/harmony/tools/jar/Main.java Wed Apr 29 12:38:19 2009
@@ -0,0 +1,165 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.harmony.tools.jar;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+/**
+ * This is a tool that allows you to create/unpack jar/zip 
+ * archives 
+ */
+public class Main {
+
+    /**
+     * Prints the usage information.
+     */
+    public static void usage() {
+        System.out.println("Usage:");
+        System.out.println("  jar c[v0Mmf] [-C dir] [manifest_file] [jar_file] [input_files]");
+        System.out.println("  jar u[v0Mmf] [-C dir] [manifest_file] [jar_file] [input_files]");
+        System.out.println("  jar x[vf] [jar_file] [input_files]");
+        System.out.println("  jar t[vf] [jar_file] [input_files]");
+        System.out.println("  jar i jar_file");
+        System.out.println("");
+        System.out.println("Examples:");
+        System.out.println("  To create a jar file called my.jar with manifest mymanifest.mf containing");
+        System.out.println("  a.class and b.class, execute the following:");
+        System.out.println("     jar cmf mymanifest.mf my.jar a.class b.class");
+        System.out.println("  To extract a jar file called my.jar with verbose output, execute the");
+        System.out.println("  following:");
+        System.out.println("     jar xvf my.jar");
+    }
+
+    /**
+     * A convenient way to run this tool from a command line.
+     */
+    public static void main(String args[]) throws Exception {
+        if (args.length == 0) {
+            usage();
+            return;
+        }
+
+        // Strip '-' at the start of options
+        if (args[0].charAt(0) == '-') {
+            args[0] = args[0].substring(1);
+        }
+
+        switch (args[0].charAt(0)) {
+        case 'c':
+            createJar(args);
+            break;
+        case 'u':
+            updateJar(args);
+            break;
+        case 'x':
+            extractJar(args);
+            break;
+        case 't':
+            listJar(args);
+            break;
+        case 'i':
+            indexJar(args);
+            break;
+        default:
+            System.out.println("Error: Illegal option '"+args[0].charAt(0)+"'");
+            usage();
+            return;
+        }
+
+        // Need to parse -J option too - the launcher should handle this, no?
+    }
+
+    /**
+     * Creates a jar file with the specified arguments
+     */
+    private static void createJar(String[] args) {
+    }
+
+    /**
+     * Updates a jar file with the specified arguments
+     */
+    private static void updateJar(String[] args) {
+    }
+
+    /**
+     * Extracts a jar file with the specified arguments
+     */
+    private static void extractJar(String[] args) {
+    }
+
+    /**
+     * Lists contents of jar file with the specified arguments
+     */
+    private static void listJar(String[] args) throws Exception{
+        boolean verboseFlag = false, fileFlag = false;
+        for (int i=1; i<args[0].length(); i++) {
+            switch (args[0].charAt(i)) {
+            case 'v':
+                verboseFlag = true;
+                break;
+            case 'f':
+                fileFlag = true;
+                break;
+            default:
+                System.out.println("Error: Illegal option for -t: '"+args[0].charAt(i)+"'");
+                return;
+            }
+        }
+
+        if (fileFlag && args.length<2) {
+            System.out.println("Error: No file name specified for 'f' option");
+            return;
+        }
+
+        ZipInputStream zis;
+        if (!fileFlag) {
+            // Read from stdin
+            if (verboseFlag) System.out.println("Reading input from stdin");
+            zis = new ZipInputStream(System.in);
+        } else {
+            if (verboseFlag) System.out.println("Reading jar file: "+args[1]);
+            zis = new ZipInputStream(new FileInputStream(new File(args[1])));
+        }
+
+        if (verboseFlag) System.out.println("Listing files:");
+
+        ZipEntry ze;
+        while ((ze = zis.getNextEntry()) != null) {
+            //System.out.println(ze.getCompressedSize()+" "+ze.getSize()+" "+ze.getTime()+" "+ze.getName());
+            Date date = new Date(ze.getTime());
+            DateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyy");
+            String formattedDate = dateFormat.format(date);
+            System.out.printf("%6d %s %s\n", ze.getSize(), formattedDate, ze.getName());
+        }
+
+        zis.close();
+    }
+
+    /**
+     * Indexes a jar file with the specified arguments
+     */
+    private static void indexJar(String[] args) {
+    }
+
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jdktools/src/main/java/org/apache/harmony/tools/jar/Main.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/jdktools/trunk/modules/samsa/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/samsa/build.xml?rev=769773&r1=769772&r2=769773&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/samsa/build.xml (original)
+++ harmony/enhanced/jdktools/trunk/modules/samsa/build.xml Wed Apr 29 12:38:19 2009
@@ -90,6 +90,9 @@
         <copy file="${hy.samsa.exe}" tofile="${jdktools.deploy.dir}/bin/policytool${exe.suffix}" />
         <chmod file="${jdktools.deploy.dir}/bin/policytool${exe.suffix}" perm="ugo+x" />
 
+        <copy file="${hy.samsa.exe}" tofile="${jdktools.deploy.dir}/bin/jar${exe.suffix}" />
+        <chmod file="${jdktools.deploy.dir}/bin/jar${exe.suffix}" perm="ugo+x" />
+
         <copy file="${hy.samsa.exe}" tofile="${jretools.deploy.dir}/bin/keytool${exe.suffix}" />
         <chmod file="${jretools.deploy.dir}/bin/keytool${exe.suffix}" perm="ugo+x" />