public void load(Ruby runtime, boolean wrap) {
RubyModule configModule = runtime.defineModule("Config");
configModule.defineAnnotatedMethods(RbConfigLibrary.class);
RubyHash configHash = RubyHash.newHash(runtime);
configModule.defineConstant("CONFIG", configHash);
runtime.getObject().defineConstant("RbConfig", configModule);
String[] versionParts = Constants.RUBY_VERSION.split("\\.");
setConfig(configHash, "MAJOR", versionParts[0]);
setConfig(configHash, "MINOR", versionParts[1]);
setConfig(configHash, "TEENY", versionParts[2]);
setConfig(configHash, "ruby_version", versionParts[0] + '.' + versionParts[1]);
// Rubygems is too specific on host cpu so until we have real need lets default to universal
//setConfig(configHash, "arch", System.getProperty("os.arch") + "-java" + System.getProperty("java.specification.version"));
setConfig(configHash, "arch", "universal-java" + System.getProperty("java.specification.version"));
String normalizedHome;
if (Ruby.isSecurityRestricted()) {
normalizedHome = "SECURITY RESTRICTED";
} else {
normalizedHome = runtime.getJRubyHome();
}
setConfig(configHash, "bindir", new NormalizedFile(normalizedHome, "bin").getPath());
setConfig(configHash, "RUBY_INSTALL_NAME", jrubyScript());
setConfig(configHash, "ruby_install_name", jrubyScript());
setConfig(configHash, "SHELL", jrubyShell());
setConfig(configHash, "prefix", normalizedHome);
setConfig(configHash, "exec_prefix", normalizedHome);
setConfig(configHash, "host_os", getOSName());
setConfig(configHash, "host_vendor", System.getProperty("java.vendor"));
setConfig(configHash, "host_cpu", Platform.ARCH);
setConfig(configHash, "target_os", getOSName());
setConfig(configHash, "target_cpu", Platform.ARCH);
String jrubyJarFile = "jruby.jar";
URL jrubyPropertiesUrl = Ruby.getClassLoader().getResource(Constants.JRUBY_PROPERTIES);
if (jrubyPropertiesUrl != null) {
Pattern jarFile = Pattern.compile("jar:file:.*?([a-zA-Z0-9.\\-]+\\.jar)!" + Constants.JRUBY_PROPERTIES);
Matcher jarMatcher = jarFile.matcher(jrubyPropertiesUrl.toString());
jarMatcher.find();
if (jarMatcher.matches()) {
jrubyJarFile = jarMatcher.group(1);
}
}
setConfig(configHash, "LIBRUBY", jrubyJarFile);
setConfig(configHash, "LIBRUBY_SO", jrubyJarFile);
setConfig(configHash, "build", Constants.BUILD);
setConfig(configHash, "target", Constants.TARGET);
String libdir = System.getProperty("jruby.lib");
if (libdir == null) {
libdir = new NormalizedFile(normalizedHome, "lib").getPath();
} else {
try {
// Our shell scripts pass in non-canonicalized paths, but even if we didn't
// anyone who did would become unhappy because Ruby apps expect no relative
// operators in the pathname (rubygems, for example).
libdir = new NormalizedFile(libdir).getCanonicalPath();
} catch (IOException e) {
libdir = new NormalizedFile(libdir).getAbsolutePath();
}
}
String rubyLibDir = new NormalizedFile(libdir, "ruby/1.8").getPath();
String siteDir = new NormalizedFile(libdir, "ruby/site_ruby").getPath();
String siteLibDir = new NormalizedFile(libdir, "ruby/site_ruby/1.8").getPath();
String siteArchDir = new NormalizedFile(libdir, "ruby/site_ruby/1.8/java").getPath();
String archDir = new NormalizedFile(libdir, "ruby/1.8/java").getPath();
setConfig(configHash, "libdir", libdir);
setConfig(configHash, "rubylibdir", rubyLibDir);
setConfig(configHash, "sitedir", siteDir);
setConfig(configHash, "sitelibdir", siteLibDir);
setConfig(configHash, "sitearchdir", siteArchDir);
setConfig(configHash, "archdir", archDir);
setConfig(configHash, "topdir", archDir);
setConfig(configHash, "configure_args", "");
setConfig(configHash, "datadir", new NormalizedFile(normalizedHome, "share").getPath());
setConfig(configHash, "mandir", new NormalizedFile(normalizedHome, "man").getPath());
setConfig(configHash, "sysconfdir", new NormalizedFile(normalizedHome, "etc").getPath());
setConfig(configHash, "localstatedir", new NormalizedFile(normalizedHome, "var").getPath());
setConfig(configHash, "DLEXT", "jar");
if (Platform.IS_WINDOWS) {
setConfig(configHash, "EXEEXT", ".exe");
} else {
setConfig(configHash, "EXEEXT", "");
}
RubyHash mkmfHash = RubyHash.newHash(runtime);
setConfig(mkmfHash, "libdir", libdir);
setConfig(mkmfHash, "arch", "java");
setConfig(mkmfHash, "rubylibdir", rubyLibDir);