From: lehtonen Date: Wed, 6 Oct 2010 01:30:18 +0000 (+0000) Subject: Cleaner os.openmodelica.win32 usage in ModelicaManager. X-Git-Tag: simantics-1.2.0~6 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=524bf33fc5e6f27c02593a5a564ddeb658b571ce;p=simantics%2Fsysdyn.git Cleaner os.openmodelica.win32 usage in ModelicaManager. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@18269 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.modelica/META-INF/MANIFEST.MF b/org.simantics.modelica/META-INF/MANIFEST.MF index 4b301f97..33fac154 100644 --- a/org.simantics.modelica/META-INF/MANIFEST.MF +++ b/org.simantics.modelica/META-INF/MANIFEST.MF @@ -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 diff --git a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java index 7762e81a..132d2c05 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java +++ b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java @@ -17,12 +17,12 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; -import java.net.URI; import java.net.URL; -import java.net.URLConnection; +import java.net.URLDecoder; import java.util.HashMap; -import org.eclipse.osgi.framework.internal.core.BundleURLConnection; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Platform; import org.osgi.framework.Bundle; public class ModelicaManager { @@ -55,32 +55,24 @@ public class ModelicaManager { OSType os = calculateOS(); if (os == OSType.UNKNOWN) - throw new UnsatisfiedLinkError("unknown OS '" + osName + "' cannot load native fastlz library"); + throw new UnsatisfiedLinkError("unknown OS '" + osName + "' for running OpenModelica"); // Teemu's stuff, testing openmodelica in a plugin if(dir == null && os.equals(OSType.WINDOWS)) { - for(Bundle bundle : Activator.getContext().getBundles()) { - if(bundle.getSymbolicName().equals("org.simantics.openmodelica.win32")) { - try{ - URL entry = bundle.getEntry("."); - if(entry != null) { - URLConnection connection = entry.openConnection(); - if(connection instanceof BundleURLConnection) { - URL fileURL = ((BundleURLConnection)connection).getFileURL(); - URI uri = new URI(fileURL.toString()); - String path = new File(uri).getAbsolutePath(); - path = path.substring(0, path.length() - 1); - path = path + "OpenModelica1.5.0\\om.bat"; - File f = new File(path); - return f; - } - } - } - catch (Exception e) { - e.printStackTrace(); + Bundle bundle = Platform.getBundle("org.simantics.openmodelica.win32"); + if (bundle != null) { + try{ + URL entry = bundle.getEntry("/"); + if(entry != null) { + URL fileURL = FileLocator.toFileURL(entry); + File root = new File( URLDecoder.decode(fileURL.getPath(), "UTF-8") ); + File f = new File(new File(root, "OpenModelica1.5.0"), "om.bat"); + return f; } - + } + catch (Exception e) { + e.printStackTrace(); } } }