1 11 package org.eclipse.osgi.framework.internal.defaultadaptor; 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 public class DevClassPathHelper { 20 static protected boolean inDevelopmentMode = false; 21 static protected String [] devDefaultClasspath; 22 static protected Properties devProperties = null; 23 24 static { 25 String osgiDev = System.getProperty("osgi.dev"); if (osgiDev != null) { 28 try { 29 inDevelopmentMode = true; 30 URL location = new URL (osgiDev); 31 devProperties = load(location); 32 if (devProperties != null) 33 devDefaultClasspath = getArrayFromList(devProperties.getProperty("*")); } catch (MalformedURLException e) { 35 devDefaultClasspath = getArrayFromList(osgiDev); 36 } 37 } 38 } 39 40 public static String [] getDevClassPath(String id) { 41 String [] result = null; 42 if (id != null && devProperties != null) { 43 String entry = devProperties.getProperty(id); 44 if (entry != null) 45 result = getArrayFromList(entry); 46 } 47 if (result == null) 48 result = devDefaultClasspath; 49 return result; 50 } 51 52 58 public static String [] getArrayFromList(String prop) { 59 if (prop == null || prop.trim().equals("")) return new String [0]; 61 Vector list = new Vector(); 62 StringTokenizer tokens = new StringTokenizer(prop, ","); while (tokens.hasMoreTokens()) { 64 String token = tokens.nextToken().trim(); 65 if (!token.equals("")) list.addElement(token); 67 } 68 return list.isEmpty() ? new String [0] : (String []) list.toArray(new String [list.size()]); 69 } 70 71 public static boolean inDevelopmentMode() { 72 return inDevelopmentMode; 73 } 74 75 78 private static Properties load(URL url) { 79 Properties props = new Properties(); 80 try { 81 InputStream is = null; 82 try { 83 is = url.openStream(); 84 props.load(is); 85 } finally { 86 is.close(); 87 } 88 } catch (IOException e) { 89 } 91 return props; 92 } 93 } | Popular Tags |