KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > neu > ccs > jmk > sun > Jar


1 // $Id: Jar.java,v 1.2 2001/12/07 11:41:24 ramsdell Exp $
2

3 /*
4  * Copyright 1999 by Olivier Refalo
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */

20
21 package edu.neu.ccs.jmk.sun;
22
23 import sun.tools.jar.*;
24 import edu.neu.ccs.jmk.Operator;
25 import edu.neu.ccs.jmk.CommandFailedException;
26 import java.io.*;
27
28 /**
29  * Jar as an Operator.
30  * <pre>
31  * jar = "edu.neu.ccs.jmk.sun.Jar";
32  *
33  * "all":;
34  * {
35  * forname jar "cvf" "arch.jar" (glob "*.class");
36  * }
37  * </pre>
38  */

39 public final class Jar
40 implements Operator
41 {
42     public String JavaDoc getName()
43     {
44         return("Jar");
45     }
46
47     public void exec(String JavaDoc[] _args, PrintWriter _out)
48     throws CommandFailedException
49     {
50         Main ji;
51
52         if ( _args.length == 0 )
53             throw new CommandFailedException("No args to " + getName());
54         try
55         {
56             OutputStream os=new OutputStreamToPrintWriter(_out);
57             // I know, this code is deprecated but Jar needs PrintStreams !
58
PrintStream ps=new PrintStream(os);
59             ji = new Main(ps, ps, "jar");
60
61             if ( ji.run(_args) == false )
62                 throw new CommandFailedException(getName() + " failed");
63
64         } catch ( CommandFailedException ex1 )
65         {
66             throw ex1;
67         } catch ( Exception JavaDoc ex2 )
68         {
69             throw new CommandFailedException(getName() + " threw an exception ->"+ex2.toString());
70         } finally
71         {
72             ji=null;
73             // clean up VM allocations
74
System.gc();
75         }
76     }
77
78 }
79
Popular Tags