Example #1
0
  public static void createTemplate(Ruby runtime, RubyModule mASN1) {
    mTemplate = runtime.defineModuleUnder("Template", mASN1);
    RubyModule mParser = runtime.defineModuleUnder("Parser", mTemplate);
    cTemplateValue =
        mTemplate.defineClassUnder(
            "Value", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);

    CODEC = runtime.newSymbol("codec");
    OPTIONS = runtime.newSymbol("options");
    DEFAULT = runtime.newSymbol("default");
    NAME = runtime.newSymbol("name");
    TYPE = runtime.newSymbol("type");
    OPTIONAL = runtime.newSymbol("optional");
    TAG = runtime.newSymbol("tag");
    TAGGING = runtime.newSymbol("tagging");
    LAYOUT = runtime.newSymbol("layout");
    MIN_SIZE = runtime.newSymbol("min_size");

    CODEC_PRIMITIVE = runtime.newSymbol("PRIMITIVE");
    CODEC_TEMPLATE = runtime.newSymbol("TEMPLATE");
    CODEC_SEQUENCE = runtime.newSymbol("SEQUENCE");
    CODEC_SET = runtime.newSymbol("SET");
    CODEC_SEQUENCE_OF = runtime.newSymbol("SEQUENCE_OF");
    CODEC_SET_OF = runtime.newSymbol("SET_OF");
    CODEC_ANY = runtime.newSymbol("ANY");
    CODEC_CHOICE = runtime.newSymbol("CHOICE");

    mTemplate.defineAnnotatedMethods(RubyAsn1Template.class);
    mParser.defineAnnotatedMethods(TemplateParser.class);
    cTemplateValue.defineAnnotatedMethods(RubyAsn1Template.class);
  }
Example #2
0
  public void load(Ruby runtime, boolean wrap) throws IOException {
    RubyModule timeout = runtime.defineModule("Timeout");
    RubyClass superclass = runtime.getRuntimeError();
    RubyClass timeoutError =
        runtime.defineClassUnder("Error", superclass, superclass.getAllocator(), timeout);
    runtime.defineClassUnder(
        "ExitException", runtime.getException(), runtime.getException().getAllocator(), timeout);

    // Here we create an "anonymous" exception type used for unrolling the stack.
    // MRI creates a new one for *every call* to timeout, which can be costly.
    // We opt to use a single exception type for all cases to avoid this overhead.
    RubyClass anonEx =
        runtime.defineClassUnder(
            "AnonymousException",
            runtime.getException(),
            runtime.getException().getAllocator(),
            timeout);
    anonEx.setBaseName(null); // clear basename so it's anonymous when raising

    // These are not really used by timeout, but exposed for compatibility
    timeout.defineConstant(
        "THIS_FILE", RubyRegexp.newRegexp(runtime, "timeout\\.rb", new RegexpOptions()));
    timeout.defineConstant("CALLER_OFFSET", RubyFixnum.newFixnum(runtime, 0));

    // Timeout module methods
    timeout.defineAnnotatedMethods(Timeout.class);

    // Toplevel defines
    runtime.getObject().defineConstant("TimeoutError", timeoutError);
    runtime.getObject().defineAnnotatedMethods(TimeoutToplevel.class);
  }
  public static void create(Ruby runtime) {
    RubyModule mNet = runtime.getModule("Net");

    RubyClass cBufferedIO = (RubyClass) mNet.getConstant("BufferedIO");
    cBufferedIO.defineAnnotatedMethods(NetProtocolBufferedIO.class);

    RubyModule mNativeImpl = cBufferedIO.defineModuleUnder("NativeImplementation");

    mNativeImpl.defineAnnotatedMethods(NativeImpl.class);
  }
  @Override
  public boolean basicLoad(final Ruby ruby) throws IOException {
    RubyModule jr_jackson = ruby.defineModule("JrJackson");

    RubyModule jr_jackson_raw = ruby.defineModuleUnder("Raw", jr_jackson);
    jr_jackson_raw.defineAnnotatedMethods(JrJacksonRaw.class);

    RubyClass runtimeError = ruby.getRuntimeError();
    RubyClass parseError =
        jr_jackson.defineClassUnder("ParseError", runtimeError, runtimeError.getAllocator());
    return true;
  }
