/grevecom/src/org/eclipse/conesc/plugin/utils/BinarySelector.java

https://bitbucket.org/muxa/conesc · Java · 89 lines · 61 code · 12 blank · 16 comment · 16 complexity · 31ece5e7278c4704c09dd238998d4b14 MD5 · raw file

  1. /*******************************************************************************
  2. * Copyright (c) 2014 Mikhail Afanasov and DeepSe Group.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * Mikhail Afanasov - initial API and implementation
  10. ?*******************************************************************************/
  11. package org.eclipse.conesc.plugin.utils;
  12. import java.io.IOException;
  13. import java.net.URI;
  14. import java.net.URISyntaxException;
  15. import java.net.URL;
  16. import java.util.Collections;
  17. import org.eclipse.conesc.plugin.ConesCPlugin;
  18. import org.eclipse.core.runtime.FileLocator;
  19. import org.eclipse.core.runtime.Path;
  20. import org.eclipse.core.runtime.Platform;
  21. import org.osgi.framework.Bundle;
  22. public class BinarySelector {
  23. public static final String MACOS = "Mac";
  24. public static final String LINUX = "Linux";
  25. public static final String LINUX32 = "Linux32";
  26. public static final String LINUX64 = "Linux64";
  27. public static final String WINDOWS = "Windows";
  28. public static final String WINDOWS32 = "Windows32";
  29. public static final String WINDOWS64 = "Windows64";
  30. public static String osCheck() {
  31. String os = System.getProperty("os.name");
  32. if (os.startsWith(MACOS)) return MACOS;
  33. if (os.startsWith(LINUX)) {
  34. String arch = System.getProperty("os.arch");
  35. String realArch = arch.endsWith("64") ? "64" : "32";
  36. return LINUX+realArch;
  37. }
  38. if (os.startsWith(WINDOWS)) {
  39. String arch = System.getenv("PROCESSOR_ARCHITECTURE");
  40. String wow64Arch = System.getenv("PROCESSOR_ARCHITEW6432");
  41. String realArch = arch.endsWith("64")
  42. || wow64Arch != null && wow64Arch.endsWith("64")
  43. ? "64" : "32";
  44. return WINDOWS+realArch;
  45. }
  46. return os;
  47. }
  48. public static String getNuSMVBin() throws IOException {
  49. Bundle bundle = Platform.getBundle("org.eclipse.conesc.plugin");
  50. Path path = null;
  51. String result = "";
  52. if (bundle == null)
  53. result = BinarySelector.class.getProtectionDomain().getCodeSource().getLocation().getPath();
  54. if (osCheck().equals(MACOS)) path = new Path("/NuSMV-2.5.4-linux-mac/bin_mac/NuSMV");
  55. if (osCheck().equals(LINUX32)) path = new Path("/NuSMV-2.5.4-linux-mac/bin_linux/NuSMV");
  56. if (osCheck().equals(LINUX64)) path = new Path("/NuSMV-2.5.4-linux-mac/bin_linux_64/NuSMV");
  57. if (osCheck().equals(WINDOWS64)) path = new Path("/NuSMV-2.5.4-linux-mac/bin_win_64/NuSMV.exe");
  58. if (path == null) throw new IOException("I do not have NuSMV binary for your "+osCheck()+" system.");
  59. if (bundle == null)
  60. return result+"../"+path.toString();
  61. String uri = "";
  62. try{
  63. uri = ConesCPlugin.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
  64. uri = uri.substring(0, uri.lastIndexOf(Path.SEPARATOR))+path.toString();
  65. System.out.println("URI!!! "+uri);
  66. } catch (URISyntaxException e) {
  67. // TODO Auto-generated catch block
  68. e.printStackTrace();
  69. }
  70. //URL urlToFoo = FileLocator.toFileURL(new URL("platform:/plugin/org.eclipse.conesc.plugin/"+path.toString()));
  71. //URL relative_path = FileLocator.find(bundle,path,Collections.EMPTY_MAP);
  72. //URL absolute_path = FileLocator.resolve(relative_path);
  73. //System.err.println("relative path "+relative_path.toString());
  74. //System.err.println("absolute path "+absolute_path.toString());
  75. return uri;//absolute_path.getPath();
  76. }
  77. }