1 11 package org.eclipse.osgi.framework.adaptor.core; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 import java.net.MalformedURLException ; 16 import java.net.URL ; 17 import java.util.*; 18 19 23 public final class DevClassPathHelper { 24 static private boolean inDevelopmentMode = false; 25 static private String [] devDefaultClasspath; 26 static private Dictionary devProperties = null; 27 28 static { 29 String osgiDev = System.getProperty("osgi.dev"); if (osgiDev != null) { 32 try { 33 inDevelopmentMode = true; 34 URL location = new URL (osgiDev); 35 devProperties = load(location); 36 if (devProperties != null) 37 devDefaultClasspath = getArrayFromList((String ) devProperties.get("*")); } catch (MalformedURLException e) { 39 devDefaultClasspath = getArrayFromList(osgiDev); 40 } 41 } 42 } 43 44 private static String [] getDevClassPath(String id, Dictionary properties, String [] defaultClasspath) { 45 String [] result = null; 46 if (id != null && properties != null) { 47 String entry = (String ) properties.get(id); 48 if (entry != null) 49 result = getArrayFromList(entry); 50 } 51 if (result == null) 52 result = defaultClasspath; 53 return result; 54 } 55 56 63 public static String [] getDevClassPath(String id, Dictionary properties) { 64 if (properties == null) 65 return getDevClassPath(id, devProperties, devDefaultClasspath); 66 return getDevClassPath(id, properties, getArrayFromList((String ) properties.get("*"))); } 68 69 74 public static String [] getDevClassPath(String id) { 75 return getDevClassPath(id, null); 76 } 77 78 84 public static String [] getArrayFromList(String prop) { 85 if (prop == null || prop.trim().equals("")) return new String [0]; 87 Vector list = new Vector(); 88 StringTokenizer tokens = new StringTokenizer(prop, ","); while (tokens.hasMoreTokens()) { 90 String token = tokens.nextToken().trim(); 91 if (!token.equals("")) list.addElement(token); 93 } 94 return list.isEmpty() ? new String [0] : (String []) list.toArray(new String [list.size()]); 95 } 96 97 101 public static boolean inDevelopmentMode() { 102 return inDevelopmentMode; 103 } 104 105 108 private static Properties load(URL url) { 109 Properties props = new Properties(); 110 try { 111 InputStream is = null; 112 try { 113 is = url.openStream(); 114 props.load(is); 115 } finally { 116 if (is != null) 117 is.close(); 118 } 119 } catch (IOException e) { 120 } 122 return props; 123 } 124 } 125 | Popular Tags |