1 11 package org.eclipse.help.internal.appserver; 12 13 import java.io.*; 14 import java.net.*; 15 import java.util.*; 16 17 20 public class DevClassPathHelper { 21 static protected boolean inDevelopmentMode = false; 22 static protected String [] devDefaultClasspath; 23 static protected Properties devProperties = null; 24 25 static { 26 String osgiDev = System.getProperty("osgi.dev"); if (osgiDev != null) { 30 try { 31 inDevelopmentMode = true; 32 URL location = new URL(osgiDev); 33 devProperties = load(location); 34 if (devProperties != null) 35 devDefaultClasspath = getArrayFromList(devProperties 36 .getProperty("*")); } catch (MalformedURLException e) { 38 devDefaultClasspath = getArrayFromList(osgiDev); 39 } 40 } 41 } 42 43 public static String [] getDevClassPath(String id) { 44 String [] result = null; 45 if (id != null && devProperties != null) { 46 String entry = devProperties.getProperty(id); 47 if (entry != null) 48 result = getArrayFromList(entry); 49 } 50 if (result == null) 51 result = devDefaultClasspath; 52 return result; 53 } 54 55 63 public static String [] getArrayFromList(String prop) { 64 if (prop == null || prop.trim().equals("")) return new String [0]; 66 Vector list = new Vector(); 67 StringTokenizer tokens = new StringTokenizer(prop, ","); while (tokens.hasMoreTokens()) { 69 String token = tokens.nextToken().trim(); 70 if (!token.equals("")) list.addElement(token); 72 } 73 return list.isEmpty() ? new String [0] : (String []) list 74 .toArray(new String [list.size()]); 75 } 76 77 public static boolean inDevelopmentMode() { 78 return inDevelopmentMode; 79 } 80 81 84 private static Properties load(URL url) { 85 Properties props = new Properties(); 86 try { 87 InputStream is = null; 88 try { 89 is = url.openStream(); 90 props.load(is); 91 } finally { 92 if (is != null) 93 is.close(); 94 } 95 } catch (IOException e) { 96 AppserverPlugin.logError("Help failed to load properties file " + url, e); } 98 return props; 99 } 100 } 101 | Popular Tags |