PageRenderTime 75ms CodeModel.GetById 65ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/installer/InstallThread.java

#
Java | 109 lines | 76 code | 11 blank | 22 comment | 4 complexity | a7504fcb6074d649d1a5bdb95dfecf40 MD5 | raw file
  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 */
 13package installer;
 14
 15import java.io.*;
 16import java.util.Vector;
 17
 18/*
 19 * The thread that performs installation.
 20 */
 21public class InstallThread extends Thread
 22{
 23	public InstallThread(Install installer, Progress progress,
 24		String installDir, OperatingSystem.OSTask[] osTasks,
 25		int size, Vector 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 comp = (String)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 installDir;
 80	private OperatingSystem.OSTask[] osTasks;
 81	private int size;
 82	private Vector components;
 83
 84	private void installComponent(String 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 fileName = entry.getName();
101			//System.err.println(fileName);
102			String outfile = installDir + File.separatorChar
103				+ fileName.replace('/',File.separatorChar);
104			installer.copy(tarInput,outfile,progress);
105		}
106
107		tarInput.close();
108	}
109}