]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Merged /sysdyn/trunk:r31333 to /sysdyn/branches/1.9 for 1.9.1.
authorlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 21 May 2015 16:50:57 +0000 (16:50 +0000)
committerlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 21 May 2015 16:50:57 +0000 (16:50 +0000)
refs #5865

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches/1.9@31343 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.modelica/.classpath
org.simantics.modelica/.settings/org.eclipse.jdt.core.prefs
org.simantics.modelica/META-INF/MANIFEST.MF
org.simantics.modelica/src/org/simantics/modelica/ModelicaException.java
org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java
org.simantics.modelica/src/org/simantics/modelica/preferences/ModelicaPreferenceInitializer.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/ModelicaPreferencePage.java

index 8a8f1668cdcc5c73a6921162616f01cb556ae7c1..b1dabee38291b97f08cc3a18bee4e65b1e550530 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
 <classpath>\r
-       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>\r
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>\r
        <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>\r
        <classpathentry kind="src" path="src"/>\r
        <classpathentry kind="output" path="bin"/>\r
index f25d3a623c4e5efb712aa0d4e43a3d999af92e03..11f6e462df7b697da0744bef232871f1aa1b0cb3 100644 (file)
@@ -1,8 +1,7 @@
-#Tue Jan 26 16:43:56 EET 2010\r
 eclipse.preferences.version=1\r
 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6\r
-org.eclipse.jdt.core.compiler.compliance=1.6\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7\r
+org.eclipse.jdt.core.compiler.compliance=1.7\r
 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
 org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
-org.eclipse.jdt.core.compiler.source=1.6\r
+org.eclipse.jdt.core.compiler.source=1.7\r
index 2cf62ac407a964b03661005b057c132456642fc2..3e74b2a60353a2fa6c2b15728de18cb6ad8b977b 100644 (file)
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
 Bundle-Name: Modelica
 Bundle-SymbolicName: org.simantics.modelica;singleton:=true
 Bundle-Version: 1.1.0.qualifier
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
 Require-Bundle: org.eclipse.osgi;bundle-version="3.6.0",
  org.eclipse.core.runtime;bundle-version="3.6.0",
  org.simantics.utils;bundle-version="1.1.0",
index 32c99c969e44a953156aa5f5b1ee7884a5e491de..3f06e2e8f7b6fefcc16a09ae6482c70aed7f00e0 100644 (file)
@@ -19,4 +19,12 @@ public class ModelicaException extends Exception {
                super(message);\r
        }\r
 \r
+       public ModelicaException(String message, Throwable cause) {\r
+               super(message, cause);\r
+       }\r
+\r
+       public ModelicaException(Throwable cause) {\r
+               super(cause);\r
+       }\r
+\r
 }\r
index 77656b8ef73336b053a1dcda3e955ec4e90f9a16..ae702400062b1f8c5de745b1f03143726a729527 100644 (file)
@@ -76,7 +76,10 @@ public class ModelicaManager {
                return new File(home, "bin" + File.separator + "omc" + (onWindows() ? ".exe" : ""));\r
        }\r
        \r
