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