KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > installer > ConsoleInstall


1 /*
2  * ConsoleInstall.java
3  *
4  * Originally written by Slava Pestov for the jEdit installer project. This work
5  * has been placed into the public domain. You may use this work in any way and
6  * for any purpose you wish.
7  *
8  * THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, NOT EVEN THE
9  * IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR OF THIS SOFTWARE, ASSUMES
10  * _NO_ RESPONSIBILITY FOR ANY CONSEQUENCE RESULTING FROM THE USE, MODIFICATION,
11  * OR REDISTRIBUTION OF THIS SOFTWARE.
12  */

13
14 package installer;
15
16 import java.io.*;
17 import java.util.Vector JavaDoc;
18
19 /*
20  * Performs text-only installation.
21  */

22 public class ConsoleInstall
23 {
24     public ConsoleInstall()
25     {
26         installer = new Install();
27
28         String JavaDoc appName = installer.getProperty("app.name");
29         String JavaDoc appVersion = installer.getProperty("app.version");
30
31         BufferedReader in = new BufferedReader(new InputStreamReader(
32             System.in));
33
34         System.out.println("*** " + appName + " " + appVersion + " installer");
35
36         OperatingSystem os = OperatingSystem.getOperatingSystem();
37
38         String JavaDoc installDir = os.getInstallDirectory(appName,appVersion);
39
40         System.out.print("Installation directory: [" + installDir + "] ");
41         System.out.flush();
42
43         String JavaDoc _installDir = readLine(in);
44         if(_installDir.length() != 0)
45             installDir = _installDir;
46
47         OperatingSystem.OSTask[] osTasks = os.getOSTasks(installer);
48
49         for(int i = 0; i < osTasks.length; i++)
50         {
51             OperatingSystem.OSTask osTask = osTasks[i];
52             String JavaDoc label = osTask.getLabel();
53             // label == null means no configurable options
54
if(label != null)
55             {
56                 String JavaDoc dir = osTask.getDirectory();
57                 System.out.print(label + " [" + dir + "] ");
58                 System.out.flush();
59
60                 dir = readLine(in);
61                 osTask.setEnabled(true);
62                 if(dir.length() != 0)
63                 {
64                     if(dir.equals("off"))
65                         osTask.setEnabled(false);
66                     else
67                         osTask.setDirectory(dir);
68                 }
69             }
70         }
71
72         int compCount = installer.getIntegerProperty("comp.count");
73         Vector JavaDoc components = new Vector JavaDoc(compCount);
74
75         System.out.println("*** Program components to install");
76         for(int i = 0; i < compCount; i++)
77         {
78             String JavaDoc fileset = installer.getProperty("comp." + i + ".fileset");
79
80             String JavaDoc osDep = installer.getProperty("comp." + i + ".os");
81             if(osDep != null)
82             {
83                 if(!os.getClass().getName().endsWith(osDep))
84                 {
85                     continue;
86                 }
87             }
88
89             System.out.print("Install "
90                 + installer.getProperty("comp." + i + ".name")
91                 + " ("
92                 + installer.getProperty("comp." + i + ".disk-size")
93                 + "Kb) [Y/n]? ");
94
95             String JavaDoc line = readLine(in);
96             if(line.length() == 0 || line.charAt(0) == 'y'
97                 || line.charAt(0) == 'Y')
98                 components.addElement(fileset);
99         }
100
101         System.out.println("*** Starting installation...");
102         ConsoleProgress progress = new ConsoleProgress();
103         InstallThread thread = new InstallThread(
104             installer,progress,installDir,osTasks,
105             0 /* XXX */,components);
106         thread.start();
107     }
108
109     // private members
110
private Install installer;
111
112     private String JavaDoc readLine(BufferedReader in)
113     {
114         try
115         {
116             String JavaDoc line = in.readLine();
117             if(line == null)
118             {
119                 System.err.println("\nEOF in input!");
120                 System.exit(1);
121                 // can't happen
122
throw new InternalError JavaDoc();
123             }
124             return line;
125         }
126         catch(IOException io)
127         {
128             System.err.println("\nI/O error: " + io);
129             System.exit(1);
130             // can't happen
131
throw new InternalError JavaDoc();
132         }
133     }
134 }
135
Popular Tags