-       private static Process runWithEnvironment(File homeDir, File workDir, File executable, String... parameters) {\r
+       private static Process runWithEnvironment(File homeDir, File workDir, File executable, String... parameters) throws IOException {\r
+               if (!executable.isFile() && !executable.canExecute())\r
+                       throw new FileNotFoundException("executable " + executable.getAbsolutePath() + " not found");\r
+\r
                // construct the command\r
                List<String> command = new ArrayList<String>();\r
                command.add(executable.getAbsolutePath());\r
@@ -118,22 +121,20 @@ public class ModelicaManager {
                \r
                // run the process\r
                Process process = null;\r
-               try {\r
-                       process = builder.start();\r
-               }\r
-               catch (Exception e) {\r
-                       e.printStackTrace();\r
-               }\r
-               \r
+               process = builder.start();\r
                return process;\r
        }\r
        \r
-       private static Process runOMC(File homeDir, File workDir, String... parameters) {\r
+       private static Process runOMC(File homeDir, File workDir, String... parameters) throws IOException {\r
                return runWithEnvironment(homeDir, workDir, getOMCBinary(homeDir), parameters);\r
        }\r
        \r
        public static String getOMVersion(File home) {\r
-               return getProcessOutput(runOMC(home, home, "--version"));\r
+               try {\r
+                       return getProcessOutput(runOMC(home, home, "--version"));\r
+               } catch (IOException e) {\r
+                       return null;\r
+               }\r
        }\r
        \r
        public static String getDefaultOMVersion() {\r
@@ -173,8 +174,7 @@ public class ModelicaManager {
                if (installed != null)\r
                        return installed;\r
                \r
-               // TODO: what is the correct error to throw?\r
-               throw new Error("OpenModelica could not be found");\r
+               return null;\r
        }\r
 \r
        public static File getInstalledOMHome() {\r
@@ -206,25 +206,22 @@ public class ModelicaManager {
         * Gets the whole process output in one string\r
         * \r
         * @param process Process\r
-        * @return process output\r
+        * @return process output or <code>null</code> if retrieving the process\r
+        *         output fails for some I/O-related reason\r
         */\r
-       public static String getProcessOutput(final Process process) {\r
-               try {\r
-                       BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));\r
+       private static String getProcessOutput(final Process process) throws IOException {\r
+               String lf = System.getProperty("line.separator");\r
+               try (BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()))) {\r
                        StringBuilder output = new StringBuilder();\r
                        String line;\r
                        boolean first = true;\r
                        while ((line = input.readLine()) != null) {\r
                                if(!first)\r
-                                       output.append(System.getProperty("line.separator"));\r
+                                       output.append(lf);\r
                                first = false;\r
                                output.append(line);\r
                        }\r
-                       input.close();\r
                        return output.toString();\r
-               } catch (Exception e) {\r
-                       e.printStackTrace();\r
-                       return null;\r
                }\r
        }\r
 \r
@@ -413,20 +410,20 @@ public class ModelicaManager {
 \r
        public static void buildFullModel(SimulationLocation location, IModelicaMonitor monitor) \r
                        throws ModelicaException {\r
-               Process process = runOMC(location.omHome, location.getModelDir(), location.fullModelScriptFile.getAbsolutePath());\r
-               printProcessOutput(process, monitor);\r
-               \r
                try {\r
+                       Process process = runOMC(location.omHome, location.getModelDir(), location.fullModelScriptFile.getAbsolutePath());\r
+                       printProcessOutput(process, monitor);\r
                        process.waitFor();\r
+                       trimExtraFromFullModel(location);\r
+               } catch (IOException ex) {\r
+                       throw new ModelicaException(ex);\r
+               } catch (InterruptedException ex) {\r
+                       throw new ModelicaException(ex);\r
                }\r
-               catch (InterruptedException e) {\r
-                       e.printStackTrace();\r
-               }\r
-\r
-               trimExtraFromFullModel(location);\r
        }\r
        \r
        private static void trimExtraFromFullModel(SimulationLocation location) {\r
+               // TODO: consider throwing IOException, not catching them.\r
                try {\r
                        FileInputStream fs = new FileInputStream(location.fullModelFile);\r
                        InputStreamReader in = new InputStreamReader(fs);\r
@@ -472,20 +469,16 @@ public class ModelicaManager {
         */\r
        public static void buildModel(SimulationLocation location, IModelicaMonitor monitor) \r
                        throws ModelicaException {\r
-               \r
-               Process process = runOMC(location.omHome, location.getModelDir(), location.modelScriptFile.getAbsolutePath());\r
-               printProcessOutput(process, monitor);\r
-               \r
                try {\r
+                       Process process = runOMC(location.omHome, location.getModelDir(), location.modelScriptFile.getAbsolutePath());\r
+                       printProcessOutput(process, monitor);\r
                        process.waitFor();\r
-               }\r
-               catch (InterruptedException e) {\r
-                       e.printStackTrace();\r
-               }\r
-               \r
-               if (!location.executableFile.isFile()) {\r
-                       // If executable file was not created, something went wrong\r
-                       throw new ModelicaException("executable file not created");\r
+                       if (!location.executableFile.isFile()) {\r
+                               // If executable file was not created, something went wrong\r
+                               throw new ModelicaException("executable file not created");\r
+                       }\r
+               } catch (IOException | InterruptedException ex) {\r
+                       throw new ModelicaException(ex);\r
                }\r
        }\r
 \r
@@ -519,7 +512,7 @@ public class ModelicaManager {
                return runWithEnvironment(location.omHome, location.getModelDir(), location.executableFile, commandString);\r
        }\r
 \r
-       public static String getFlatModelText(SimulationLocation location, IModelicaMonitor monitor, List<String> additional) {\r
+       public static String getFlatModelText(SimulationLocation location, IModelicaMonitor monitor, List<String> additional) throws IOException {\r
                String[] command = new String[additional.size()+1];\r
                command[0] = location.modelFile.getAbsolutePath();\r
                for (int i = 0; i < additional.size(); i++) {\r
index 553aeaba7a58457f8cc15cb6a3ac4602efe2b5bd..2f33fb310940b7d84dbe18e4795367d3a4b21421 100644 (file)
@@ -46,7 +46,8 @@ public class ModelicaPreferenceInitializer extends AbstractPreferenceInitializer
        }  \r
 \r
        private void useDefault(Preferences node) {\r
-               node.put(OpenModelicaPreferences.OM_HOME, ModelicaManager.getDefaultOMHome().getAbsolutePath());\r
+               File omhome = ModelicaManager.getDefaultOMHome();\r
+               node.put(OpenModelicaPreferences.OM_HOME, omhome != null ? omhome.getAbsolutePath() : "");\r
        }\r
 \r
 }\r
index 0ab5acee7c6a6a1d3e767f5efdf9402c2b5dde03..f97816a5a55f12f6244233933e57df44479e2d5f 100644 (file)
@@ -86,7 +86,8 @@ public class ModelicaPreferencePage extends FieldEditorPreferencePage implements
                        public void doLoadDefault() {\r
                                IScopeContext context = ConfigurationScope.INSTANCE;\r
                                Preferences node = context.getNode(Activator.PLUGIN_ID);\r
-                               node.put(OpenModelicaPreferences.OM_HOME, ModelicaManager.getDefaultOMHome().getAbsolutePath());\r
+                               File omhome = ModelicaManager.getDefaultOMHome();\r
+                               node.put(OpenModelicaPreferences.OM_HOME, omhome != null ? omhome.getAbsolutePath() : "");\r
                                load();\r
                        }\r
                };\r
@@ -113,8 +114,10 @@ public class ModelicaPreferencePage extends FieldEditorPreferencePage implements
                        protected boolean doCheckState() {\r
                                boolean valid = super.doCheckState();\r
                                if(valid) {\r
-                                       // path is a valid directory\r
+                                       // path is a valid directory or empty\r
                                        String path = getStringValue();\r
+                                       if (path.isEmpty())\r
+                                               return true;\r
                                        File dir = new File(path);\r
                                        String version = ModelicaManager.getOMVersion(dir);\r
                                        if(version == null || version.isEmpty()) {\r
@@ -134,7 +137,8 @@ public class ModelicaPreferencePage extends FieldEditorPreferencePage implements
 \r
                        @Override\r
                        public void doLoadDefault() {\r
-                               updatePath(ModelicaManager.getDefaultOMHome().getAbsolutePath());\r
+                               File omhome = ModelicaManager.getDefaultOMHome();\r
+                               updatePath(omhome != null ? omhome.getAbsolutePath() : "");\r
                        }\r
 \r
                        private void updatePath(String newValue) {\r
@@ -149,7 +153,8 @@ public class ModelicaPreferencePage extends FieldEditorPreferencePage implements
 \r
                };\r
 \r
-               path.setErrorMessage("Path must be a valid OpenModelica directory");\r
+               path.setErrorMessage("Path must be a valid OpenModelica directory or left empty");\r
+               path.setEmptyStringAllowed(true);\r
                addField(path);\r
        }\r
 \r