PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  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. */
  13. package installer;
  14. import java.io.*;
  15. import java.util.Vector;
  16. /*
  17. * The thread that performs installation.
  18. */
  19. public class InstallThread extends Thread
  20. {
  21. public InstallThread(Install installer, Progress progress,
  22. String installDir, OperatingSystem.OSTask[] osTasks,
  23. int size, Vector components)
  24. {
  25. super("Install thread");
  26. this.installer = installer;
  27. this.progress = progress;
  28. this.installDir = installDir;
  29. this.osTasks = osTasks;
  30. this.size = size;
  31. this.components = components;
  32. }
  33. public void run()
  34. {
  35. progress.setMaximum(size * 1024);
  36. try
  37. {
  38. // install user-selected packages
  39. for(int i = 0; i < components.size(); i++)
  40. {
  41. String comp = (String)components.elementAt(i);
  42. System.err.println("Installing " + comp);
  43. installComponent(comp);
  44. }
  45. // do operating system specific stuff (creating startup
  46. // scripts, installing man pages, etc.)
  47. for(int i = 0; i < osTasks.length; i++)
  48. {
  49. System.err.println("Performing task " +
  50. osTasks[i].getName());
  51. osTasks[i].perform(installDir,components);
  52. }
  53. }
  54. catch(FileNotFoundException fnf)
  55. {
  56. progress.error("The installer could not create the "
  57. + "destination directory.\n"
  58. + "Maybe you do not have write permission?");
  59. return;
  60. }
  61. catch(IOException io)
  62. {
  63. progress.error(io.toString());
  64. return;
  65. }
  66. progress.done();
  67. }
  68. // private members
  69. private Install installer;
  70. private Progress progress;
  71. private String installDir;
  72. private OperatingSystem.OSTask[] osTasks;
  73. private int size;
  74. private Vector components;
  75. private void installComponent(String name) throws IOException
  76. {
  77. InputStream in = new BufferedInputStream(
  78. getClass().getResourceAsStream(name + ".tar.bz2"));
  79. // skip header bytes
  80. // maybe should check if they're valid or not?
  81. in.read();
  82. in.read();
  83. TarInputStream tarInput = new TarInputStream(
  84. new CBZip2InputStream(in));
  85. TarEntry entry;
  86. while((entry = tarInput.getNextEntry()) != null)
  87. {
  88. if(entry.isDirectory())
  89. continue;
  90. String fileName = entry.getName();
  91. //System.err.println(fileName);
  92. String outfile = installDir + File.separatorChar
  93. + fileName.replace('/',File.separatorChar);
  94. installer.copy(tarInput,outfile,progress);
  95. }
  96. tarInput.close();
  97. }
  98. }