]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Cleaner os.openmodelica.win32 usage in ModelicaManager.
authorlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 6 Oct 2010 01:30:18 +0000 (01:30 +0000)
committerlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 6 Oct 2010 01:30:18 +0000 (01:30 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@18269 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.modelica/META-INF/MANIFEST.MF
org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java

index 4b301f97498a1304ee460ab265904c09108f2347..33fac154427bd8722ecb032a9d53d660a2f9bb48 100644 (file)
@@ -6,7 +6,8 @@ Bundle-Version: 1.0.0.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Require-Bundle: gnu.trove2;bundle-version="2.0.4",
  org.simantics.databoard;bundle-version="0.5.2",
- org.eclipse.osgi;bundle-version="3.6.0"
+ org.eclipse.osgi;bundle-version="3.6.0",
+ org.eclipse.core.runtime;bundle-version="3.6.0"
 Export-Package: org.simantics.modelica,
  org.simantics.modelica.data
 Bundle-Activator: org.simantics.modelica.Activator
index 7762e81a0f8f68edd1d155b9b8eb3a6cd0a931cd..132d2c050eade04de9b1d809a0342034447d7339 100644 (file)
@@ -17,12 +17,12 @@ import java.io.FileNotFoundException;
 import java.io.IOException;\r
 import java.io.InputStream;\r
 import java.io.PrintStream;\r
-import java.net.URI;\r
 import java.net.URL;\r
-import java.net.URLConnection;\r
+import java.net.URLDecoder;\r
 import java.util.HashMap;\r
 \r
-import org.eclipse.osgi.framework.internal.core.BundleURLConnection;\r
+import org.eclipse.core.runtime.FileLocator;\r
+import org.eclipse.core.runtime.Platform;\r
 import org.osgi.framework.Bundle;\r
 \r
 public class ModelicaManager {\r
@@ -55,32 +55,24 @@ public class ModelicaManager {
                OSType os = calculateOS();\r
 \r
                if (os == OSType.UNKNOWN)\r
-                       throw new UnsatisfiedLinkError("unknown OS '" + osName + "' cannot load native fastlz library");\r
+                       throw new UnsatisfiedLinkError("unknown OS '" + osName + "' for running OpenModelica");\r
 \r
                // Teemu's stuff, testing openmodelica in a plugin\r
                if(dir == null && os.equals(OSType.WINDOWS)) {\r
 \r
-                       for(Bundle bundle : Activator.getContext().getBundles()) {\r
-                               if(bundle.getSymbolicName().equals("org.simantics.openmodelica.win32")) {\r
-                                       try{\r
-                                               URL entry = bundle.getEntry(".");\r
-                                               if(entry != null) {\r
-                                                       URLConnection connection = entry.openConnection();\r
-                                                       if(connection instanceof BundleURLConnection) {\r
-                                                               URL fileURL = ((BundleURLConnection)connection).getFileURL();\r
-                                                               URI uri = new URI(fileURL.toString());\r
-                                                               String path = new File(uri).getAbsolutePath();\r
-                                                               path = path.substring(0, path.length() - 1);\r
-                                                               path = path + "OpenModelica1.5.0\\om.bat";\r
-                                                               File f = new File(path);\r
-                                                               return f;\r
-                                                       }\r
-                                               }\r
-                                       }\r
-                                       catch (Exception e) {\r
-                                               e.printStackTrace();\r
+                       Bundle bundle = Platform.getBundle("org.simantics.openmodelica.win32");\r
+                       if (bundle != null) {\r
+                               try{\r
+                                       URL entry = bundle.getEntry("/");\r
+                                       if(entry != null) {\r
+                                               URL fileURL = FileLocator.toFileURL(entry);\r
+                                               File root = new File( URLDecoder.decode(fileURL.getPath(), "UTF-8") );\r
+                                               File f = new File(new File(root, "OpenModelica1.5.0"), "om.bat");\r
+                                               return f;\r
                                        }\r
-\r
+                               }\r
+                               catch (Exception e) {\r
+                                       e.printStackTrace();\r
                                }\r
                        }\r
                }\r