PageRenderTime 84ms CodeModel.GetById 76ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/installer/ConsoleInstall.java

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