1 package org.simantics.db.server.internal;
\r
4 import java.io.FileNotFoundException;
\r
5 import java.io.IOException;
\r
8 import org.eclipse.core.runtime.FileLocator;
\r
9 import org.eclipse.core.runtime.Path;
\r
10 import org.eclipse.core.runtime.Plugin;
\r
11 import org.osgi.framework.Bundle;
\r
12 import org.osgi.framework.BundleContext;
\r
14 public class Activator extends Plugin {
\r
16 public static final String PLUGIN_ID = "org.simantics.db.server";
\r
17 static Activator activator;
\r
20 public void start(BundleContext context) throws Exception {
\r
22 super.start(context);
\r
26 public void stop(BundleContext context) throws Exception {
\r
27 super.stop(context);
\r
31 public static Activator get() {
\r
35 private static final String ROOT = "/";
\r
37 public static File getRoot()
\r
38 throws FileNotFoundException, IOException {
\r
39 Bundle b = Activator.get().getBundle();
\r
40 URL source = FileLocator.find(b, new Path(ROOT), null);
\r
41 URL fileSource = FileLocator.toFileURL(source);
\r
42 if (fileSource == source)
\r
43 throw new FileNotFoundException(ROOT + "could not be made available from bundle " + b.getSymbolicName());
\r
44 File root = new File(fileSource.getFile());
\r
47 public static File getServerFolder()
\r
48 throws FileNotFoundException, IOException {
\r
49 final String suffix = calculateSuffix();
\r
50 final String name = getRoot() + File.separator + suffix;
\r
51 File folder = new File(name);
\r
52 if (!folder.isDirectory()) {
\r
53 String wd = new File(".").getAbsolutePath();
\r
54 throw new FileNotFoundException("No directory for " + name + " current directory=" + wd + ".");
\r
58 public static String getExeSuffix() {
\r
59 String osName = System.getProperty("os.name").toLowerCase();
\r
60 if (osName.startsWith("windows"))
\r
65 private static String calculateSuffix() throws FileNotFoundException {
\r
66 String osArch = System.getProperty("os.arch").toLowerCase();
\r
67 String osName = System.getProperty("os.name").toLowerCase();
\r
69 if (osName.startsWith("windows"))
\r
70 return "win32.x86_64";
\r
71 else if (osName.startsWith("linux"))
\r
72 return "linux.x86_64";
\r
73 else if (osName.startsWith("darwin"))
\r
74 return "darwin.x86_64";
\r
75 } else if (osArch.equals("i386") || osArch.equals("i586") || osArch.equals("i686") || osArch.equals("x86")) {
\r
76 if (osName.startsWith("windows"))
\r
78 else if (osName.startsWith("linux"))
\r
81 throw new FileNotFoundException("Unsupported architecture " + osArch + " and/or operating system " + osName);
\r
84 private static boolean is64BitOS() {
\r
85 if (System.getProperty("os.name").toLowerCase().contains("windows")) {
\r
86 // Even though os.arch reports a 32-bit system this might be because
\r
87 // we are running 32-bit Java. Therefore check the OS architecture.
\r
88 // Note that WMI would be the correct way to check this, but this
\r
89 // works pretty well also.
\r
90 return System.getenv("ProgramFiles(x86)") != null;
\r
92 return System.getProperty("os.arch").indexOf("64") != -1;
\r