PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/installer/ConsoleInstall.java

#
Java | 134 lines | 94 code | 21 blank | 19 comment | 20 complexity | 374dabb578ff3130dbab45d15f0cb354 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. OperatingSystem.OSTask[] osTasks = os.getOSTasks(installer);
  37. for(int i = 0; i < osTasks.length; i++)
  38. {
  39. OperatingSystem.OSTask osTask = osTasks[i];
  40. String label = osTask.getLabel();
  41. // label == null means no configurable options
  42. if(label != null)
  43. {
  44. String dir = osTask.getDirectory();
  45. System.out.print(label + " [" + dir + "] ");
  46. System.out.flush();
  47. dir = readLine(in);
  48. osTask.setEnabled(true);
  49. if(dir.length() != 0)
  50. {
  51. if(dir.equals("off"))
  52. osTask.setEnabled(false);
  53. else
  54. osTask.setDirectory(dir);
  55. }
  56. }
  57. }
  58. int compCount = installer.getIntegerProperty("comp.count");
  59. Vector components = new Vector(compCount);
  60. System.out.println("*** Program components to install");
  61. for(int i = 0; i < compCount; i++)
  62. {
  63. String fileset = installer.getProperty("comp." + i + ".fileset");
  64. String osDep = installer.getProperty("comp." + i + ".os");
  65. if(osDep != null)
  66. {
  67. if(!os.getClass().getName().endsWith(osDep))
  68. {
  69. continue;
  70. }
  71. }
  72. System.out.print("Install "
  73. + installer.getProperty("comp." + i + ".name")
  74. + " ("
  75. + installer.getProperty("comp." + i + ".disk-size")
  76. + "Kb) [Y/n]? ");
  77. String line = readLine(in);
  78. if(line.length() == 0 || line.charAt(0) == 'y'
  79. || line.charAt(0) == 'Y')
  80. components.addElement(fileset);
  81. }
  82. System.out.println("*** Starting installation...");
  83. ConsoleProgress progress = new ConsoleProgress();
  84. InstallThread thread = new InstallThread(
  85. installer,progress,installDir,osTasks,
  86. 0 /* XXX */,components);
  87. thread.start();
  88. }
  89. // private members
  90. private Install installer;
  91. private String readLine(BufferedReader in)
  92. {
  93. try
  94. {
  95. String line = in.readLine();
  96. if(line == null)
  97. {
  98. System.err.println("\nEOF in input!");
  99. System.exit(1);
  100. // can't happen
  101. throw new InternalError();
  102. }
  103. return line;
  104. }
  105. catch(IOException io)
  106. {
  107. System.err.println("\nI/O error: " + io);
  108. System.exit(1);
  109. // can't happen
  110. throw new InternalError();
  111. }
  112. }
  113. }