/jEdit/tags/jedit-4-3-pre5/installer/InstallThread.java
Java | 109 lines | 76 code | 11 blank | 22 comment | 4 complexity | a7504fcb6074d649d1a5bdb95dfecf40 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- /*
- * InstallThread.java
- *
- * Originally written by Slava Pestov for the jEdit installer project. This work
- * has been placed into the public domain. You may use this work in any way and
- * for any purpose you wish.
- *
- * THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, NOT EVEN THE
- * IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR OF THIS SOFTWARE, ASSUMES
- * _NO_ RESPONSIBILITY FOR ANY CONSEQUENCE RESULTING FROM THE USE, MODIFICATION,
- * OR REDISTRIBUTION OF THIS SOFTWARE.
- */
- package installer;
- import java.io.*;
- import java.util.Vector;
- /*
- * The thread that performs installation.
- */
- public class InstallThread extends Thread
- {
- public InstallThread(Install installer, Progress progress,
- String installDir, OperatingSystem.OSTask[] osTasks,
- int size, Vector components)
- {
- super("Install thread");
- this.installer = installer;
- this.progress = progress;
- this.installDir = installDir;
- this.osTasks = osTasks;
- this.size = size;
- this.components = components;
- }
- public void run()
- {
- progress.setMaximum(size * 1024);
- try
- {
- // install user-selected packages
- for(int i = 0; i < components.size(); i++)
- {
- String comp = (String)components.elementAt(i);
- System.err.println("Installing " + comp);
- installComponent(comp);
- }
- // do operating system specific stuff (creating startup
- // scripts, installing man pages, etc.)
- for(int i = 0; i < osTasks.length; i++)
- {
- System.err.println("Performing task " +
- osTasks[i].getName());
- osTasks[i].perform(installDir,components);
- }
- }
- catch(FileNotFoundException fnf)
- {
- progress.error("The installer could not create the "
- + "destination directory.\n"
- + "Maybe you do not have write permission?");
- return;
- }
- catch(IOException io)
- {
- progress.error(io.toString());
- return;
- }
- progress.done();
- }
- // private members
- private Install installer;
- private Progress progress;
- private String installDir;
- private OperatingSystem.OSTask[] osTasks;
- private int size;
- private Vector components;
- private void installComponent(String name) throws IOException
- {
- InputStream in = new BufferedInputStream(
- getClass().getResourceAsStream(name + ".tar.bz2"));
- // skip header bytes
- // maybe should check if they're valid or not?
- in.read();
- in.read();
- TarInputStream tarInput = new TarInputStream(
- new CBZip2InputStream(in));
- TarEntry entry;
- while((entry = tarInput.getNextEntry()) != null)
- {
- if(entry.isDirectory())
- continue;
- String fileName = entry.getName();
- //System.err.println(fileName);
- String outfile = installDir + File.separatorChar
- + fileName.replace('/',File.separatorChar);
- installer.copy(tarInput,outfile,progress);
- }
- tarInput.close();
- }
- }