X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.server%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fserver%2Finternal%2FActivator.java;h=145fba9122f1113ec21afcacda883de8293e1c2c;hb=HEAD;hp=bd1a95286579db3798a8415fc3925af47eec5915;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.server/src/org/simantics/db/server/internal/Activator.java b/bundles/org.simantics.db.server/src/org/simantics/db/server/internal/Activator.java index bd1a95286..145fba912 100644 --- a/bundles/org.simantics.db.server/src/org/simantics/db/server/internal/Activator.java +++ b/bundles/org.simantics.db.server/src/org/simantics/db/server/internal/Activator.java @@ -1,94 +1,94 @@ -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; - } -} +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; + } +}