Пример #1
0
Файл: bc.c Проект: Zubnix/aura
jint JNI_CreateJavaVM(JavaVM** p_vm, JNIEnv** p_env, void* pvm_args) {
    initOptions();

    JavaVMInitArgs* vmArgs = (JavaVMInitArgs*) pvm_args;
    if (vmArgs) {
        for (int i = 0; i < vmArgs->nOptions; i++) {
            JavaVMOption* opt = &vmArgs->options[i];
            if (startsWith(opt->optionString, "-rvm:")) {
                char* arg = &opt->optionString[5];
                rvmParseOption(arg, &options);
            } else if (startsWith(opt->optionString, "-X")) {
                char* arg = &opt->optionString[2];
                rvmParseOption(arg, &options);
            } else if (startsWith(opt->optionString, "-D")) {
                char* arg = &opt->optionString[1];
                rvmParseOption(arg, &options);
            } else if (startsWith(opt->optionString, "-verbose")) {
                rvmParseOption("log=trace", &options);
            }
        }
    }

    if (!rvmInitOptions(0, NULL, &options, FALSE)) {
        return JNI_ERR;
    }

    // Start up robovm (JNI)
    Env* env = rvmStartup(&options);
    if (!env) {
        return JNI_ERR;
    }

    vm = env->vm;

    // Return values.
    if (p_vm) {
        *p_vm = &vm->javaVM;
    }
    if (p_env) {
        *p_env = &env->jni;
    }

    return JNI_OK;
}
Пример #2
0
static void parseRoboVMIni(Options* options) {
    char path[PATH_MAX];

    // Look for a robovm.ini next to the executable
    strncpy(path, options->resourcesPath, sizeof(path) - 1);
    strcat(path, "/robovm.ini");
    FILE* f = fopen(path, "r");
    if (f) {
        char* line = NULL;
        size_t linecap = 0;
        ssize_t linelen;
        while ((linelen = getline(&line, &linecap, f)) > 0) {
            line = trim(line);
            if (strlen(line) > 0 && line[0] != '#') {
                rvmParseOption(line, options);
            }
        }
        if (line) {
            free(line);
        }
        fclose(f);
    }
}
Пример #3
0
jboolean rvmInitOptions(int argc, char* argv[], Options* options, jboolean ignoreRvmArgs) {
    if (argc > 0) {
        // We're called from a RoboVM executable
        if (!realpath(argv[0], options->imagePath)) {
            return FALSE;
        }
    } else {
        // We're called via JNI. The caller could already have set
        // imagePath. If not we try to determine it via dladdr().
        if (strlen(options->imagePath) == 0) {
            Dl_info dlinfo;
            if (dladdr(rvmInitOptions, &dlinfo) == 0 || dlinfo.dli_fname == NULL) {
                rvmAbort("Could not determine image path using dladdr()");
            }
            strncpy(options->imagePath, dlinfo.dli_fname, sizeof(options->imagePath) - 1);
        }
    }

    if (strlen(options->resourcesPath) == 0) {
        strncpy(options->resourcesPath, options->imagePath, sizeof(options->resourcesPath) - 1);
        jint i = strlen(options->resourcesPath);
        while (i >= 0 && options->resourcesPath[i] != '/') {
            options->resourcesPath[i--] = '\0';
        }
        if (i >= 0 && options->resourcesPath[i] == '/') {
            options->resourcesPath[i] = '\0';
        }
        if (argc == 0) {
#if defined(DARWIN)
            // Called via JNI and on Darwin. Assume this is a framework. Use the
            // Resources folder next to the image.
            strncat(options->resourcesPath, "/Resources",
                    sizeof(options->resourcesPath) - strlen(options->resourcesPath) - 1);
#endif
        }
    }

    // Look for a robovm.ini in the resources path
    parseRoboVMIni(options);

    if (argc > 0) {
        jint firstJavaArg = 1;
        for (jint i = 1; i < argc; i++) {
            if (startsWith(argv[i], "-rvm:")) {
                if (!ignoreRvmArgs) {
                    char* arg = &argv[i][5];
                    rvmParseOption(arg, options);
                }
                firstJavaArg++;
            } else {
                break;
            }
        }

        options->commandLineArgs = NULL;
        options->commandLineArgsCount = argc - firstJavaArg;
        if (options->commandLineArgsCount > 0) {
            options->commandLineArgs = &argv[firstJavaArg];
        }

        return options->mainClass != NULL;
    }

    return TRUE;
}