package org.eclipse.core.internal.runtime;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
public class DevClassPathHelper {
public static final String PROP_DEV = "osgi.dev";
static protected boolean inDevelopmentMode = false;
static protected String[] devDefaultClasspath;
static protected Properties devProperties = null;
static {
String osgiDev = Activator.getContext() == null ? System.getProperty(PROP_DEV) : Activator.getContext().getProperty(PROP_DEV);
if (osgiDev != null) {
try {
inDevelopmentMode = true;
URL location = new URL(osgiDev);
devProperties = load(location);
if (devProperties != null)
devDefaultClasspath = getArrayFromList(devProperties.getProperty("*"));
} catch (MalformedURLException e) {
devDefaultClasspath = getArrayFromList(osgiDev);
}
}
}
public static String[] getDevClassPath(String id) {
String[] result = null;
if (id != null && devProperties != null) {
String entry = devProperties.getProperty(id);
if (entry != null)
result = getArrayFromList(entry);
}
if (result == null)
result = devDefaultClasspath;
return result;
}
public static String[] getArrayFromList(String prop) {
if (prop == null || prop.trim().equals(""))
return new String[0];
Vector<String> list = new Vector<>();
StringTokenizer tokens = new StringTokenizer(prop, ",");
while (tokens.hasMoreTokens()) {
String token = tokens.nextToken().trim();
if (!token.equals(""))
list.addElement(token);
}
return list.isEmpty() ? new String[0] : (String[]) list.toArray(new String[list.size()]);
}
public static boolean inDevelopmentMode() {
return inDevelopmentMode;
}
private static Properties load(URL url) {
Properties props = new Properties();
try {
InputStream is = null;
try {
is = url.openStream();
props.load(is);
} finally {
if (is != null)
is.close();
}
} catch (IOException e) {
}
return props;
}
}