1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.fastlz.bundle;
15 import java.io.FileNotFoundException;
17 import java.net.URLDecoder;
19 import org.eclipse.core.runtime.FileLocator;
20 import org.eclipse.core.runtime.IPath;
21 import org.eclipse.core.runtime.Path;
22 import org.osgi.framework.BundleActivator;
23 import org.osgi.framework.BundleContext;
24 import org.simantics.fastlz.FastLZ;
25 import org.simantics.fastlz.impl.FastLZConfig;
26 import org.simantics.fastlz.impl.OS;
29 * An OSGi bundle activator for that guarantees the FastLZ library is
30 * initialized after this bundle is properly activated.
32 public class Activator implements BundleActivator {
35 public void start(BundleContext context) throws Exception {
36 // Make sure that the FastLZ native library gets initialized properly.
37 FastLZConfig.attemptStaticInitialization = false;
38 IPath path = new Path("/" + OS.resolveLibName());
39 URL libURL = FileLocator.find(context.getBundle(), path, null);
41 // Fallback for the where org.simantics.fastlz is checked out in the
42 // development environment.
43 path = new Path("/bin/" + OS.resolveLibName());
44 libURL = FileLocator.find(context.getBundle(), path, null);
46 throw new FileNotFoundException(path + " not found in bundle " + context.getBundle().getSymbolicName());
48 URL fileURL = FileLocator.toFileURL(libURL);
49 File filePath = new File(URLDecoder.decode(fileURL.getPath(), "UTF-8"));
50 FastLZ.initialize(filePath);
55 public void stop(BundleContext context) throws Exception {