package org.simantics.district.maps.server; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; import org.eclipse.core.runtime.FileLocator; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { public static final String PLUGIN_ID = "org.simantics.maps.server"; private static BundleContext context; private static Activator defaultt; static BundleContext getContext() { return context; } /* * (non-Javadoc) * * @see org.osgi.framework.BundleActivator#start(org.osgi.framework. * BundleContext) */ public void start(BundleContext bundleContext) throws Exception { Activator.context = bundleContext; Activator.defaultt = this; } /* * (non-Javadoc) * * @see * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext bundleContext) throws Exception { Activator.context = null; Activator.defaultt = null; } public static Path getNodeJSRoot() throws IOException, URISyntaxException { return resolvePath("/node"); } public static Path getTileserverMapnikRoot() throws IOException, URISyntaxException { return resolvePath("/server"); } private static Path resolvePath(String entry) throws IOException, URISyntaxException { URL entryURL = getContext().getBundle().getEntry(entry); URL entryFileURL = FileLocator.toFileURL(entryURL); URI encodedUri = new URI(entryFileURL.getProtocol(), entryFileURL.getPath(), null).normalize(); return Paths.get(encodedUri); } public static Activator getDefault() { return defaultt; } }