1 /*******************************************************************************
2 * Copyright (c) 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.procore.server.environment;
15 import java.io.IOException;
17 import java.util.Arrays;
19 import org.eclipse.core.runtime.FileLocator;
20 import org.eclipse.core.runtime.IProgressMonitor;
21 import org.simantics.db.procore.server.environment.windows.Msi;
22 import org.simantics.db.procore.server.environment.windows.Product;
23 import org.simantics.db.procore.server.environment.windows.ProductCodes;
26 * @author Tuukka Lehtonen
28 public final class ServerEnvironment {
30 // http://msdn.microsoft.com/en-us/library/aa368542(v=vs.85).aspx
31 private static final int ERROR_SUCCESS = 0;
32 private static final int ERROR_SUCCESS_REBOOT_REQUIRED = 3010;
35 * Checks whether the current running environment has all the necessary
36 * components installed to run the ProCore database server.
38 * @throws ExecutionEnvironmentException if dependencies for running the
39 * database server are not met
41 public static void ensureServerDependenciesMet() throws ExecutionEnvironmentException {
42 ExecutionEnvironment env = ExecutionEnvironment.calculate();
47 Msi.checkOneOfProductsInstalled(ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X86_KB2467174);
50 Msi.checkProductsInstalled(ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X86_KB2467174, ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X64_KB2467174);
59 * Checks whether the current running environment has all the necessary
60 * components installed to run the ProCore database server.
62 * @throws ExecutionEnvironmentException if dependencies for running the
63 * database server are not met
65 public static void tryInstallDependencies(IProgressMonitor monitor) throws InstallException {
66 ExecutionEnvironment env = ExecutionEnvironment.calculate();
71 runInstaller(monitor, ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X86_KB2467174, "VC90.2008.SP1.KB2467174.redist.x86.exe");
74 runInstaller(monitor, ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X86_KB2467174, "VC90.2008.SP1.KB2467174.redist.x86.exe");
75 runInstaller(monitor, ProductCodes.VISUAL_CPP_2008_SP1_REDIST_X64_KB2467174, "VC90.2008.SP1.KB2467174.redist.x64.exe");
83 private static void runInstaller(IProgressMonitor monitor, Product product, String installerPath) throws InstallException {
85 URL url = FileLocator.find(new URL("platform:/plugin/org.simantics.db.procore.server.environment/" + installerPath));
86 URL fileUrl = FileLocator.toFileURL(url);
87 final File file = new File(fileUrl.getFile());
88 System.out.println(file);
90 Process installer = new ProcessBuilder("cmd.exe", "/C", file.toString(), "/qb").start();
93 int exitValue = installer.exitValue();
94 //System.out.println("installation done, exit code: " + exitValue);
98 case ERROR_SUCCESS_REBOOT_REQUIRED:
99 throw new RebootRequiredException(Arrays.asList(product));
101 throw new InstallException("Installation of " + product.getDescription() + " failed with error code " + exitValue, Arrays.asList(product));
102 } catch (IllegalThreadStateException e) {
103 // if (monitor.isCanceled()) {
104 // installer.destroy();
108 //System.out.println("sleeping");
110 } catch (InterruptedException ie) {
114 } catch (IOException e) {
115 throw new InstallException(e, Arrays.asList(product));
119 // -------------------------------------------------------------------------
121 public static void main(String[] args) {
123 ensureServerDependenciesMet();
124 } catch (ExecutionEnvironmentException e) {