PageRenderTime 53ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/src/com/eteks/sweethome3d/SweetHome3DBootstrap.java

https://github.com/arturo-mayorga/sh3d
Java | 166 lines | 130 code | 6 blank | 30 comment | 20 complexity | 894b5a43534f727f58fc6fd129b7c96e MD5 | raw file
  1. /*
  2. * SweetHome3DBootstrap.java 2 sept. 07
  3. *
  4. * Sweet Home 3D, Copyright (c) 2007 Emmanuel PUYBARET / eTeks <info@eteks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. package com.eteks.sweethome3d;
  21. import java.io.File;
  22. import java.lang.reflect.Array;
  23. import java.lang.reflect.InvocationTargetException;
  24. import java.lang.reflect.Method;
  25. import java.net.MalformedURLException;
  26. import java.util.ArrayList;
  27. import java.util.Arrays;
  28. import java.util.List;
  29. import java.util.Locale;
  30. import javax.swing.JOptionPane;
  31. import com.eteks.sweethome3d.tools.ExtensionsClassLoader;
  32. /**
  33. * This bootstrap class loads Sweet Home 3D application classes from jars in classpath
  34. * or from extension jars stored as resources.
  35. * @author Emmanuel Puybaret
  36. */
  37. public class SweetHome3DBootstrap {
  38. public static void main(String [] args) throws MalformedURLException, IllegalAccessException,
  39. InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
  40. Class sweetHome3DBootstrapClass = SweetHome3DBootstrap.class;
  41. List<String> extensionJarsAndDlls = new ArrayList<String>(Arrays.asList(new String [] {
  42. "iText-2.1.7.jar", // Jars included in Sweet Home 3D executable jar file
  43. "freehep-vectorgraphics-svg-2.1.1b.jar",
  44. "Loader3DS1_2u.jar",
  45. "sunflow-0.07.3i.jar",
  46. "jmf.jar",
  47. "batik-svgpathparser-1.7.jar",
  48. "jnlp.jar"}));
  49. String operatingSystemName = System.getProperty("os.name");
  50. String javaVersion = System.getProperty("java.version");
  51. String java7Prefix = "1.7.0_";
  52. if (operatingSystemName.startsWith("Mac OS X")
  53. && javaVersion.startsWith("1.6")
  54. && System.getProperty("com.eteks.sweethome3d.deploymentInformation", "").startsWith("Java Web Start")) {
  55. // Refuse to let Sweet Home 3D run under Mac OS X with Java Web Start 6
  56. String message = Locale.getDefault().getLanguage().equals(Locale.FRENCH.getLanguage())
  57. ? "Sweet Home 3D ne peut pas fonctionner avec Java\n"
  58. + "Web Start 6 sous Mac OS X de façon fiable.\n"
  59. + "Merci de télécharger le programme d'installation depuis\n"
  60. + "http://www.sweethome3d.com/fr/download.jsp"
  61. : "Sweet Home 3D can't reliably run with Java Web Start 6\n"
  62. + "under Mac OS X.\n"
  63. + "Please download the installer version from\n"
  64. + "http://www.sweethome3d.com/download.jsp";
  65. JOptionPane.showMessageDialog(null, message);
  66. System.exit(1);
  67. } else if (!operatingSystemName.startsWith("Mac OS X")
  68. || javaVersion.startsWith("1.5")
  69. || javaVersion.startsWith("1.6")) {
  70. extensionJarsAndDlls.addAll(Arrays.asList(new String [] {
  71. "j3dcore.jar", // Main Java 3D jars
  72. "vecmath.jar",
  73. "j3dutils.jar",
  74. "macosx/gluegen-rt.jar", // Mac OS X jars and DLLs for Java 5 or 6
  75. "macosx/jogl.jar",
  76. "macosx/libgluegen-rt.jnilib",
  77. "macosx/libjogl.jnilib",
  78. "macosx/libjogl_awt.jnilib",
  79. "macosx/libjogl_cg.jnilib"}));
  80. } else if (javaVersion.startsWith(java7Prefix)
  81. && javaVersion.length() >= java7Prefix.length() + 1
  82. && Character.isDigit(javaVersion.charAt(java7Prefix.length()))
  83. && (javaVersion.length() >= java7Prefix.length() + 2 // Test version on 2 digits
  84. && Character.isDigit(javaVersion.charAt(java7Prefix.length() + 1))
  85. && Integer.parseInt(javaVersion.substring(java7Prefix.length(), java7Prefix.length() + 2)) < 40
  86. || javaVersion.length() == java7Prefix.length() + 1 // Test whether version is on 1 digit (i.e. < 40)
  87. || !Character.isDigit(javaVersion.charAt(java7Prefix.length() + 1)))) {
  88. // Refuse to let Sweet Home 3D run under Mac OS X with Java 7 before version 7u40
  89. String message = Locale.getDefault().getLanguage().equals(Locale.FRENCH.getLanguage())
  90. ? "Sous Mac OS X, Sweet Home 3D ne peut fonctionner avec Java 7\n"
  91. + "qu'à partir de la version Java 7u40. Merci de mettre à jour\n"
  92. + "votre version de Java ou de lancer Sweet Home 3D sous Java 6."
  93. : "Under Mac OS X, Sweet Home 3D can run with Java 7 only\n"
  94. + "from version Java 7u40. Please, update you Java version\n"
  95. + "or run Sweet Home 3D under Java 6.";
  96. JOptionPane.showMessageDialog(null, message);
  97. System.exit(1);
  98. } else { // Java >= 1.7.0_40
  99. extensionJarsAndDlls.addAll(Arrays.asList(new String [] {
  100. "macosx/java3d-1.6/j3dcore.jar", // Mac OS X Java 3D 1.6 jars and DLLs
  101. "macosx/java3d-1.6/vecmath.jar",
  102. "macosx/java3d-1.6/j3dutils.jar",
  103. "macosx/java3d-1.6/gluegen.jar",
  104. "macosx/java3d-1.6/jogl-java3d.jar",
  105. "macosx/java3d-1.6/libgluegen-rt.jnilib",
  106. "macosx/java3d-1.6/libjogl_desktop.jnilib",
  107. "macosx/java3d-1.6/libnativewindow_awt.jnilib",
  108. "macosx/java3d-1.6/libnativewindow_macosx.jnilib"}));
  109. // Disable JOGL library loader
  110. System.setProperty("jogamp.gluegen.UseTempJarCache", "false");
  111. }
  112. if ("64".equals(System.getProperty("sun.arch.data.model"))) {
  113. extensionJarsAndDlls.add("linux/x64/libj3dcore-ogl.so"); // Linux 64 bits DLLs
  114. extensionJarsAndDlls.add("windows/x64/j3dcore-ogl.dll"); // Windows 64 bits DLLs
  115. } else {
  116. extensionJarsAndDlls.addAll(Arrays.asList(new String [] {
  117. "linux/i386/libj3dcore-ogl.so", // Linux 32 bits DLLs
  118. "linux/i386/libj3dcore-ogl-cg.so",
  119. "windows/i386/j3dcore-d3d.dll", // Windows 32 bits DLLs
  120. "windows/i386/j3dcore-ogl.dll",
  121. "windows/i386/j3dcore-ogl-cg.dll",
  122. "windows/i386/j3dcore-ogl-chk.dll"}));
  123. }
  124. String [] applicationPackages = {
  125. "com.eteks.sweethome3d",
  126. "javax.media",
  127. "javax.vecmath",
  128. "com.sun.j3d",
  129. "com.sun.opengl",
  130. "com.sun.gluegen.runtime",
  131. "com.jogamp",
  132. "jogamp",
  133. "javax.media.opengl",
  134. "javax.media.nativewindow",
  135. "com.sun.media",
  136. "com.ibm.media",
  137. "jmpapps.util",
  138. "com.microcrowd.loader.java3d",
  139. "org.sunflow",
  140. "org.apache.batik"};
  141. String applicationClassName = "com.eteks.sweethome3d.SweetHome3D";
  142. ClassLoader java3DClassLoader = operatingSystemName.startsWith("Windows")
  143. ? new ExtensionsClassLoader(
  144. sweetHome3DBootstrapClass.getClassLoader(),
  145. sweetHome3DBootstrapClass.getProtectionDomain(),
  146. extensionJarsAndDlls.toArray(new String [extensionJarsAndDlls.size()]), null, applicationPackages,
  147. // Use cache under Windows because temporary files tagged as deleteOnExit can't
  148. // be deleted if they are still opened when program exits
  149. new File(System.getProperty("java.io.tmpdir")), applicationClassName + "-cache-")
  150. : new ExtensionsClassLoader(
  151. sweetHome3DBootstrapClass.getClassLoader(),
  152. sweetHome3DBootstrapClass.getProtectionDomain(),
  153. extensionJarsAndDlls.toArray(new String [extensionJarsAndDlls.size()]), applicationPackages);
  154. Class applicationClass = java3DClassLoader.loadClass(applicationClassName);
  155. Method applicationClassMain =
  156. applicationClass.getMethod("main", Array.newInstance(String.class, 0).getClass());
  157. // Call application class main method with reflection
  158. applicationClassMain.invoke(null, new Object [] {args});
  159. }
  160. }