]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.fastlz/src/org/simantics/fastlz/bundle/Activator.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.fastlz / src / org / simantics / fastlz / bundle / Activator.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.fastlz.bundle;
13
14 import java.io.File;
15 import java.io.FileNotFoundException;
16 import java.net.URL;
17 import java.net.URLDecoder;
18
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;
27
28 /**
29  * An OSGi bundle activator for that guarantees the FastLZ library is
30  * initialized after this bundle is properly activated.
31  */
32 public class Activator implements BundleActivator {
33
34     @Override
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);
40         if (libURL == 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);
45             if (libURL == null)
46                 throw new FileNotFoundException(path + " not found in bundle " + context.getBundle().getSymbolicName());
47         }
48         URL fileURL = FileLocator.toFileURL(libURL);
49         File filePath = new File(URLDecoder.decode(fileURL.getPath(), "UTF-8"));
50         FastLZ.initialize(filePath);
51         
52     }
53
54     @Override
55     public void stop(BundleContext context) throws Exception {
56     }
57
58 }