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