01: /*
02:
03: Derby - Class org.apache.derbyTesting.functionTests.util.JartUtil
04:
05: Licensed to the Apache Software Foundation (ASF) under one
06: or more contributor license agreements. See the NOTICE file
07: distributed with this work for additional information
08: regarding copyright ownership. The ASF licenses this file
09: to you under the Apache License, Version 2.0 (the
10: "License"); you may not use this file except in compliance
11: with the License. You may obtain a copy of the License at
12:
13: http://www.apache.org/licenses/LICENSE-2.0
14:
15: Unless required by applicable law or agreed to in writing,
16: software distributed under the License is distributed on an
17: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18: KIND, either express or implied. See the License for the
19: specific language governing permissions and limitations
20: under the License.
21: */
22:
23: package org.apache.derbyTesting.functionTests.util;
24:
25: import java.io.*;
26:
27: /**
28: *
29: * <Put Class Comments Here>
30: */
31: public class JarUtil {
32:
33: /**
34: * Unjar a file into the specified directory. This runs in a separate
35: * process. Note, your test needs security permissions to read user.dir
36: * and to start a process for this to work.
37: *
38: * @param jarpath - Path to jar file
39: *
40: * @param outputdir - The directory to unjar to. If this is null,
41: * we user user.dir (the current directory)
42: *
43: */
44: public static void unjar(String jarpath, String outputdir)
45: throws ClassNotFoundException, IOException,
46: InterruptedException {
47: if (outputdir == null) {
48: outputdir = System.getProperty("user.dir");
49: }
50: File jarFile = new File((new File(outputdir, jarpath))
51: .getCanonicalPath());
52:
53: // Now unjar the file
54: String jarCmd = "jar xf " + jarFile.getPath();
55: // Now execute the jar command
56: Process pr = null;
57: try {
58: //System.out.println("Use process to execute: " + jarCmd);
59: pr = Runtime.getRuntime().exec(jarCmd);
60:
61: pr.waitFor();
62: //System.out.println("Process done.");
63: pr.destroy();
64: } finally {
65: if (pr != null) {
66: pr.destroy();
67: pr = null;
68: }
69: }
70: }
71: }
|