PageRenderTime 3326ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/fr.univartois.cril.xtext.als.ui/src/fr/univartois/cril/xtext/ui/activator/AlsActivator.java

http://alloy4eclipse.googlecode.com/
Java | 340 lines | 262 code | 44 blank | 34 comment | 8 complexity | fe6ea46d13592652a44364da02717e98 MD5 | raw file
  1. /*
  2. * generated by Xtext
  3. */
  4. package fr.univartois.cril.xtext.ui.activator;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7. import org.apache.log4j.Logger;
  8. import org.eclipse.core.runtime.IStatus;
  9. import org.eclipse.core.runtime.Plugin;
  10. import org.eclipse.core.runtime.Status;
  11. import org.eclipse.jface.preference.IPreferenceStore;
  12. import org.eclipse.ui.plugin.AbstractUIPlugin;
  13. import org.osgi.framework.BundleContext;
  14. import com.google.inject.Guice;
  15. import com.google.inject.Injector;
  16. import com.google.inject.Module;
  17. import com.google.inject.util.Modules;
  18. import edu.mit.csail.sdg.alloy4.Util;
  19. import fr.univartois.cril.xtext.alloyplugin.Helper;
  20. import fr.univartois.cril.xtext.preferences.PreferenceInitializer;
  21. /**
  22. * Generated
  23. */
  24. public class AlsActivator extends AbstractUIPlugin {
  25. /**
  26. * The plug-in ID.
  27. */
  28. public static final String PLUGIN_ID = "fr.univartois.cril.xtext.alloyplugin";
  29. /***/
  30. public static final String ALS_PARTITIONING = "__pos_als_partitioning";
  31. //
  32. public static final String COMMAND_VIEW_ID = "fr.univartois.cril.alloyplugin.launch.views.AlloyCommandView";
  33. /**
  34. * The system-specific file separator (forward-slash on UNIX, back-slash on
  35. * Windows, etc.)
  36. */
  37. public static final String FILE_SEPARATOR = System
  38. .getProperty("file.separator");
  39. private Map<String, Injector> injectors = new HashMap<String, Injector>();
  40. private static AlsActivator INSTANCE;
  41. private BundleContext contexte;
  42. public AlsActivator() {
  43. super();
  44. INSTANCE = this;
  45. copyFromJAR();
  46. }
  47. public Injector getInjector(String languageName) {
  48. return injectors.get(languageName);
  49. }
  50. @Override
  51. public void start(BundleContext context) throws Exception {
  52. super.start(context);
  53. contexte = context;
  54. PreferenceInitializer init = new PreferenceInitializer();
  55. init.initializeDefaultPreferences();
  56. try {
  57. injectors
  58. .put("fr.univartois.cril.xtext.Als",
  59. Guice.createInjector(Modules
  60. .override(
  61. Modules.override(
  62. getRuntimeModule("fr.univartois.cril.xtext.Als"))
  63. .with(getUiModule("fr.univartois.cril.xtext.Als")))
  64. .with(getSharedStateModule())));
  65. } catch (Exception e) {
  66. Logger.getLogger(getClass()).error(e.getMessage(), e);
  67. throw e;
  68. }
  69. }
  70. public void stop(BundleContext context) throws Exception {
  71. INSTANCE = null;
  72. super.stop(context);
  73. }
  74. public static AlsActivator getInstance() {
  75. return INSTANCE;
  76. }
  77. protected Module getRuntimeModule(String grammar) {
  78. if ("fr.univartois.cril.xtext.Als".equals(grammar)) {
  79. return new fr.univartois.cril.xtext.AlsRuntimeModule();
  80. }
  81. throw new IllegalArgumentException(grammar);
  82. }
  83. protected Module getUiModule(String grammar) {
  84. if ("fr.univartois.cril.xtext.Als".equals(grammar)) {
  85. return new fr.univartois.cril.xtext.ui.AlsUiModule(this);
  86. }
  87. throw new IllegalArgumentException(grammar);
  88. }
  89. protected Module getSharedStateModule() {
  90. return new org.eclipse.xtext.ui.shared.SharedStateModule();
  91. }
  92. @Override
  93. public IPreferenceStore getPreferenceStore() {
  94. return super.getPreferenceStore();
  95. }
  96. public BundleContext getBundleContext() {
  97. return this.contexte;
  98. }
  99. private void copyFromJAR() {
  100. // Compute the appropriate platform
  101. String os = System.getProperty("os.name").toLowerCase()
  102. .replace(' ', '-');
  103. if (os.startsWith("mac-"))
  104. os = "mac";
  105. else if (os.startsWith("windows-"))
  106. os = "windows";
  107. String arch = System.getProperty("os.arch").toLowerCase()
  108. .replace(' ', '-');
  109. if (arch.equals("powerpc"))
  110. arch = "ppc-" + os;
  111. else
  112. arch = "x86-" + os;
  113. // Find out the appropriate Alloy directory
  114. final String platformBinary = Helper.alloyHome() + FILE_SEPARATOR
  115. + "binary";
  116. // Copy the platform-dependent binaries
  117. Util.copy(true, false, platformBinary, arch + "/libminisat.so", arch
  118. + "/libminisat.jnilib", arch + "/libminisatprover.so", arch
  119. + "/libminisatprover.jnilib", arch + "/libzchaff.so", arch
  120. + "/libzchaff.jnilib", arch + "/minisat1", arch + "/berkmin",
  121. arch + "/dotbin");
  122. Util.copy(false, false, platformBinary, arch + "/minisat.dll", arch
  123. + "/minisatprover.dll", arch + "/zchaff.dll", arch
  124. + "/minisat1.exe", arch + "/berkmin.exe", arch + "/dotbin.exe",
  125. arch + "/jpeg.dll", arch + "/libexpat.dll", arch
  126. + "/libexpatw.dll", arch + "/zlib1.dll", arch
  127. + "/z.dll", arch + "/freetype6.dll", arch + "/png.dll");
  128. // Copy the model files
  129. Util.copy(
  130. false,
  131. true,
  132. Helper.alloyHome(),
  133. "models/book/appendixA/addressBook1.als",
  134. "models/book/appendixA/addressBook2.als",
  135. "models/book/appendixA/barbers.als",
  136. "models/book/appendixA/closure.als",
  137. "models/book/appendixA/distribution.als",
  138. "models/book/appendixA/phones.als",
  139. "models/book/appendixA/prison.als",
  140. "models/book/appendixA/properties.als",
  141. "models/book/appendixA/ring.als",
  142. "models/book/appendixA/spanning.als",
  143. "models/book/appendixA/tree.als",
  144. "models/book/appendixA/tube.als",
  145. "models/book/appendixA/undirected.als",
  146. "models/book/appendixE/hotel.thm",
  147. "models/book/appendixE/p300-hotel.als",
  148. "models/book/appendixE/p303-hotel.als",
  149. "models/book/appendixE/p306-hotel.als",
  150. "models/book/chapter2/addressBook1a.als",
  151. "models/book/chapter2/addressBook1b.als",
  152. "models/book/chapter2/addressBook1c.als",
  153. "models/book/chapter2/addressBook1d.als",
  154. "models/book/chapter2/addressBook1e.als",
  155. "models/book/chapter2/addressBook1f.als",
  156. "models/book/chapter2/addressBook1g.als",
  157. "models/book/chapter2/addressBook1h.als",
  158. "models/book/chapter2/addressBook2a.als",
  159. "models/book/chapter2/addressBook2b.als",
  160. "models/book/chapter2/addressBook2c.als",
  161. "models/book/chapter2/addressBook2d.als",
  162. "models/book/chapter2/addressBook2e.als",
  163. "models/book/chapter2/addressBook3a.als",
  164. "models/book/chapter2/addressBook3b.als",
  165. "models/book/chapter2/addressBook3c.als",
  166. "models/book/chapter2/addressBook3d.als",
  167. "models/book/chapter2/theme.thm",
  168. "models/book/chapter4/filesystem.als",
  169. "models/book/chapter4/grandpa1.als",
  170. "models/book/chapter4/grandpa2.als",
  171. "models/book/chapter4/grandpa3.als",
  172. "models/book/chapter4/lights.als",
  173. "models/book/chapter5/addressBook.als",
  174. "models/book/chapter5/lists.als",
  175. "models/book/chapter5/sets1.als",
  176. "models/book/chapter5/sets2.als",
  177. "models/book/chapter6/hotel.thm",
  178. "models/book/chapter6/hotel1.als",
  179. "models/book/chapter6/hotel2.als",
  180. "models/book/chapter6/hotel3.als",
  181. "models/book/chapter6/hotel4.als",
  182. "models/book/chapter6/mediaAssets.als",
  183. "models/book/chapter6/memory/abstractMemory.als",
  184. "models/book/chapter6/memory/cacheMemory.als",
  185. /*
  186. * "models/book/chapter6/memory/checkCache.als",
  187. * "models/book/chapter6/memory/checkFixedSize.als",
  188. */
  189. "models/book/chapter6/memory/fixedSizeMemory.als", /*
  190. * "models/book/chapter6/memory/fixedSizeMemory_H.als"
  191. * ,
  192. */
  193. "models/book/chapter6/ringElection.thm",
  194. "models/book/chapter6/ringElection1.als",
  195. "models/book/chapter6/ringElection2.als",
  196. "models/examples/algorithms/dijkstra.als",
  197. "models/examples/algorithms/dijkstra.thm",
  198. "models/examples/algorithms/messaging.als",
  199. "models/examples/algorithms/messaging.thm",
  200. "models/examples/algorithms/opt_spantree.als",
  201. "models/examples/algorithms/opt_spantree.thm",
  202. "models/examples/algorithms/peterson.als",
  203. /* "models/examples/algorithms/ringlead.als", */"models/examples/algorithms/ringlead.thm",
  204. "models/examples/algorithms/s_ringlead.als",
  205. "models/examples/algorithms/stable_mutex_ring.als",
  206. "models/examples/algorithms/stable_mutex_ring.thm",
  207. "models/examples/algorithms/stable_orient_ring.als",
  208. "models/examples/algorithms/stable_orient_ring.thm",
  209. "models/examples/algorithms/stable_ringlead.als",
  210. "models/examples/algorithms/stable_ringlead.thm",
  211. "models/examples/case_studies/INSLabel.als",
  212. "models/examples/case_studies/chord.als",
  213. "models/examples/case_studies/chord2.als",
  214. "models/examples/case_studies/chordbugmodel.als",
  215. "models/examples/case_studies/com.als",
  216. "models/examples/case_studies/firewire.als",
  217. "models/examples/case_studies/firewire.thm",
  218. "models/examples/case_studies/ins.als",
  219. "models/examples/case_studies/iolus.als",
  220. "models/examples/case_studies/sync.als",
  221. "models/examples/case_studies/syncimpl.als",
  222. "models/examples/puzzles/farmer.als",
  223. "models/examples/puzzles/farmer.thm",
  224. "models/examples/puzzles/handshake.als",
  225. "models/examples/puzzles/handshake.thm",
  226. "models/examples/puzzles/hanoi.als",
  227. "models/examples/puzzles/hanoi.thm",
  228. "models/examples/systems/file_system.als",
  229. "models/examples/systems/file_system.thm",
  230. "models/examples/systems/javatypes_soundness.als",
  231. "models/examples/systems/lists.als",
  232. "models/examples/systems/lists.thm",
  233. "models/examples/systems/marksweepgc.als",
  234. "models/examples/systems/views.als",
  235. "models/examples/toys/birthday.als",
  236. "models/examples/toys/birthday.thm",
  237. "models/examples/toys/ceilingsAndFloors.als",
  238. "models/examples/toys/ceilingsAndFloors.thm",
  239. "models/examples/toys/genealogy.als",
  240. "models/examples/toys/genealogy.thm",
  241. "models/examples/toys/grandpa.als",
  242. "models/examples/toys/grandpa.thm",
  243. "models/examples/toys/javatypes.als",
  244. "models/examples/toys/life.als",
  245. "models/examples/toys/life.thm",
  246. "models/examples/toys/numbering.als",
  247. "models/examples/toys/railway.als",
  248. "models/examples/toys/railway.thm",
  249. "models/examples/toys/trivial.als",
  250. "models/examples/tutorial/farmer.als",
  251. "models/util/boolean.als", "models/util/graph.als",
  252. "models/util/integer.als", "models/util/natural.als",
  253. "models/util/ordering.als", "models/util/relation.als",
  254. "models/util/seqrel.als", "models/util/sequence.als",
  255. "models/util/sequniv.als", "models/util/ternary.als",
  256. "models/util/time.als");
  257. // Record the locations
  258. // System.setProperty("alloy.dotbin0",
  259. // AlloyPlugin.getDefault().getPreferenceStore()
  260. // .getString(PreferenceConstants.P_DOT_PATH));
  261. }
  262. public static AlsActivator getDefault() {
  263. return INSTANCE;
  264. }
  265. public IStatus createStatus(int severity, int code, String message,
  266. Throwable throwable) {
  267. return new Status(severity, getBundle().getSymbolicName(), code,
  268. message, throwable);
  269. }
  270. public IStatus createError(int code, Throwable throwable) {
  271. String message = throwable.getMessage();
  272. if (message == null) {
  273. message = throwable.getClass().getName();
  274. }
  275. return createStatus(IStatus.ERROR, code, message, throwable);
  276. }
  277. public void logInfo(String message) {
  278. getLog().log(createStatus(IStatus.INFO, IStatus.INFO, message, null));
  279. }
  280. public void logWarning(String message) {
  281. getLog().log(createStatus(IStatus.WARNING, IStatus.INFO, message, null));
  282. }
  283. public void logError(String message) {
  284. getLog().log(createStatus(IStatus.ERROR, IStatus.ERROR, message, null));
  285. }
  286. public void log(Throwable t) {
  287. getLog().log(createError(IStatus.ERROR, t));
  288. }
  289. /**
  290. * @author romuald druelle
  291. * @return
  292. */
  293. public static String getPluginId() {
  294. return getDefault().getBundle().getSymbolicName();
  295. }
  296. }