// look to see if WEKA_HOME has been defined as an environment
// variable
Environment env = Environment.getSystemWide();
String wh = env.getVariableValue("WEKA_HOME");
if (wh != null) {
WEKA_HOME = new File(wh);
PACKAGES_DIR = new File(wh + File.separator + "packages");
} else {
env.addVariableSystemWide("WEKA_HOME", WEKA_HOME.toString());
}
boolean ok = true;
if (!WEKA_HOME.exists()) {
// create it for the user
if (!WEKA_HOME.mkdir()) {
System.err.println("Unable to create WEKA_HOME ("
+ WEKA_HOME.getAbsolutePath() + ")");
ok = false;
}
}
if (!PACKAGES_DIR.exists()) {
// create the packages dir
if (!PACKAGES_DIR.mkdir()) {
System.err.println("Unable to create packages directory ("
+ PACKAGES_DIR.getAbsolutePath() + ")");
ok = false;
}
}
m_wekaHomeEstablished = ok;
PACKAGE_MANAGER.setPackageHome(PACKAGES_DIR);
try {
String repURL = env.getVariableValue("weka.core.wekaPackageRepositoryURL");
if (repURL == null || repURL.length() == 0) {
// See if there is a URL named in $WEKA_HOME/props/PackageRepository.props
File repPropsFile = new File(PROPERTIES_DIR.toString() + File.separator
+ "PackageRepository.props");
if (repPropsFile.exists()) {
Properties repProps = new Properties();
repProps.load(new FileInputStream(repPropsFile));
repURL = repProps.getProperty("weka.core.wekaPackageRepositoryURL");
}
}
if (repURL == null || repURL.length() == 0) {
repURL = "http://weka.sourceforge.net/packageMetaData";
} else {
System.err.println("weka.core.WekaPackageRepositoryURL = " + repURL);
}
REP_URL = new URL(repURL);
PACKAGE_MANAGER.setPackageRepositoryURL(REP_URL);
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
PACKAGE_MANAGER.setBaseSystemName("weka");
PACKAGE_MANAGER.setBaseSystemVersion(weka.core.Version.VERSION);
// Now check the cache and establish it if necessary
File cacheDir = new File(WEKA_HOME.toString() + File.separator
+ "repCache");
try {
String tempCacheString = "file://" + cacheDir.toString();
// sanitize URI and fix slashes (for Windows)
tempCacheString = tempCacheString.replace(" ", "%20");
tempCacheString = tempCacheString.replace('\\', '/');
if (tempCacheString.startsWith("file://") && !tempCacheString.startsWith("file:///")) {
tempCacheString = tempCacheString.substring(7);
tempCacheString = "file:///" + tempCacheString;
}
URI tempURI = new URI(tempCacheString);
// System.err.println(" -- " + tempURI.toString());
CACHE_URL = tempURI.toURL();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (!cacheDir.exists()) {
if (!cacheDir.mkdir()) {
System.err.println("Unable to create repository cache directory ("
+ cacheDir.getAbsolutePath() + ")");
CACHE_URL = null;
} else {
// refreshCache();
INITIAL_CACHE_BUILD_NEEDED = true;
}