]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore.server.environment/src/org/simantics/db/procore/server/environment/ServerEnvironment.java
Merge "Move debugging options under DevelopmentKeys"
[simantics/platform.git] / bundles / org.simantics.db.procore.server.environment / src / org / simantics / db / procore / server / environment / ServerEnvironment.java
index 4a0290d55cd7f66d15c4ea3f0d0ac43a4315079c..5de87a27ecfc9fa28a32eacb1660722626f01fde 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db.procore.server.environment;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.net.URL;\r
-import java.util.Arrays;\r
-\r
-import org.eclipse.core.runtime.FileLocator;\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.simantics.db.procore.server.environment.windows.Msi;\r
-import org.simantics.db.procore.server.environment.windows.Product;\r
-import org.simantics.db.procore.server.environment.windows.ProductCodes;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public final class ServerEnvironment {\r
-\r
-    // http://msdn.microsoft.com/en-us/library/aa368542(v=vs.85).aspx\r
-    private static final int ERROR_SUCCESS                 = 0;\r
-    private static final int ERROR_SUCCESS_REBOOT_REQUIRED = 3010;\r
-\r
-    /**\r
-     * Checks whether the current running environment has all the necessary\r
-     * components installed to run the ProCore database server.\r
-     * \r
-     * @throws ExecutionEnvironmentException if dependencies for running the\r
-     *         database server are not met\r
-     */\r
-    public static void ensureServerDependenciesMet() throws ExecutionEnvironmentException {\r
-        ExecutionEnvironment env = ExecutionEnvironment.calculate();\r
-        switch (env.os) {\r
-            case WINDOWS: {\r
-                switch (env.arch) {\r
-                    case X86:\r
-                        Msi.checkOneOfProductsInstalled(ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X86_KB2467174);\r
-                        break;\r
-                    case X86_64:\r
-                        Msi.checkProductsInstalled(ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X86_KB2467174, ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X64_KB2467174);\r
-                        break;\r
-                }\r
-                break;\r
-            }\r
-        }\r
-    }\r
-\r
-    /**\r
-     * Checks whether the current running environment has all the necessary\r
-     * components installed to run the ProCore database server.\r
-     * \r
-     * @throws ExecutionEnvironmentException if dependencies for running the\r
-     *         database server are not met\r
-     */\r
-    public static void tryInstallDependencies(IProgressMonitor monitor) throws InstallException {\r
-        ExecutionEnvironment env = ExecutionEnvironment.calculate();\r
-        switch (env.os) {\r
-            case WINDOWS: {\r
-                switch (env.arch) {\r
-                    case X86:\r
-                        runInstaller(monitor, ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X86_KB2467174, "VC90.2008.SP1.KB2467174.redist.x86.exe");\r
-                        break;\r
-                    case X86_64:\r
-                        runInstaller(monitor, ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X86_KB2467174, "VC90.2008.SP1.KB2467174.redist.x86.exe");\r
-                        runInstaller(monitor, ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X64_KB2467174, "VC90.2008.SP1.KB2467174.redist.x64.exe");\r
-                        break;\r
-                }\r
-                break;\r
-            }\r
-        }\r
-    }\r
-\r
-    private static void runInstaller(IProgressMonitor monitor, Product product, String installerPath) throws InstallException {\r
-        try {\r
-            URL url = FileLocator.find(new URL("platform:/plugin/org.simantics.db.procore.server.environment/" + installerPath));\r
-            URL fileUrl = FileLocator.toFileURL(url);\r
-            final File file = new File(fileUrl.getFile());\r
-            System.out.println(file);\r
-\r
-            Process installer = new ProcessBuilder("cmd.exe", "/C", file.toString(), "/qb").start();\r
-            while (true) {\r
-                try {\r
-                    int exitValue = installer.exitValue();\r
-                    //System.out.println("installation done, exit code: " + exitValue);\r
-                    switch (exitValue) {\r
-                        case ERROR_SUCCESS:\r
-                            return;\r
-                        case ERROR_SUCCESS_REBOOT_REQUIRED:\r
-                            throw new RebootRequiredException(Arrays.asList(product));\r
-                    }\r
-                    throw new InstallException("Installation of " + product.getDescription() + " failed with error code " + exitValue, Arrays.asList(product));\r
-                } catch (IllegalThreadStateException e) {\r
-//                    if (monitor.isCanceled()) {\r
-//                        installer.destroy();\r
-//                    }\r
-                    // Not done yet.\r
-                    try {\r
-                        //System.out.println("sleeping");\r
-                        Thread.sleep(250);\r
-                    } catch (InterruptedException ie) {\r
-                    }\r
-                }\r
-            }\r
-        } catch (IOException e) {\r
-            throw new InstallException(e, Arrays.asList(product));\r
-        }\r
-    }\r
-\r
-    // -------------------------------------------------------------------------\r
-\r
-    public static void main(String[] args) {\r
-        try {\r
-            ensureServerDependenciesMet();\r
-        } catch (ExecutionEnvironmentException e) {\r
-            e.printStackTrace();\r
-        }\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.procore.server.environment;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Arrays;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.simantics.db.procore.server.environment.windows.Msi;
+import org.simantics.db.procore.server.environment.windows.Product;
+import org.simantics.db.procore.server.environment.windows.ProductCodes;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public final class ServerEnvironment {
+
+    // http://msdn.microsoft.com/en-us/library/aa368542(v=vs.85).aspx
+    private static final int ERROR_SUCCESS                 = 0;
+    private static final int ERROR_SUCCESS_REBOOT_REQUIRED = 3010;
+
+    /**
+     * Checks whether the current running environment has all the necessary
+     * components installed to run the ProCore database server.
+     * 
+     * @throws ExecutionEnvironmentException if dependencies for running the
+     *         database server are not met
+     */
+    public static void ensureServerDependenciesMet() throws ExecutionEnvironmentException {
+        ExecutionEnvironment env = ExecutionEnvironment.calculate();
+        switch (env.os) {
+            case WINDOWS: {
+                switch (env.arch) {
+                    case X86:
+                        Msi.checkOneOfProductsInstalled(ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X86_KB2467174);
+                        break;
+                    case X86_64:
+                        Msi.checkProductsInstalled(ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X86_KB2467174, ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X64_KB2467174);
+                        break;
+                }
+                break;
+            }
+        }
+    }
+
+    /**
+     * Checks whether the current running environment has all the necessary
+     * components installed to run the ProCore database server.
+     * 
+     * @throws ExecutionEnvironmentException if dependencies for running the
+     *         database server are not met
+     */
+    public static void tryInstallDependencies(IProgressMonitor monitor) throws InstallException {
+        ExecutionEnvironment env = ExecutionEnvironment.calculate();
+        switch (env.os) {
+            case WINDOWS: {
+                switch (env.arch) {
+                    case X86:
+                        runInstaller(monitor, ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X86_KB2467174, "VC90.2008.SP1.KB2467174.redist.x86.exe");
+                        break;
+                    case X86_64:
+                        runInstaller(monitor, ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X86_KB2467174, "VC90.2008.SP1.KB2467174.redist.x86.exe");
+                        runInstaller(monitor, ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X64_KB2467174, "VC90.2008.SP1.KB2467174.redist.x64.exe");
+                        break;
+                }
+                break;
+            }
+        }
+    }
+
+    private static void runInstaller(IProgressMonitor monitor, Product product, String installerPath) throws InstallException {
+        try {
+            URL url = FileLocator.find(new URL("platform:/plugin/org.simantics.db.procore.server.environment/" + installerPath));
+            URL fileUrl = FileLocator.toFileURL(url);
+            final File file = new File(fileUrl.getFile());
+            System.out.println(file);
+
+            Process installer = new ProcessBuilder("cmd.exe", "/C", file.toString(), "/qb").start();
+            while (true) {
+                try {
+                    int exitValue = installer.exitValue();
+                    //System.out.println("installation done, exit code: " + exitValue);
+                    switch (exitValue) {
+                        case ERROR_SUCCESS:
+                            return;
+                        case ERROR_SUCCESS_REBOOT_REQUIRED:
+                            throw new RebootRequiredException(Arrays.asList(product));
+                    }
+                    throw new InstallException("Installation of " + product.getDescription() + " failed with error code " + exitValue, Arrays.asList(product));
+                } catch (IllegalThreadStateException e) {
+//                    if (monitor.isCanceled()) {
+//                        installer.destroy();
+//                    }
+                    // Not done yet.
+                    try {
+                        //System.out.println("sleeping");
+                        Thread.sleep(250);
+                    } catch (InterruptedException ie) {
+                    }
+                }
+            }
+        } catch (IOException e) {
+            throw new InstallException(e, Arrays.asList(product));
+        }
+    }
+
+    // -------------------------------------------------------------------------
+
+    public static void main(String[] args) {
+        try {
+            ensureServerDependenciesMet();
+        } catch (ExecutionEnvironmentException e) {
+            e.printStackTrace();
+        }
+    }
+
+}