]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils/src/org/simantics/utils/LibraryPathUtils.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils / src / org / simantics / utils / LibraryPathUtils.java
index 4e68c68f520219703c8e14221cdd6d4def6189e4..0cb55be6484e059a14859b974fdeba70948b3242 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.utils;\r
-\r
-import java.io.File;\r
-import java.util.Properties;\r
-\r
-/**\r
- * \r
- * @author Toni Kalajainen\r
- */\r
-public class LibraryPathUtils {\r
-\r
-    // The problem with JMF is that it is (should be)\r
-    // Located in Java CLASSPATH. For some reason eclipse java VM does not\r
-    // Look into CLASSPATH.\r
-    // The following code adds CLASSPATH to System enviroment java.library.path\r
-    public static void addCLASSPATHtoEclipseVariables() {\r
-        String CLASSPATH = System.getenv("CLASSPATH");\r
-        if (CLASSPATH != null)\r
-            for (String classPath : CLASSPATH.split(";")) {\r
-                if (!classPath.toLowerCase().endsWith(".jar"))\r
-                    addLibraryPath(classPath);\r
-                addClassPath(classPath);\r
-            }\r
-        CLASSPATH = System.getenv("PATH");\r
-        if (CLASSPATH != null)\r
-            for (String classPath : CLASSPATH.split(";")) {\r
-                addLibraryPath(classPath);\r
-            }\r
-        // On linux\r
-        CLASSPATH = System.getenv("LD_LIBRARY_PATH");\r
-        if (CLASSPATH != null)\r
-            for (String classPath : CLASSPATH.split(";")) {\r
-                addLibraryPath(classPath);\r
-            }\r
-\r
-        // printEnvVariables();\r
-    }\r
-\r
-    public static void addLibraryPath(String newLibrary) {\r
-        if (newLibrary == null || "".equals(newLibrary))\r
-            return;\r
-        String java_library_path = System.getProperty("java.library.path");\r
-        if (java_library_path != null) {\r
-            for (String library : java_library_path.split(";"))\r
-                if (library.equals(newLibrary))\r
-                    return;\r
-        }\r
-\r
-        // System.out.println("Adding path: " + newLibrary);\r
-\r
-        if (java_library_path == null || "".equals(java_library_path))\r
-            java_library_path = newLibrary;\r
-        else {\r
-            if (!java_library_path.endsWith(";"))\r
-                java_library_path += ";";\r
-            java_library_path += newLibrary + ";";\r
-        }\r
-\r
-        System.setProperty("java.library.path", java_library_path);\r
-    }\r
-\r
-    public static void addClassPath(String newLibrary) {\r
-        if (newLibrary == null || "".equals(newLibrary))\r
-            return;\r
-        String java_library_path = System.getProperty("java.class.path");\r
-        if (java_library_path != null) {\r
-            for (String library : java_library_path.split(";"))\r
-                if (library.equals(newLibrary))\r
-                    return;\r
-        }\r
-\r
-        // System.out.println("Adding cp: " + newLibrary);\r
-\r
-        if (java_library_path == null || "".equals(java_library_path))\r
-            java_library_path = newLibrary;\r
-        else {\r
-            if (!java_library_path.endsWith(";"))\r
-                java_library_path += ";";\r
-            java_library_path += newLibrary + ";";\r
-        }\r
-\r
-        System.setProperty("java.class.path", java_library_path);\r
-    }\r
-\r
-    public static void printEnvVariables() {\r
-        // Add env variable CLASSPATH\r
-        Properties props = System.getProperties();\r
-        for (Object key : props.keySet()) {\r
-            Object value = props.get(key);\r
-            System.out.println(key + "=" + value);\r
-        }\r
-\r
-        System.out.println("\n\nEnv:");\r
-        for (Object key : System.getenv().keySet()) {\r
-            Object value = System.getenv().get(key);\r
-            System.out.println(key + "=" + value);\r
-        }\r
-    }\r
-\r
-    /**\r
-     * Find location of a jar library\r
-     * \r
-     * @param library name of the library\r
-     * @return full location of the library\r
-     */\r
-    public static String findLibrary(String library) {\r
-        String CLASSPATH = System.getenv("CLASSPATH");\r
-\r
-        if (CLASSPATH == null)\r
-            return null;\r
-        // 1st search case sensitive\r
-        for (String classPath : CLASSPATH.split(";"))\r
-            if (classPath.endsWith(library))\r
-                return classPath;\r
-\r
-        // Widen search for insensitive\r
-        for (String classPath : CLASSPATH.split(";"))\r
-            if (classPath.toLowerCase().endsWith(library.toLowerCase()))\r
-                return classPath;\r
-        return null;\r
-    }       \r
-    \r
-    /**\r
-     * This method searches for CLASSPATH and converts libraries there into\r
-     * separate key,value pairs in system properties. The key will be \r
-     * name of the library and value will be it's location in file system.\r
-     *\r
-     * This method acts as a helper tool for loading external libraries into \r
-     * the visibility of bundle class loader.\r
-     * Call:\r
-     * LibraryPathUtils.createSystemPropertiesFromClassPathLibraries(); \r
-     * \r
-     * This call should be invoked at the very beginning of application. \r
-     * This way external libraries can by dynamicly loaded at runtime. \r
-     * The way to do this, is to add "external:$library.jar$" into plugin \r
-     * settings runtime/classpath, \r
-     * in Manifest.mf it is "Bundle-ClassPath: external:$library.jar$" \r
-     */\r
-    public static void createSystemPropertiesFromClassPathLibraries() {\r
-        String CLASSPATH = System.getenv("CLASSPATH");\r
-\r
-        if (CLASSPATH == null)\r
-            return;\r
-        \r
-        // 1st search case sensitive\r
-        for (String classPath : CLASSPATH.split(";")) {\r
-            //System.out.println(classPath);\r
-            if (!classPath.toLowerCase().endsWith(".jar")) continue;\r
-            File lib = new File(classPath);\r
-            if (!lib.exists()) {\r
-                //System.out.println("Warning library \""+classPath+"\" does not exist yet it exists in CLASSPATH.");\r
-                continue;\r
-            } else {\r
-            }\r
-            String key = lib.getName();\r
-            String value = lib.getAbsolutePath();\r
-            System.setProperty(key, value);\r
-            //System.out.println(key+"="+value);\r
-        }\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.utils;
+
+import java.io.File;
+import java.util.Properties;
+
+/**
+ * 
+ * @author Toni Kalajainen
+ */
+public class LibraryPathUtils {
+
+    // The problem with JMF is that it is (should be)
+    // Located in Java CLASSPATH. For some reason eclipse java VM does not
+    // Look into CLASSPATH.
+    // The following code adds CLASSPATH to System enviroment java.library.path
+    public static void addCLASSPATHtoEclipseVariables() {
+        String CLASSPATH = System.getenv("CLASSPATH");
+        if (CLASSPATH != null)
+            for (String classPath : CLASSPATH.split(";")) {
+                if (!classPath.toLowerCase().endsWith(".jar"))
+                    addLibraryPath(classPath);
+                addClassPath(classPath);
+            }
+        CLASSPATH = System.getenv("PATH");
+        if (CLASSPATH != null)
+            for (String classPath : CLASSPATH.split(";")) {
+                addLibraryPath(classPath);
+            }
+        // On linux
+        CLASSPATH = System.getenv("LD_LIBRARY_PATH");
+        if (CLASSPATH != null)
+            for (String classPath : CLASSPATH.split(";")) {
+                addLibraryPath(classPath);
+            }
+
+        // printEnvVariables();
+    }
+
+    public static void addLibraryPath(String newLibrary) {
+        if (newLibrary == null || "".equals(newLibrary))
+            return;
+        String java_library_path = System.getProperty("java.library.path");
+        if (java_library_path != null) {
+            for (String library : java_library_path.split(";"))
+                if (library.equals(newLibrary))
+                    return;
+        }
+
+        // System.out.println("Adding path: " + newLibrary);
+
+        if (java_library_path == null || "".equals(java_library_path))
+            java_library_path = newLibrary;
+        else {
+            if (!java_library_path.endsWith(";"))
+                java_library_path += ";";
+            java_library_path += newLibrary + ";";
+        }
+
+        System.setProperty("java.library.path", java_library_path);
+    }
+
+    public static void addClassPath(String newLibrary) {
+        if (newLibrary == null || "".equals(newLibrary))
+            return;
+        String java_library_path = System.getProperty("java.class.path");
+        if (java_library_path != null) {
+            for (String library : java_library_path.split(";"))
+                if (library.equals(newLibrary))
+                    return;
+        }
+
+        // System.out.println("Adding cp: " + newLibrary);
+
+        if (java_library_path == null || "".equals(java_library_path))
+            java_library_path = newLibrary;
+        else {
+            if (!java_library_path.endsWith(";"))
+                java_library_path += ";";
+            java_library_path += newLibrary + ";";
+        }
+
+        System.setProperty("java.class.path", java_library_path);
+    }
+
+    public static void printEnvVariables() {
+        // Add env variable CLASSPATH
+        Properties props = System.getProperties();
+        for (Object key : props.keySet()) {
+            Object value = props.get(key);
+            System.out.println(key + "=" + value);
+        }
+
+        System.out.println("\n\nEnv:");
+        for (Object key : System.getenv().keySet()) {
+            Object value = System.getenv().get(key);
+            System.out.println(key + "=" + value);
+        }
+    }
+
+    /**
+     * Find location of a jar library
+     * 
+     * @param library name of the library
+     * @return full location of the library
+     */
+    public static String findLibrary(String library) {
+        String CLASSPATH = System.getenv("CLASSPATH");
+
+        if (CLASSPATH == null)
+            return null;
+        // 1st search case sensitive
+        for (String classPath : CLASSPATH.split(";"))
+            if (classPath.endsWith(library))
+                return classPath;
+
+        // Widen search for insensitive
+        for (String classPath : CLASSPATH.split(";"))
+            if (classPath.toLowerCase().endsWith(library.toLowerCase()))
+                return classPath;
+        return null;
+    }       
+    
+    /**
+     * This method searches for CLASSPATH and converts libraries there into
+     * separate key,value pairs in system properties. The key will be 
+     * name of the library and value will be it's location in file system.
+     *
+     * This method acts as a helper tool for loading external libraries into 
+     * the visibility of bundle class loader.
+     * Call:
+     * LibraryPathUtils.createSystemPropertiesFromClassPathLibraries(); 
+     * 
+     * This call should be invoked at the very beginning of application. 
+     * This way external libraries can by dynamicly loaded at runtime. 
+     * The way to do this, is to add "external:$library.jar$" into plugin 
+     * settings runtime/classpath, 
+     * in Manifest.mf it is "Bundle-ClassPath: external:$library.jar$" 
+     */
+    public static void createSystemPropertiesFromClassPathLibraries() {
+        String CLASSPATH = System.getenv("CLASSPATH");
+
+        if (CLASSPATH == null)
+            return;
+        
+        // 1st search case sensitive
+        for (String classPath : CLASSPATH.split(";")) {
+            //System.out.println(classPath);
+            if (!classPath.toLowerCase().endsWith(".jar")) continue;
+            File lib = new File(classPath);
+            if (!lib.exists()) {
+                //System.out.println("Warning library \""+classPath+"\" does not exist yet it exists in CLASSPATH.");
+                continue;
+            } else {
+            }
+            String key = lib.getName();
+            String value = lib.getAbsolutePath();
+            System.setProperty(key, value);
+            //System.out.println(key+"="+value);
+        }
+    }
+
+}