[Jsmooth-cvs] jsmooth/skeletons/commonjava JavaMachineManager.cpp, 1.18, 1.19 SunJVMDLL.cpp, 1.2, 1
Status: Beta
Brought to you by:
reyes
From: Rodrigo R. <re...@us...> - 2007-05-13 19:56:39
|
Update of /cvsroot/jsmooth/jsmooth/skeletons/commonjava In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv12151 Modified Files: JavaMachineManager.cpp SunJVMDLL.cpp SunJVMLauncher.cpp SunJVMLauncher.h Log Message: adds return code propagation Index: SunJVMLauncher.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMLauncher.cpp,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** SunJVMLauncher.cpp 1 May 2007 19:40:16 -0000 1.28 --- SunJVMLauncher.cpp 13 May 2007 19:56:35 -0000 1.29 *************** *** 47,123 **** DEBUG("Running now " + this->toString() + ", instanciate=" + (justInstanciate?"yes":"no")); ! if (VmVersion.isValid() == false) ! { ! DEBUG("No version identified for " + toString()); ! SunJVMExe exe(this->JavaHome); ! VmVersion = exe.guessVersion(); ! DEBUG("Version found: " + VmVersion.toString()); ! } ! ! if (VmVersion.isValid() == false) ! { ! DEBUG("No version found, can't instanciate DLL without it"); ! return false; ! } // patch proposed by zregvart: if you're using bundeled JVM, you // apriori know the version bundled and we can trust. The version // check is therefore unrequired. ! if (origin != "bundled") { ! Version max(resource.getProperty(ResourceManager:: KEY_MAXVERSION)); ! Version min(resource.getProperty(ResourceManager:: KEY_MINVERSION)); ! if (min.isValid() && (VmVersion < min)) ! return false; ! if (max.isValid() && (max < VmVersion)) ! return false; ! } ! DEBUG("Launching " + toString()); ! // ! // search for the dll if it's not set in the registry, or if the ! // file doesn't exist ! // ! if ( (this->JavaHome.size()>0) ! && ((this->RuntimeLibPath.size() == 0) || (!FileUtils::fileExists(this->RuntimeLibPath))) ) ! { ! std::string assump = FileUtils::concFile(this->JavaHome, "jre\\bin\\jvm.dll"); ! std::string assump2 = FileUtils::concFile(this->JavaHome, "jre\\bin\\server\\jvm.dll"); // for JRE 1.5+ ! std::string assump3 = FileUtils::concFile(this->JavaHome, "jre\\bin\\client\\jvm.dll"); // for JRE 1.5+ ! std::string assump4 = FileUtils::concFile(this->JavaHome, "bin\\javai.dll"); // For JRE 1.1 ! if (FileUtils::fileExists(assump)) ! this->RuntimeLibPath = assump; ! else if (FileUtils::fileExists(assump2)) ! this->RuntimeLibPath = assump2; ! else if (FileUtils::fileExists(assump3)) ! this->RuntimeLibPath = assump3; ! else if (FileUtils::fileExists(assump4)) ! this->RuntimeLibPath = assump4; ! else ! { ! vector<string> dlls = FileUtils::recursiveSearch(this->JavaHome, string("jvm.dll")); ! if (dlls.size() > 0) ! this->RuntimeLibPath = dlls[0]; ! } ! } ! if (FileUtils::fileExists(this->RuntimeLibPath)) ! { ! m_dllrunner = new SunJVMDLL(this->RuntimeLibPath, this->VmVersion); ! // set up the vm parameters... ! setupVM(resource, m_dllrunner); ! if (justInstanciate) ! return m_dllrunner->instanciate(); ! else ! return m_dllrunner->run(resource.getProperty(ResourceManager::KEY_MAINCLASSNAME), ! true); ! } ! return false; } --- 47,133 ---- DEBUG("Running now " + this->toString() + ", instanciate=" + (justInstanciate?"yes":"no")); ! Version max(resource.getProperty(ResourceManager:: KEY_MAXVERSION)); ! Version min(resource.getProperty(ResourceManager:: KEY_MINVERSION)); // patch proposed by zregvart: if you're using bundeled JVM, you // apriori know the version bundled and we can trust. The version // check is therefore unrequired. ! if (origin != "bundled") { ! if (VmVersion.isValid() == false) ! { ! DEBUG("No version identified for " + toString()); ! SunJVMExe exe(this->JavaHome); ! VmVersion = exe.guessVersion(); ! DEBUG("Version found: " + VmVersion.toString()); ! } ! ! if (VmVersion.isValid() == false) ! { ! DEBUG("No version found, can't instanciate DLL without it"); ! return false; ! } ! if (min.isValid() && (VmVersion < min)) ! return false; ! if (max.isValid() && (max < VmVersion)) ! return false; ! } ! DEBUG("Launching " + toString()); ! // ! // search for the dll if it's not set in the registry, or if the ! // file doesn't exist ! // ! if ( (this->JavaHome.size()>0) ! && ((this->RuntimeLibPath.size() == 0) || (!FileUtils::fileExists(this->RuntimeLibPath))) ) ! { ! std::string assump = FileUtils::concFile(this->JavaHome, "jre\\bin\\jvm.dll"); ! std::string assump2 = FileUtils::concFile(this->JavaHome, "jre\\bin\\server\\jvm.dll"); // for JRE 1.5+ ! std::string assump3 = FileUtils::concFile(this->JavaHome, "jre\\bin\\client\\jvm.dll"); // for JRE 1.5+ ! std::string assump4 = FileUtils::concFile(this->JavaHome, "bin\\javai.dll"); // For JRE 1.1 ! if (FileUtils::fileExists(assump)) ! this->RuntimeLibPath = assump; ! else if (FileUtils::fileExists(assump2)) ! this->RuntimeLibPath = assump2; ! else if (FileUtils::fileExists(assump3)) ! this->RuntimeLibPath = assump3; ! else if (FileUtils::fileExists(assump4)) ! this->RuntimeLibPath = assump4; ! else ! { ! vector<string> dlls = FileUtils::recursiveSearch(this->JavaHome, string("jvm.dll")); ! if (dlls.size() > 0) ! this->RuntimeLibPath = dlls[0]; ! } ! } ! if (FileUtils::fileExists(this->RuntimeLibPath)) ! { ! DEBUG("RuntimeLibPath used: " + this->RuntimeLibPath); ! Version v = this->VmVersion; ! if (!v.isValid()) ! { ! v = min; ! if (!v.isValid()) ! v = Version("1.2.0"); ! DEBUG("No version, trying with " + v.toString()); ! } ! m_dllrunner = new SunJVMDLL(this->RuntimeLibPath, v); ! // set up the vm parameters... ! setupVM(resource, m_dllrunner); ! if (justInstanciate) ! return m_dllrunner->instanciate(); ! else ! return m_dllrunner->run(resource.getProperty(ResourceManager::KEY_MAINCLASSNAME), ! true); ! } ! ! return false; } *************** *** 214,948 **** } - - // bool SunJVMLauncher::setupVM12DLL(ResourceManager& resource, const string& origin) - // { - // std::string jarpath = resource.saveJarInTempFile(); - // HINSTANCE vmlib = LoadLibrary(this->RuntimeLibPath.c_str()); - - // if (vmlib != 0) - // { - // DEBUG("v1.2+ type VM loaded from " +this->RuntimeLibPath); - - // CreateJavaVM_t CreateJavaVM = (CreateJavaVM_t)GetProcAddress(vmlib, "JNI_CreateJavaVM"); - // GetDefaultJavaVMInitArgs_t GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t)GetProcAddress(vmlib, "JNI_GetDefaultJavaVMInitArgs"); - - // if ((CreateJavaVM != NULL) && (GetDefaultJavaVMInitArgs != NULL)) - // { - // DEBUG("VM Created successfully"); - // JavaVM *vm = new JavaVM(); - // JNIEnv *env = new JNIEnv(); - - // // - // // create the properties array - // // - // const vector<JavaProperty>& jprops = resource.getJavaProperties(); - // vector<string> jpropstrv; - // for (int i=0; i<jprops.size(); i++) - // { - // const JavaProperty& jp = jprops[i]; - // string value = jp.getValue(); - - // value = StringUtils::replace(value, "${VMSELECTION}", origin); - // value = StringUtils::replace(value, "${VMSPAWNTYPE}", "JVMDLL"); - - // // jpropstrv.push_back("-D" + jp.getName() + "=" + StringUtils::fixQuotes(value)); - - // jpropstrv.push_back( "-D" + jp.getName() + "=" + value); - // } - - // if (resource.getProperty("maxheap") != "") - // { - // jpropstrv.push_back("-Xmx" + sizeToString(resource.getProperty("maxheap"))); // the extra space at the end would cause JNI_EINVAL return code in CreateJavaVM - - // } - // if (resource.getProperty("initialheap") != "") - // { - // jpropstrv.push_back("-Xms" + sizeToString(resource.getProperty("initialheap"))); // the extra space at the end would cause JNI_EINVAL return code in CreateJavaVM - // } - - // JavaVMInitArgs vm_args; - // GetDefaultJavaVMInitArgs(&vm_args); - - // JavaVMOption options[1 + jpropstrv.size()]; - // std::string cpoption = "-Djava.class.path="; - // string cpath = jarpath; - // string additionalcpath = resource.getNormalizedClassPath(); - // if ((cpath.size()>0) && (additionalcpath.size()>0)) - // cpath += ';'; - // if (additionalcpath.size()>0) - // cpath += additionalcpath; - // // cpoption += StringUtils::fixQuotes(cpath); - // cpoption += cpath; - // cpoption += ""; - - // DEBUG("Classpath: " + cpoption); - // options[0].optionString = (char*)cpoption.c_str(); - // vm_args.version = 0x00010002; - // vm_args.version = JNI_VERSION_1_2; - // vm_args.options = options; - // vm_args.nOptions = 1 + jpropstrv.size(); - - // for (int i=0; i<jpropstrv.size(); i++) - // { - // options[1 + i].optionString = (char*)jpropstrv[i].c_str(); - // } - // for (int i=0; i< 1+jpropstrv.size(); i++) - // { - // DEBUG(string("Option added:") + options[i].optionString); - // } - - // vm_args.ignoreUnrecognized = JNI_TRUE; - - // // - // // Create the VM - // if (CreateJavaVM( &vm, &env, &vm_args) != 0) - // { - // DEBUG("Can't create VM"); - // return false; - // } - // DEBUG("VM Created !!"); - - // jclass clstest = env->FindClass("java/lang/System"); - // if (clstest != 0) - // { - // DEBUG("Found java.lang.system !"); - // } - // else - // { - // DEBUG("java.lang.system not found"); - // return false; - // } - - // m_javavm = vm; - // m_javaenv = env; - - // this->LaunchingStatus = JVM_DLL_INSTANCIATED; - // return true; - // } - // } - // else - // { - // DEBUG("Warning: can't even load the DLL: " + this->RuntimeLibPath); - // } - - // return false; - // } - - // bool SunJVMLauncher::runVMDLL(ResourceManager& resource, const string& origin, bool justInstanciate) - // { - // DEBUG("DLL set up " + this->toString() + ", instanciate=" + (justInstanciate?"yes":"no")); - - // std::string classname = resource.getProperty(string(ResourceManager::KEY_MAINCLASSNAME)); - // classname = StringUtils::replace(classname,".", "/"); - // DEBUG("Check if " + classname + " is available"); - // jclass cls = (m_javaenv)->FindClass(classname.c_str()); - // if (cls == 0) - // { - // DEBUG(std::string("Can't Find CLASS <") + classname + std::string("> (probably a classpath issue)")); - // return false; - // } - // else - // DEBUG("OK, class " + classname + " is available"); - - // char strbuf[255]; - // sprintf(strbuf, ""); - // jstring jstr = (m_javaenv)->NewStringUTF(strbuf); - // jmethodID mid = (m_javaenv)->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V"); - - // vector<string> pargs = StringUtils::split(resource.getProperty(ResourceManager::KEY_ARGUMENTS), " \t\n\r", "\"\'"); - // for (int i=0; i<pargs.size(); i++) - // DEBUG("Argument " + StringUtils::toString(i)+" : <" + pargs[i] + ">"); - - // jobjectArray args; - - // if (pargs.size() > 0) - // { - // args = (m_javaenv)->NewObjectArray(pargs.size(), (m_javaenv)->FindClass("java/lang/String"), jstr); - // for (int i=0; i<pargs.size(); i++) - // { - // jstr = (m_javaenv)->NewStringUTF(pargs[i].c_str()); - // (m_javaenv)->SetObjectArrayElement(args, i, jstr); - // } - // } - // else - // { - // args = (m_javaenv)->NewObjectArray(0, (m_javaenv)->FindClass("java/lang/String"), jstr); - // } - - // if ((mid != 0) && (args != 0)) - // { - // DEBUG(std::string("VM OK, instanciate ? ") + (justInstanciate?"yes":"no")); - // if (justInstanciate) - // { - // return true; - // } - - // DEBUG("Calling static void main(String[]) method from " + classname); - // m_javaenv->CallStaticVoidMethod(cls, mid, args); - // DEBUG(classname + " call complete"); - // m_javavm->DestroyJavaVM(); - // DEBUG("VM destroyed"); - // return true; - // } - // else - // { - // DEBUG("Can't find method !"); - // return false; - // } - // } - - - - // bool SunJVMLauncher::setupVM11DLL(ResourceManager& resource, const string& origin) - // { - // DEBUG("Setting up a 1.1-type JVM from the DLL " + this->RuntimeLibPath); - - // std::string jarpath = resource.saveJarInTempFile(); - // std::string extracp = resource.getNormalizedClassPath(); - - // HINSTANCE vmlib = LoadLibrary(this->RuntimeLibPath.c_str()); - - // if (vmlib != 0) - // { - // DEBUG("DLL successfully loaded from " + this->RuntimeLibPath ); - // CreateJavaVM_t CreateJavaVM = (CreateJavaVM_t)GetProcAddress(vmlib, "JNI_CreateJavaVM"); - // GetDefaultJavaVMInitArgs_t GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t)GetProcAddress(vmlib, "JNI_GetDefaultJavaVMInitArgs"); - - // if ((CreateJavaVM != NULL) && (GetDefaultJavaVMInitArgs != NULL)) - // { - // DEBUG("Found the CreateJavaVM and GetDefaultJavaVMInitArgs methods in the DLL... that's good"); - - // JavaVM *javavm = new JavaVM(); - // JNIEnv *env = new JNIEnv(); - - // jint res; - // jclass cls; - // jmethodID mid; - // jstring jstr; - // jobjectArray args; - - // JDK1_1InitArgs vm_args; - // //vm_args.exit = myexit; - // vm_args.version = 0x00010001; - // GetDefaultJavaVMInitArgs(&vm_args); - - // if (resource.getProperty("maxheap") != "") - // { - // vm_args.maxHeapSize = StringUtils::parseInt(resource.getProperty("maxheap")); - // } - // if (resource.getProperty("initialheap") != "") - // { - // vm_args.minHeapSize = StringUtils::parseInt(resource.getProperty("initialheap")); - // } - - // // - // // create the properties array - // // - // const vector<JavaProperty>& jprops = resource.getJavaProperties(); - // vector<string> jpropstrv; - // for (int i=0; i<jprops.size(); i++) - // { - // const JavaProperty& jp = jprops[i]; - // string value = jp.getValue(); - - // value = StringUtils::replace(value, "${VMSELECTION}", origin); - // value = StringUtils::replace(value, "${VMSPAWNTYPE}", "JVMDLL"); - - // // jpropstrv.push_back(jp.getName() + "=" + StringUtils::fixQuotes(value)); - // jpropstrv.push_back(jp.getName() + "=" + value); - // } - - // char const * props[jprops.size()+1]; - // for (int i=0; i<jpropstrv.size(); i++) - // { - // props[i] = jpropstrv[i].c_str(); - // } - // props[jprops.size()] = NULL; - - // vm_args.properties = (char**)props; - - // /* Append USER_CLASSPATH to the default system class path */ - - // std::string classpath = vm_args.classpath; - // classpath += ";" + jarpath; - // classpath += ";" + extracp; - // DEBUG("Classpath = " + classpath); - // vm_args.classpath = (char*)classpath.c_str(); - - // /* Create the Java VM */ - // if ((res = CreateJavaVM( &javavm, &env, &vm_args)) < 0) - // { - // DEBUG("Can't create VM " + this->RuntimeLibPath); - // return false; - // } - - // DEBUG("VM 1.1 successfully created"); - - // // - // // Test java.lang.system - // if (env->FindClass("java/lang/System") == 0) - // { - // DEBUG("java.lang.system not found... aborting the VM setup"); - // return false; - // } - - // m_javavm = javavm; - // m_javaenv = env; - - // this->LaunchingStatus = JVM_DLL_INSTANCIATED; - - // return true; - // } - // } - - // return false; - // } - - // bool SunJVMLauncher::runVM11proc(ResourceManager& resource, bool noConsole, const string& origin) - // { - // DEBUG("Running process with 1.1 compatibility mode"); - - // string javapath = "bin\\java.exe"; - // string jrepath = "bin\\jre.exe"; - // if (noConsole) - // { - // javapath = "bin\\javaw.exe"; - // jrepath = "bin\\jrew.exe"; - // } - - // std::string exepath = StringUtils::requote( FileUtils::concFile(this->JavaHome, javapath) ); - // if (FileUtils::fileExists(exepath) == false) - // exepath = StringUtils::requote( FileUtils::concFile(this->JavaHome, jrepath) ); - - // if (FileUtils::fileExists(exepath)) - // { - // if (runExe(exepath, true, resource, noConsole, "1.1", origin)) - // { - // this->LaunchingStatus = JVM_PROCESS_LAUNCHED; - // return true; - // } - // } - - // return false; - // } - - // bool SunJVMLauncher::runVM12proc(ResourceManager& resource, bool noConsole, const string& origin) - // { - // string javapath = "bin\\java.exe"; - // string jrepath = "bin\\jre.exe"; - // if (noConsole) - // { - // javapath = "bin\\javaw.exe"; - // jrepath = "bin\\jrew.exe"; - // } - - // std::string exepath = StringUtils::requote( FileUtils::concFile(this->JavaHome, javapath) ); - // if (FileUtils::fileExists(exepath) == false) - // exepath = StringUtils::requote( FileUtils::concFile(this->JavaHome, jrepath) ); - - // if (FileUtils::fileExists(exepath)) - // { - // if (runExe(exepath, false, resource, noConsole, "1.2+", origin)) - // { - // this->LaunchingStatus = JVM_PROCESS_LAUNCHED; - // return true; - // } - // } - - // return false; - // } - - // bool SunJVMLauncher::runExe(const string& exepath, bool forceFullClasspath, ResourceManager& resource, bool noConsole, const string& version, const string& origin) - // { - // DEBUG("Running new proc for " + exepath); - - // string embeddedjar = resource.saveJarInTempFile(); - // DEBUG("Embedded jar saved at " + embeddedjar); - // string classpath = embeddedjar; - - // if (forceFullClasspath && (JavaHome != "")) - // { - // DEBUG("Forcing full classpath"); - // vector<string> cpzips = FileUtils::recursiveSearch(JavaHome, "*.zip"); - // for (vector<string>::iterator i=cpzips.begin(); i!=cpzips.end(); i++) - // DEBUG("ZIP FILE: " + *i); - // vector<string> cpjars = FileUtils::recursiveSearch(JavaHome, "*.jar"); - // for (vector<string>::iterator i=cpjars.begin(); i!=cpjars.end(); i++) - // DEBUG("JAR FILE: " + *i); - // vector<string> fullcp; - // fullcp.insert(fullcp.end(), cpzips.begin(), cpzips.end()); - // fullcp.insert(fullcp.end(), cpjars.begin(), cpjars.end()); - // for (vector<string>::iterator i=fullcp.begin(); i!=fullcp.end(); i++) - // DEBUG("FULL CP FILE: " + *i); - // string lcp = StringUtils::join(fullcp, ";"); - - // classpath += string(";") + lcp; - // } - - // string addcp = resource.getNormalizedClassPath(); - // classpath += ";" + addcp; - - // string addargs = resource.getProperty(ResourceManager::KEY_ARGUMENTS); - - // string javaproperties = ""; - // const vector<JavaProperty>& jprops = resource.getJavaProperties(); - // for (vector<JavaProperty>::const_iterator i=jprops.begin(); i != jprops.end(); i++) - // { - // JavaProperty jp = *i; - // string v = jp.getValue(); - - // v = StringUtils::replace(v, "${VMSELECTION}", origin); - // v = StringUtils::replace(v, "${VMSPAWNTYPE}", "PROC"); - - // string::iterator t = v.end(); - // if (*(--t) == '\\') - // v += "\\"; - - // javaproperties += " \"-D" + jp.getName() + "\"=" + StringUtils::fixQuotes(v); - // } - - // if (resource.getProperty("maxheap") != "") - // { - // if (version == "1.1") - // javaproperties += " -mx" + sizeToString(resource.getProperty("maxheap")) + " "; - // else - // javaproperties += " -Xmx" + sizeToString(resource.getProperty("maxheap")) + " "; - // } - - // if (resource.getProperty("initialheap") != "") - // { - // if (version == "1.1") - // javaproperties += " -ms" + sizeToString(resource.getProperty("initialheap")) + " "; - // else - // javaproperties += " -Xms" + sizeToString(resource.getProperty("initialheap")) + " "; - // } - - // string classname = resource.getProperty(string(ResourceManager::KEY_MAINCLASSNAME)); - // string arguments = javaproperties + " -classpath \"" + classpath + "\" " + classname + " " + addargs; - - // DEBUG("CLASSNAME = <" + classname + ">"); - // STARTUPINFO info; - // GetStartupInfo(&info); - // int creationFlags = 0; - // int inheritsHandle; - // if (noConsole == false) - // { - // info.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES; - // info.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); - // info.hStdError = GetStdHandle(STD_ERROR_HANDLE); - // info.hStdInput = GetStdHandle(STD_INPUT_HANDLE); - // creationFlags = NORMAL_PRIORITY_CLASS; - // inheritsHandle = TRUE; - // } - // else - // { - // info.dwFlags = STARTF_USESHOWWINDOW; - // creationFlags = NORMAL_PRIORITY_CLASS | DETACHED_PROCESS; - // inheritsHandle = FALSE; - // } - - // PROCESS_INFORMATION procinfo; - // string exeline = StringUtils::fixQuotes(exepath) + " " + arguments; - // int res = CreateProcess(NULL, (char*)exeline.c_str(), NULL, NULL, inheritsHandle, creationFlags, NULL, NULL, &info, &procinfo); - - // DEBUG("---------------------------------------------------"); - // DEBUG("COMMAND LINE: " +exeline); - // DEBUG("RESULT: " + StringUtils::toString(res)); - // if (res != 0) - // { - // DEBUG("WAITING: " + StringUtils::toString(res)); - // WaitForSingleObject(procinfo.hProcess, INFINITE); - // DEBUG("WAIT ENDED"); - - // if (embeddedjar.size()>0) - // { - // DEBUG("DELETING " + embeddedjar); - // DeleteFile(embeddedjar.c_str()); - // } - // return true; - // } - // else - // { - // DEBUG("Can't run " + exeline); - // } - - // if (embeddedjar.size()>0) - // { - // DEBUG("DELETING " + embeddedjar); - // DeleteFile(embeddedjar.c_str()); - // } - - // return false; - // } - - // Version SunJVMLauncher::guessVersionByProcess(const string& exepath) - // { - // Version result; - - // // Return immediatly if the exe does not exist - // if (!FileUtils::fileExists(exepath)) - // return result; - - // string tmpfilename = FileUtils::createTempFileName(".tmp"); - // SECURITY_ATTRIBUTES secattrs; - // secattrs.nLength = sizeof(SECURITY_ATTRIBUTES); - // secattrs.lpSecurityDescriptor = NULL; - // secattrs.bInheritHandle = TRUE; - - // HANDLE tmph = CreateFile(tmpfilename.c_str(), GENERIC_WRITE, - // FILE_SHARE_WRITE, &secattrs, - // CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - - // if (tmph == NULL) - // { - // DEBUG("TEMPH == NULL"); - // } - - // DEBUG("REDIRECTED TMP TO " + tmpfilename); - // STARTUPINFO info; - // GetStartupInfo(&info); - // info.hStdOutput = tmph; - // info.hStdError = tmph; - // info.wShowWindow = TRUE; - // info.dwFlags = STARTF_USESTDHANDLES; - // PROCESS_INFORMATION procinfo; - - // string exeline = exepath + " -version"; - // DEBUG("Running: " + exeline); - // int res = CreateProcess(NULL, (char*)exeline.c_str(), NULL, NULL, - // TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &info, &procinfo); - - // if (res != 0) - // { - // WaitForSingleObject(procinfo.hProcess, INFINITE); - // CloseHandle(tmph); - - // tmph = CreateFile(tmpfilename.c_str(), GENERIC_READ, - // FILE_SHARE_READ, NULL, - // OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - - // if (tmph != NULL) - // { - // DEBUG("Reading temp..."); - // char buffer[128]; - // DWORD hasread; - // buffer[127] = 0; - // if (ReadFile(tmph, buffer, 127, &hasread, NULL)) - // { - // DEBUG(string("DATA READ: ") + buffer); - // vector<string> split = StringUtils::split(buffer, " \t\n\r", "\""); - // for (vector<string>::iterator i=split.begin(); i != split.end(); i++) - // { - // Version v(*i); - // if (v.isValid()) - // { - // result = v; - // break; - // } - // } - // } - // CloseHandle(tmph); - // } - // else - // { - // DEBUG("Can't open temporary file for result"); - // } - // } - // else - // { - // DEBUG("Can't run process"); - // } - - // FileUtils::deleteOnReboot(tmpfilename); - // return result; - // } - - // std::string SunJVMLauncher::sizeToString(std::string size) - // { - // if ( (size.find('m') != string::npos) - // || (size.find('M') != string::npos) - // || (size.find('k') != string::npos) - // || (size.find('K') != string::npos) ) - // { - // return size; - // } - // else - // return sizeToString(StringUtils::parseInt(size)); - // } - - // std::string SunJVMLauncher::sizeToString(int size) - // { - // if (size > (1024*1024)) - // { - // return StringUtils::toString(size / (1024*1024)) + "m"; - // } else if (size > 1024) - // { - // return StringUtils::toString(size / 1024) + "k"; - // } else - // { - // return StringUtils::toString(size); - // } - // } - - // bool SunJVMLauncher::dllInstanciate(ResourceManager& resource, const std::string& origin) - // { - // return runVMDLL(resource, origin); - // } - - // bool SunJVMLauncher::callDLLStaticMethod(const std::string& clazz, const std::string& methodname, const std::string& signature) - // { - // JNIEnv *env = new JNIEnv(); - // jint result = m_javavm->AttachCurrentThread((void**)&env, 0); - // DEBUG("Attached thread to the VM: " + StringUtils::toString(result)); - - // // if (result != 0) - // // { - // // DEBUG("Can't attach the thread to the VM!"); - // // return false; - // // } - - // JNIEnv* jenv = env; - - // std::string classname = StringUtils::replace(clazz,".", "/"); - // DEBUG("Calling " + classname + "::" + methodname + signature); - // DEBUG("Check if " + classname + " is available"); - // jclass cls = (jenv)->FindClass(classname.c_str()); - // if (cls == 0) - // { - // DEBUG(std::string("Can't Find CLASS <") + classname + std::string("> (probably a classpath issue)")); - // return false; - // } - // else - // DEBUG("OK, class " + classname + " is available"); - - // char strbuf[255]; - // sprintf(strbuf, ""); - // jstring jstr = (jenv)->NewStringUTF(strbuf); - // jmethodID mid = (jenv)->GetStaticMethodID(cls, methodname.c_str(), signature.c_str()); - - // if (mid != 0) - // { - // DEBUG("Calling static method from " + classname); - // jenv->CallStaticVoidMethod(cls, mid); - // return true; - // } - // else - // { - // DEBUG("Can't find method !"); - // return false; - // } - - // } - - // bool SunJVMLauncher::callDLLStaticMethodInt(const std::string& clazz, const std::string& methodname, const std::string& signature, int value) - // { - // JNIEnv *env = new JNIEnv(); - // jint result = m_javavm->AttachCurrentThread((void**)&env, 0); - // DEBUG("Attached thread to the VM: " + StringUtils::toString(result)); - // JNIEnv* jenv = env; - - // std::string classname = StringUtils::replace(clazz,".", "/"); - // DEBUG("Calling " + classname + "::" + methodname + signature); - // DEBUG("Check if " + classname + " is available"); - // jclass cls = (jenv)->FindClass(classname.c_str()); - // if (cls == 0) - // { - // DEBUG(std::string("Can't Find CLASS <") + classname + std::string("> (probably a classpath issue)")); - // return false; - // } - // else - // DEBUG("OK, class " + classname + " is available"); - - // char strbuf[255]; - // sprintf(strbuf, ""); - // jstring jstr = (jenv)->NewStringUTF(strbuf); - // jmethodID mid = (jenv)->GetStaticMethodID(cls, methodname.c_str(), signature.c_str()); - - // if (mid != 0) - // { - // DEBUG("Calling static method " + methodname + " from " + classname + " (" + StringUtils::toString((int)cls) + "," + StringUtils::toString((int)mid) +")" ); - // jvalue args[5]; - // args[0].i = value; - // jint val = value; - // jenv->CallStaticVoidMethod(cls, mid, (jint)value); - // return true; - // } - // else - // { - // DEBUG("Can't find method !"); - // return false; - // } - - // } - - // int SunJVMLauncher::destroyVM() - // { - // if (m_javavm != 0) - // return m_javavm->DestroyJavaVM(); - // return -1; - // } - - // jclass SunJVMLauncher::findClass(const std::string& clazz) - // { - // JNIEnv* env = new JNIEnv(); - // jint result = m_javavm->AttachCurrentThread((void**)&env, 0); - // DEBUG("Attached thread to the VM: " + StringUtils::toString(result)); - - // JNIEnv* jenv = env; - - // std::string classname = StringUtils::replace(clazz,".", "/"); - // jclass cls = (jenv)->FindClass(classname.c_str()); - // return cls; - // } - - // jmethodID SunJVMLauncher::findMethod(jclass& cls, const std::string& methodname, const std::string& signature, bool isStatic) - // { - // JNIEnv* env = new JNIEnv(); - // jint result = m_javavm->AttachCurrentThread((void**)&env, 0); - // DEBUG("Attached thread to the VM: " + StringUtils::toString(result)); - - // JNIEnv* jenv = env; - - // jmethodID mid; - // if (isStatic) - // mid = (jenv)->GetStaticMethodID(cls, methodname.c_str(), signature.c_str()); - // else - // mid = (jenv)->GetMethodID(cls, methodname.c_str(), signature.c_str()); - - // return mid; - // } - - // JavaVM* SunJVMLauncher::getJavaVM() - // { - // return m_javavm; - // } - - // void SunJVMLauncher::invokeVoidStatic(jclass clazz, jmethodID& methodid, jvalue arguments[]) - // { - // JNIEnv *env = new JNIEnv(); - // jint result = m_javavm->AttachCurrentThread((void**)&env, 0); - // DEBUG("Attached thread to the VM: " + StringUtils::toString(result)); - // JNIEnv* jenv = env; - - // jenv->CallStaticVoidMethodA(clazz, methodid, arguments); - // } - - // jint SunJVMLauncher::invokeIntStatic(jclass clazz, jmethodID& methodid, jvalue arguments[]) - // { - // JNIEnv *env = new JNIEnv(); - // jint result = m_javavm->AttachCurrentThread((void**)&env, 0); - // DEBUG("Attached thread to the VM: " + StringUtils::toString(result)); - // JNIEnv* jenv = env; - - // return jenv->CallStaticIntMethodA(clazz, methodid, arguments); - // } - - // jlong SunJVMLauncher::invokeLongStatic(jclass clazz, jmethodID& methodid, jvalue arguments[]) - // { - // JNIEnv *env = new JNIEnv(); - // jint result = m_javavm->AttachCurrentThread((void**)&env, 0); - // DEBUG("Attached thread to the VM: " + StringUtils::toString(result)); - // JNIEnv* jenv = env; - - // return jenv->CallStaticLongMethodA(clazz, methodid, arguments); - // } --- 224,225 ---- Index: SunJVMLauncher.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMLauncher.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** SunJVMLauncher.h 1 May 2007 19:40:16 -0000 1.14 --- SunJVMLauncher.h 13 May 2007 19:56:35 -0000 1.15 *************** *** 121,125 **** std::string toString() const; - Version guessVersionByProcess(const string& exepath); friend bool operator < (const SunJVMLauncher& v1, const SunJVMLauncher& v2); --- 121,124 ---- *************** *** 128,140 **** ! bool runExe(const string& exepath, bool forceFullClasspath, ResourceManager& resource, bool noConsole, const std::string& version, const string& origin); ! bool dllInstanciate(ResourceManager& resource, const string& origin); ! bool callDLLStaticMethod(const std::string& classname, const std::string& methodname, const std::string& signature); ! bool callDLLStaticMethodInt(const std::string& classname, const std::string& methodname, const std::string& signature, int value); ! int destroyVM(); ! JavaVM* getJavaVM(); // jclass findClass(const std::string& clazz); --- 127,145 ---- + + + + // Version guessVersionByProcess(const string& exepath); + + ! // bool runExe(const string& exepath, bool forceFullClasspath, ResourceManager& resource, bool noConsole, const std::string& version, const string& origin); ! // bool dllInstanciate(ResourceManager& resource, const string& origin); ! // bool callDLLStaticMethod(const std::string& classname, const std::string& methodname, const std::string& signature); ! // bool callDLLStaticMethodInt(const std::string& classname, const std::string& methodname, const std::string& signature, int value); ! // int destroyVM(); ! // JavaVM* getJavaVM(); // jclass findClass(const std::string& clazz); *************** *** 148,158 **** private: ! bool runVMDLL(ResourceManager& resource, const string& origin, bool justInstanciate=false); ! bool setupVM12DLL(ResourceManager& resource, const string& origin); ! bool setupVM11DLL(ResourceManager& resource, const string& origin); ! bool runVM11proc(ResourceManager& resource, bool noConsole, const string& origin); ! bool runVM12proc(ResourceManager& resource, bool noConsole, const string& origin); }; --- 153,163 ---- private: ! // bool runVMDLL(ResourceManager& resource, const string& origin, bool justInstanciate=false); ! // bool setupVM12DLL(ResourceManager& resource, const string& origin); ! // bool setupVM11DLL(ResourceManager& resource, const string& origin); ! // bool runVM11proc(ResourceManager& resource, bool noConsole, const string& origin); ! // bool runVM12proc(ResourceManager& resource, bool noConsole, const string& origin); }; Index: JavaMachineManager.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/JavaMachineManager.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** JavaMachineManager.cpp 1 May 2007 19:40:16 -0000 1.18 --- JavaMachineManager.cpp 13 May 2007 19:56:35 -0000 1.19 *************** *** 21,24 **** --- 21,25 ---- #include "JavaMachineManager.h" + JavaMachineManager::JavaMachineManager(ResourceManager& resman): m_resman(resman) { *************** *** 29,33 **** m_jrepathVm = JVMEnvVarLookup::lookupJVM("JRE_HOME"); m_jdkpathVm = JVMEnvVarLookup::lookupJVM("JDK_HOME"); ! m_exitCode = -1; m_useConsole = true; m_acceptExe = true; --- 30,34 ---- m_jrepathVm = JVMEnvVarLookup::lookupJVM("JRE_HOME"); m_jdkpathVm = JVMEnvVarLookup::lookupJVM("JDK_HOME"); ! m_exitCode = 0; m_useConsole = true; m_acceptExe = true; *************** *** 40,44 **** DEBUG("Found a vm bundled with the application: (" + bjvm + ")"); m_localVMenabled = true; ! m_localVM.JavaHome = FileUtils::concFile(resman.getCurrentDirectory(), bjvm); } else { --- 41,46 ---- DEBUG("Found a vm bundled with the application: (" + bjvm + ")"); m_localVMenabled = true; ! std::string home = FileUtils::concFile(resman.getCurrentDirectory(), bjvm); ! m_localVM.JavaHome = home; } else { *************** *** 54,66 **** if (m_localVMenabled) { ! DEBUG("Trying to use bundled VM " + m_localVM.JavaHome); ! if (m_localVM.runProc(m_resman, m_useConsole, "bundled")) { - m_exitCode = m_localVM.getExitCode(); return true; } ! if (m_localVM.run(m_resman, "bundled")) ! return true; } --- 56,72 ---- if (m_localVMenabled) { ! if (internalRun(m_localVM, "bundled")) { return true; } ! // DEBUG("Trying to use bundled VM " + m_localVM.JavaHome); ! // if (m_localVM.runProc(m_resman, m_useConsole, "bundled")) ! // { ! // m_exitCode = m_localVM.getExitCode(); ! // return true; ! // } ! // if (m_localVM.run(m_resman, "bundled")) ! // return true; } *************** *** 153,157 **** if (launcher.runProc(m_resman, m_useConsole, org)) { ! m_exitCode = m_localVM.getExitCode(); return true; } --- 159,163 ---- if (launcher.runProc(m_resman, m_useConsole, org)) { ! m_exitCode = launcher.getExitCode(); return true; } Index: SunJVMDLL.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMDLL.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SunJVMDLL.cpp 30 Apr 2007 20:54:32 -0000 1.2 --- SunJVMDLL.cpp 13 May 2007 19:56:35 -0000 1.3 *************** *** 96,99 **** --- 96,100 ---- m_javaenv = new JNIEnv(); + DEBUG("DLL Setup on " + m_version.toString()); bool res; if ((m_version.getMajor() == 1) && (m_version.getMinor() == 1)) *************** *** 102,105 **** --- 103,107 ---- res = setupVM12DLL(CreateJavaVM, GetDefaultJavaVMInitArgs); + DEBUG("Result code on DLL: " + StringUtils::toString(res)); if (res) { |