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