-package org.simantics.db.server.internal;\r
-\r
-import java.io.File;\r
-import java.io.FileNotFoundException;\r
-import java.io.IOException;\r
-import java.net.URL;\r
-\r
-import org.eclipse.core.runtime.FileLocator;\r
-import org.eclipse.core.runtime.Path;\r
-import org.eclipse.core.runtime.Plugin;\r
-import org.osgi.framework.Bundle;\r
-import org.osgi.framework.BundleContext;\r
-\r
-public class Activator extends Plugin {\r
-\r
- public static final String PLUGIN_ID = "org.simantics.db.server";\r
- static Activator activator;\r
-\r
- @Override\r
- public void start(BundleContext context) throws Exception {\r
- activator = this;\r
- super.start(context);\r
- }\r
-\r
- @Override\r
- public void stop(BundleContext context) throws Exception {\r
- super.stop(context);\r
- activator = null;\r
- }\r
-\r
- public static Activator get() {\r
- return activator;\r
- }\r
-\r
- private static final String ROOT = "/";\r
-\r
- public static File getRoot()\r
- throws FileNotFoundException, IOException {\r
- Bundle b = Activator.get().getBundle();\r
- URL source = FileLocator.find(b, new Path(ROOT), null);\r
- URL fileSource = FileLocator.toFileURL(source);\r
- if (fileSource == source)\r
- throw new FileNotFoundException(ROOT + "could not be made available from bundle " + b.getSymbolicName());\r
- File root = new File(fileSource.getFile());\r
- return root;\r
- }\r
- public static File getServerFolder()\r
- throws FileNotFoundException, IOException {\r
- final String suffix = calculateSuffix();\r
- final String name = getRoot() + File.separator + suffix;\r
- File folder = new File(name);\r
- if (!folder.isDirectory()) {\r
- String wd = new File(".").getAbsolutePath();\r
- throw new FileNotFoundException("No directory for " + name + " current directory=" + wd + ".");\r
- }\r
- return folder;\r
- }\r
- public static String getExeSuffix() {\r
- String osName = System.getProperty("os.name").toLowerCase();\r
- if (osName.startsWith("windows"))\r
- return ".exe";\r
- else\r
- return "";\r
- }\r
- private static String calculateSuffix() throws FileNotFoundException {\r
- String osArch = System.getProperty("os.arch").toLowerCase();\r
- String osName = System.getProperty("os.name").toLowerCase();\r
- if (is64BitOS()) {\r
- if (osName.startsWith("windows"))\r
- return "win32.x86_64";\r
- else if (osName.startsWith("linux"))\r
- return "linux.x86_64";\r
- else if (osName.startsWith("darwin"))\r
- return "darwin.x86_64";\r
- } else if (osArch.equals("i386") || osArch.equals("i586") || osArch.equals("i686") || osArch.equals("x86")) {\r
- if (osName.startsWith("windows"))\r
- return "win32.x86";\r
- else if (osName.startsWith("linux"))\r
- return "linux.x86";\r
- }\r
- throw new FileNotFoundException("Unsupported architecture " + osArch + " and/or operating system " + osName);\r
- }\r
-\r
- private static boolean is64BitOS() {\r
- if (System.getProperty("os.name").toLowerCase().contains("windows")) {\r
- // Even though os.arch reports a 32-bit system this might be because\r
- // we are running 32-bit Java. Therefore check the OS architecture.\r
- // Note that WMI would be the correct way to check this, but this\r
- // works pretty well also.\r
- return System.getenv("ProgramFiles(x86)") != null;\r
- }\r
- return System.getProperty("os.arch").indexOf("64") != -1;\r
- }\r
-}\r
+package org.simantics.db.server.internal;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+public class Activator extends Plugin {
+
+ public static final String PLUGIN_ID = "org.simantics.db.server";
+ static Activator activator;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ activator = this;
+ super.start(context);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ activator = null;
+ }
+
+ public static Activator get() {
+ return activator;
+ }
+
+ private static final String ROOT = "/";
+
+ public static File getRoot()
+ throws FileNotFoundException, IOException {
+ Bundle b = Activator.get().getBundle();
+ URL source = FileLocator.find(b, new Path(ROOT), null);
+ URL fileSource = FileLocator.toFileURL(source);
+ if (fileSource == source)
+ throw new FileNotFoundException(ROOT + "could not be made available from bundle " + b.getSymbolicName());
+ File root = new File(fileSource.getFile());
+ return root;
+ }
+ public static File getServerFolder()
+ throws FileNotFoundException, IOException {
+ final String suffix = calculateSuffix();
+ final String name = getRoot() + File.separator + suffix;
+ File folder = new File(name);
+ if (!folder.isDirectory()) {
+ String wd = new File(".").getAbsolutePath();
+ throw new FileNotFoundException("No directory for " + name + " current directory=" + wd + ".");
+ }
+ return folder;
+ }
+ public static String getExeSuffix() {
+ String osName = System.getProperty("os.name").toLowerCase();
+ if (osName.startsWith("windows"))
+ return ".exe";
+ else
+ return "";
+ }
+ private static String calculateSuffix() throws FileNotFoundException {
+ String osArch = System.getProperty("os.arch").toLowerCase();
+ String osName = System.getProperty("os.name").toLowerCase();
+ if (is64BitOS()) {
+ if (osName.startsWith("windows"))
+ return "win32.x86_64";
+ else if (osName.startsWith("linux"))
+ return "linux.x86_64";
+ else if (osName.startsWith("darwin"))
+ return "darwin.x86_64";
+ } else if (osArch.equals("i386") || osArch.equals("i586") || osArch.equals("i686") || osArch.equals("x86")) {
+ if (osName.startsWith("windows"))
+ return "win32.x86";
+ else if (osName.startsWith("linux"))
+ return "linux.x86";
+ }
+ throw new FileNotFoundException("Unsupported architecture " + osArch + " and/or operating system " + osName);
+ }
+
+ private static boolean is64BitOS() {
+ if (System.getProperty("os.name").toLowerCase().contains("windows")) {
+ // Even though os.arch reports a 32-bit system this might be because
+ // we are running 32-bit Java. Therefore check the OS architecture.
+ // Note that WMI would be the correct way to check this, but this
+ // works pretty well also.
+ return System.getenv("ProgramFiles(x86)") != null;
+ }
+ return System.getProperty("os.arch").indexOf("64") != -1;
+ }
+}