Example #5
0
  public static void createPKey(Ruby runtime, RubyModule ossl) {
    RubyModule _PKey = ossl.defineModuleUnder("PKey");
    _PKey.defineAnnotatedMethods(PKeyModule.class);
    // PKey is abstract
    RubyClass _PKeyPkey =
        _PKey.defineClassUnder(
            "PKey", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
    RubyClass _OpenSSLError = ossl.getClass("OpenSSLError");
    _PKey.defineClassUnder("PKeyError", _OpenSSLError, _OpenSSLError.getAllocator());

    _PKeyPkey.defineAnnotatedMethods(PKey.class);

    PKeyRSA.createPKeyRSA(runtime, _PKey);
    PKeyDSA.createPKeyDSA(runtime, _PKey);
    PKeyDH.createPKeyDH(runtime, _PKey, _PKeyPkey);
  }
Example #6
0
  public static void createReadline(Ruby runtime) throws IOException {
    ConsoleHolder holder = new ConsoleHolder();
    holder.history = new ReadlineHistory();
    holder.currentCompletor = null;
    COMPLETION_CASE_FOLD = runtime.getNil();

    RubyModule mReadline = runtime.defineModule("Readline");

    mReadline.dataWrapStruct(holder);

    mReadline.defineAnnotatedMethods(Readline.class);
    IRubyObject hist = runtime.getObject().callMethod(runtime.getCurrentContext(), "new");
    mReadline.fastSetConstant("HISTORY", hist);
    hist.getSingletonClass().includeModule(runtime.getEnumerable());
    hist.getSingletonClass().defineAnnotatedMethods(HistoryMethods.class);

    // MRI does similar thing on MacOS X with 'EditLine wrapper'.
    mReadline.fastSetConstant("VERSION", runtime.newString("JLine wrapper"));
  }
Example #7
0
  /**
   * Just enough configuration settings (most don't make sense in Java) to run the rubytests unit
   * tests. The tests use <code>bindir</code>, <code>RUBY_INSTALL_NAME</code> and <code>EXEEXT
   * </code>.
   */
  public void load(Ruby runtime, boolean wrap) {
    RubyModule configModule;

    configModule = runtime.defineModule("RbConfig");
    RubyKernel.autoload(
        runtime.getObject(),
        runtime.newSymbol("Config"),
        runtime.newString("rbconfig/obsolete.rb"));

    configModule.defineAnnotatedMethods(RbConfigLibrary.class);

    RubyHash configHash = RubyHash.newHash(runtime);
    configModule.defineConstant("CONFIG", configHash);

    String[] versionParts;
    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] + ".0");
    // 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"));

    normalizedHome = getNormalizedHome(runtime);

    // Use property for binDir if available, otherwise fall back to common bin default
    String binDir = SafePropertyAccessor.getProperty("jruby.bindir");
    if (binDir == null) {
      binDir = new NormalizedFile(normalizedHome, "bin").getPath();
    }
    setConfig(configHash, "bindir", binDir);

    setConfig(configHash, "RUBY_INSTALL_NAME", jrubyScript());
    setConfig(configHash, "RUBYW_INSTALL_NAME", IS_WINDOWS ? "jrubyw.exe" : jrubyScript());
    setConfig(configHash, "ruby_install_name", jrubyScript());
    setConfig(configHash, "rubyw_install_name", IS_WINDOWS ? "jrubyw.exe" : 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", getArchitecture());

    setConfig(configHash, "target_os", getOSName());

    setConfig(configHash, "target_cpu", getArchitecture());

    String jrubyJarFile = "jruby.jar";
    URL jrubyPropertiesUrl = Ruby.getClassLoader().getResource("/org/jruby/Ruby.class");
    if (jrubyPropertiesUrl != null) {
      Pattern jarFile =
          Pattern.compile("jar:file:.*?([a-zA-Z0-9.\\-]+\\.jar)!" + "/org/jruby/Ruby.class");
      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, "LIBRUBY_SO", jrubyJarFile);
    setConfig(configHash, "LIBRUBY_ALIASES", jrubyJarFile);

    setConfig(configHash, "build", Constants.BUILD);
    setConfig(configHash, "target", Constants.TARGET);

    String shareDir = new NormalizedFile(normalizedHome, "share").getPath();
    String includeDir = new NormalizedFile(normalizedHome, "lib/native/" + getOSName()).getPath();

    String vendorDirGeneral = getVendorDirGeneral(runtime);
    String siteDirGeneral = getSiteDirGeneral(runtime);
    String rubySharedLibDir = getRubySharedLibDir(runtime);
    String rubyLibDir = getRubyLibDir(runtime);
    String archDir = getArchDir(runtime);
    String vendorDir = getVendorDir(runtime);
    String vendorLibDir = getVendorLibDir(runtime);
    String vendorArchDir = getVendorArchDir(runtime);
    String siteDir = getSiteDir(runtime);
    String siteLibDir = getSiteLibDir(runtime);
    String siteArchDir = getSiteArchDir(runtime);
    String sysConfDir = getSysConfDir(runtime);

    setConfig(configHash, "libdir", vendorDirGeneral);
    setConfig(configHash, "rubylibprefix", vendorDirGeneral + "/ruby");
    setConfig(configHash, "rubylibdir", rubyLibDir);
    setConfig(configHash, "rubysharedlibdir", rubySharedLibDir);
    if (!isSiteVendorSame(runtime)) {
      setConfig(configHash, "vendordir", vendorDir);
      setConfig(configHash, "vendorlibdir", vendorLibDir);
      setConfig(configHash, "vendorarchdir", vendorArchDir);
    }
    setConfig(configHash, "sitedir", siteDir);
    setConfig(configHash, "sitelibdir", siteLibDir);
    setConfig(configHash, "sitearchdir", siteArchDir);
    setConfig(configHash, "sitearch", "java");
    setConfig(configHash, "archdir", archDir);
    setConfig(configHash, "topdir", archDir);
    setConfig(configHash, "includedir", includeDir);
    setConfig(configHash, "configure_args", "");
    setConfig(configHash, "datadir", shareDir);
    setConfig(configHash, "mandir", new NormalizedFile(normalizedHome, "man").getPath());
    setConfig(configHash, "sysconfdir", sysConfDir);
    setConfig(configHash, "localstatedir", new NormalizedFile(normalizedHome, "var").getPath());
    setConfig(configHash, "DLEXT", "jar");
    if (getRubygemsDir(runtime) != null) {
      setConfig(configHash, "rubygemsdir", new NormalizedFile(getRubygemsDir(runtime)).getPath());
    }

    if (Platform.IS_WINDOWS) {
      setConfig(configHash, "EXEEXT", ".exe");
    } else {
      setConfig(configHash, "EXEEXT", "");
    }

    setConfig(configHash, "ridir", new NormalizedFile(shareDir, "ri").getPath());

    // These will be used as jruby defaults for rubygems if found
    String gemhome = SafePropertyAccessor.getProperty("jruby.gem.home");
    String gempath = SafePropertyAccessor.getProperty("jruby.gem.path");
    if (gemhome != null) setConfig(configHash, "default_gem_home", gemhome);
    if (gempath != null) setConfig(configHash, "default_gem_path", gempath);

    setConfig(configHash, "joda-time.version", Constants.JODA_TIME_VERSION);
    setConfig(configHash, "tzdata.version", Constants.TZDATA_VERSION);

    RubyHash mkmfHash = RubyHash.newHash(runtime);

    setConfig(mkmfHash, "libdir", vendorDirGeneral);
    setConfig(mkmfHash, "arch", "java");
    setConfig(mkmfHash, "rubylibdir", rubyLibDir);
    setConfig(mkmfHash, "rubysharedlibdir", rubySharedLibDir);
    if (!isSiteVendorSame(runtime)) {
      setConfig(mkmfHash, "vendordir", vendorDir);
      setConfig(mkmfHash, "vendorlibdir", vendorLibDir);
      setConfig(mkmfHash, "vendorarchdir", vendorArchDir);
    }
    setConfig(mkmfHash, "sitedir", siteDir);
    setConfig(mkmfHash, "sitelibdir", siteLibDir);
    setConfig(mkmfHash, "sitearchdir", siteArchDir);
    setConfig(mkmfHash, "sitearch", "java");
    setConfig(mkmfHash, "archdir", archDir);
    setConfig(mkmfHash, "topdir", archDir);
    setConfig(mkmfHash, "configure_args", "");
    setConfig(mkmfHash, "datadir", new NormalizedFile(normalizedHome, "share").getPath());
    setConfig(mkmfHash, "mandir", new NormalizedFile(normalizedHome, "man").getPath());
    setConfig(mkmfHash, "sysconfdir", sysConfDir);
    setConfig(mkmfHash, "localstatedir", new NormalizedFile(normalizedHome, "var").getPath());
    if (getRubygemsDir(runtime) != null) {
      setConfig(mkmfHash, "rubygemsdir", new NormalizedFile(getRubygemsDir(runtime)).getPath());
    }

    setupMakefileConfig(configModule, mkmfHash);

    runtime.getLoadService().load("jruby/kernel/rbconfig.rb", false);
  }
 /**
  * Load the method definitions into the boolean module.
  *
  * @param bson The bson module to define the methods under.
  * @since 2.0.0
  */
 public static void extend(final RubyModule bson) {
   RubyModule falseMod = bson.defineOrGetModuleUnder(FALSE_CLASS);
   RubyModule trueMod = bson.defineOrGetModuleUnder(TRUE_CLASS);
   falseMod.defineAnnotatedMethods(BooleanExtension.class);
   trueMod.defineAnnotatedMethods(BooleanExtension.class);
 }
Example #9
0
 public static void createHex(Ruby runtime, RubyModule krypt, RubyClass kryptError) {
   RubyModule mHex = runtime.defineModuleUnder("Hex", krypt);
   mHex.defineClassUnder("HexError", kryptError, kryptError.getAllocator());
   mHex.defineAnnotatedMethods(RubyHex.class);
 }