KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > installer > MultiVolumeInstaller


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/ http://developer.berlios.de/projects/izpack/
5  *
6  * Copyright 2007 Dennis Reil
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software distributed under the License
14  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
15  * or implied. See the License for the specific language governing permissions and limitations under
16  * the License.
17  */

18 package com.izforge.izpack.installer;
19
20 import java.io.File JavaDoc;
21 import java.lang.reflect.Method JavaDoc;
22
23 import com.izforge.izpack.uninstaller.SelfModifier;
24 import com.izforge.izpack.util.Debug;
25
26 /**
27  * Main class, for starting the installer if it was build to support more than one volume.
28  *
29  * @author Dennis Reil, <Dennis.Reil@reddot.de>
30  *
31  */

32 public class MultiVolumeInstaller
33 {
34
35     // where is the installer looking for media files
36
protected static String JavaDoc mediadirectory;
37
38     /**
39      * @param args
40      */

41     public static void main(String JavaDoc[] args)
42     {
43         // default is to look in the current directory
44
MultiVolumeInstaller.setMediadirectory(new File JavaDoc(".").getParent());
45         if ((args.length > 0) && ("-direct".equals(args[0])))
46         {
47             String JavaDoc[] newargs;
48             if (args.length > 1)
49             {
50                 // cut out the direct parameter
51
newargs = new String JavaDoc[args.length - 1];
52                 System.arraycopy(args, 1, newargs, 0, args.length - 1);
53             }
54             else
55             {
56                 // set arguments to empty string array
57
newargs = new String JavaDoc[0];
58             }
59             MultiVolumeInstaller.install(newargs);
60         }
61         else
62         {
63             try
64             {
65                 Class JavaDoc clazz = MultiVolumeInstaller.class;
66                 Method JavaDoc target = clazz.getMethod("install", new Class JavaDoc[] { String JavaDoc[].class});
67                 String JavaDoc[] newargs = new String JavaDoc[args.length + 2];
68
69                 System.arraycopy(args, 0, newargs, 2, args.length);
70                 // try to find the directory, where the jar file is located, this class was loaded
71
// from
72
newargs[0] = "-mediadir";
73                 newargs[1] = SelfModifier.findJarFile(clazz).getParent();
74                 System.out.println("Setting mediadir: " + newargs[1]);
75                 MultiVolumeInstaller.setMediadirectory(SelfModifier.findJarFile(clazz).getParent());
76                 new SelfModifier(target).invoke(newargs);
77             }
78             catch (Exception JavaDoc e)
79             {
80                 Debug.trace(e);
81             }
82         }
83     }
84
85     public static String JavaDoc getMediadirectory()
86     {
87         return MultiVolumeInstaller.mediadirectory;
88     }
89
90     public static void setMediadirectory(String JavaDoc mediadirectory)
91     {
92         MultiVolumeInstaller.mediadirectory = mediadirectory;
93     }
94
95     public static void install(String JavaDoc[] args)
96     {
97         if ((args.length >= 2) && ("-mediadir".equals(args[0])))
98         {
99             // mediadir option given
100
MultiVolumeInstaller.setMediadirectory(args[1]);
101             if (args.length > 2)
102             {
103                 // cut out this option
104
String JavaDoc[] newargs = new String JavaDoc[args.length - 2];
105                 System.arraycopy(args, 2, newargs, 0, args.length - 2);
106                 args = newargs;
107             }
108             else
109             {
110                 // put in an empty string array
111
args = new String JavaDoc[0];
112             }
113         }
114         // just call the izpack installer
115
Installer.main(args);
116     }
117 }
118
Popular Tags