]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/CreateMdkPkg/src/org/tianocore/packaging/FrameworkPkg.java
e12b58438f185360b31cfe9f51d5396944b1515a
3 The file is used to install .jar file
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 package org
.tianocore
.packaging
;
19 import java
.io
.FileOutputStream
;
20 import java
.io
.IOException
;
21 import java
.io
.InputStream
;
22 import java
.util
.Enumeration
;
23 import java
.util
.jar
.JarEntry
;
24 import java
.util
.jar
.JarFile
;
26 import javax
.swing
.JFrame
;
29 The class is used to install .jar file
31 @since CreateMdkPkg 1.0
34 public class FrameworkPkg
{
36 // Define class members
40 private String pkg
= null;
42 private JarFile jf
= null;
45 Main clase, used to test
50 public static void main(String
[] args
) {
51 FrameworkPkg fp
= new FrameworkPkg("C:\\Documents and Settings\\hchen30\\Desktop\\com.jar");
53 fp
.install("C:\\MyWorkspace" + System
.getProperty("file.separator"));
54 } catch (Exception e
) {
60 This is the default constructor
63 public FrameworkPkg() {
68 This is the override constructor
73 public FrameworkPkg(String package_name
) {
83 public void setPkg(String package_name
) {
93 public void setJarFile() throws IOException
{
94 jf
= new JarFile(pkg
);
98 Install the jar file to specific path
100 @param dir The target path
103 @throws BasePkgNotInstalled
109 public int install(final String dir
) throws IOException
, BasePkgNotInstalled
, VerNotEqual
, GuidNotEqual
, SameAll
{
121 public int uninstall() {
130 @throws BasePkgNotInstalled
136 protected void pre_install() throws IOException
, BasePkgNotInstalled
, VerNotEqual
, GuidNotEqual
, SameAll
{
137 jf
= new JarFile(pkg
);
139 throw new BasePkgNotInstalled();
142 throw new VerNotEqual();
145 throw new GuidNotEqual();
158 protected void post_install() throws IOException
{
164 Extract the jar file to specific dir
166 @param dir The target path
170 private synchronized void extract(String dir
) throws IOException
{
174 for (Enumeration e
= jf
.entries(); e
.hasMoreElements(); i
++) {
175 JarEntry je
= (JarEntry
) e
.nextElement();
176 if (je
.getName().contains("META-INF"))
178 if (je
.isDirectory()) {
179 new File(dir
+ je
.getName()).mkdirs();
185 // Get an input stream for the entry.
187 InputStream entryStream
= jf
.getInputStream(je
);
191 // Create the output file (clobbering the file if it exists).
193 FileOutputStream file
= new FileOutputStream(dir
+ je
.getName());
197 // Allocate a buffer for reading the entry data.
199 byte[] buffer
= new byte[1024];
203 // Read the entry data and write it to the output file.
205 while ((bytesRead
= entryStream
.read(buffer
)) != -1) {
206 file
.write(buffer
, 0, bytesRead
);
209 System
.out
.println(je
.getName() + " extracted.");
224 class BasePkgNotInstalled
extends Exception
{
225 final static long serialVersionUID
= 0;
228 class VerNotEqual
extends Exception
{
229 final static long serialVersionUID
= 0;
232 class GuidNotEqual
extends Exception
{
233 final static long serialVersionUID
= 0;
236 class SameAll
extends Exception
{
237 final static long serialVersionUID
= 0;