KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > installer > InstallThread


1 /*
2  * InstallThread.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 package installer;
14
15 import java.io.*;
16 import java.util.Vector JavaDoc;
17
18 /*
19  * The thread that performs installation.
20  */

21 public class InstallThread extends Thread JavaDoc
22 {
23     public InstallThread(Install installer, Progress progress,
24         String JavaDoc installDir, OperatingSystem.OSTask[] osTasks,
25         int size, Vector JavaDoc components)
26     {
27         super("Install thread");
28
29         this.installer = installer;
30         this.progress = progress;
31         this.installDir = installDir;
32         this.osTasks = osTasks;
33         this.size = size;
34         this.components = components;
35     }
36
37     public void run()
38     {
39         progress.setMaximum(size * 1024);
40
41         try
42         {
43             // install user-selected packages
44
for(int i = 0; i < components.size(); i++)
45             {
46                 String JavaDoc comp = (String JavaDoc)components.elementAt(i);
47                 System.err.println("Installing " + comp);
48                 installComponent(comp);
49             }
50
51             // do operating system specific stuff (creating startup
52
// scripts, installing man pages, etc.)
53
for(int i = 0; i < osTasks.length; i++)
54             {
55                 System.err.println("Performing task " +
56                     osTasks[i].getName());
57                 osTasks[i].perform(installDir,components);
58             }
59         }
60         catch(FileNotFoundException fnf)
61         {
62             progress.error("The installer could not create the "
63                 + "destination directory.\n"
64                 + "Maybe you do not have write permission?");
65             return;
66         }
67         catch(IOException io)
68         {
69             progress.error(io.toString());
70             return;
71         }
72
73         progress.done();
74     }
75
76     // private members
77
private Install installer;
78     private Progress progress;
79     private String JavaDoc installDir;
80     private OperatingSystem.OSTask[] osTasks;
81     private int size;
82     private Vector JavaDoc components;
83
84     private void installComponent(String JavaDoc name) throws IOException
85     {
86         InputStream in = new BufferedInputStream(
87             getClass().getResourceAsStream(name + ".tar.bz2"));
88         // skip header bytes
89
// maybe should check if they're valid or not?
90
in.read();
91         in.read();
92
93         TarInputStream tarInput = new TarInputStream(
94             new CBZip2InputStream(in));
95         TarEntry entry;
96         while((entry = tarInput.getNextEntry()) != null)
97         {
98             if(entry.isDirectory())
99                 continue;
100             String JavaDoc fileName = entry.getName();
101             //System.err.println(fileName);
102
String JavaDoc outfile = installDir + File.separatorChar
103                 + fileName.replace('/',File.separatorChar);
104             installer.copy(tarInput,outfile,progress);
105         }
106
107         tarInput.close();
108     }
109 }
110
Popular Tags