[Jsmooth-cvs] jsmooth/skeletons/commonjava JavaMachineManager.cpp, 1.17, 1.18 JavaMachineManager.h,
Status: Beta
Brought to you by:
reyes
Update of /cvsroot/jsmooth/jsmooth/skeletons/commonjava In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9102/commonjava Modified Files: JavaMachineManager.cpp JavaMachineManager.h ResourceManager.cpp SunJVMExe.cpp SunJVMExe.h SunJVMLauncher.cpp SunJVMLauncher.h Log Message: adds exit code propagation when exe-run Index: SunJVMExe.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMExe.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SunJVMExe.h 28 Apr 2007 08:43:43 -0000 1.1 --- SunJVMExe.h 1 May 2007 19:40:16 -0000 1.2 *************** *** 41,44 **** --- 41,45 ---- std::string m_jrehome; Version m_version; + int m_exitCode; public: *************** *** 53,56 **** --- 54,59 ---- std::string getClassPath(bool full); + int getExitCode(); + private: }; Index: SunJVMLauncher.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMLauncher.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** SunJVMLauncher.h 30 Apr 2007 20:54:32 -0000 1.13 --- SunJVMLauncher.h 1 May 2007 19:40:16 -0000 1.14 *************** *** 81,84 **** --- 81,86 ---- SunJVMExe* m_exerunner; SunJVMDLL* m_dllrunner; + + int m_exitCode; /** *************** *** 122,125 **** --- 124,131 ---- friend bool operator < (const SunJVMLauncher& v1, const SunJVMLauncher& v2); + + int getExitCode(); + + bool runExe(const string& exepath, bool forceFullClasspath, ResourceManager& resource, bool noConsole, const std::string& version, const string& origin); Index: JavaMachineManager.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/JavaMachineManager.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** JavaMachineManager.h 9 Apr 2007 17:18:16 -0000 1.5 --- JavaMachineManager.h 1 May 2007 19:40:16 -0000 1.6 *************** *** 54,57 **** --- 54,64 ---- ResourceManager& m_resman; + int m_exitCode; + + bool m_useConsole; + bool m_acceptExe; + bool m_acceptDLL; + bool m_preferDLL; + public: /** *************** *** 63,66 **** --- 70,77 ---- JavaMachineManager(ResourceManager& resman) ; + void setUseConsole(bool useConsole); + void setAcceptExe(bool acceptExe); + void setAcceptDLL(bool acceptDLL); + void setPreferDLL(bool prefDLL); /** *************** *** 88,97 **** * @return true if the application is successfully started, false otherwise. */ ! bool run(bool noConsole, bool preferSingleProcess); SunJVMLauncher* runDLLFromRegistry(bool justInstanciate=false); protected: ! bool internalRun(SunJVMLauncher& launcher, bool noConsole, bool preferSingleProcess, const string& org); }; --- 99,110 ---- * @return true if the application is successfully started, false otherwise. */ ! bool run(); SunJVMLauncher* runDLLFromRegistry(bool justInstanciate=false); + int getExitCode(); + protected: ! bool internalRun(SunJVMLauncher& launcher, const string& org); }; Index: JavaMachineManager.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/JavaMachineManager.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** JavaMachineManager.cpp 28 Apr 2007 08:43:43 -0000 1.17 --- JavaMachineManager.cpp 1 May 2007 19:40:16 -0000 1.18 *************** *** 29,32 **** --- 29,37 ---- m_jrepathVm = JVMEnvVarLookup::lookupJVM("JRE_HOME"); m_jdkpathVm = JVMEnvVarLookup::lookupJVM("JDK_HOME"); + m_exitCode = -1; + m_useConsole = true; + m_acceptExe = true; + m_acceptDLL = true; + m_preferDLL = false; if (resman.getProperty("bundledvm").length() > 0) *************** *** 43,47 **** } ! bool JavaMachineManager::run(bool dontUseConsole, bool preferSingleProcess) { string vmorder = m_resman.getProperty(ResourceManager::KEY_JVMSEARCH); --- 48,52 ---- } ! bool JavaMachineManager::run() { string vmorder = m_resman.getProperty(ResourceManager::KEY_JVMSEARCH); *************** *** 49,58 **** if (m_localVMenabled) { ! DEBUG("Trying to use bundled VM " + m_localVM.JavaHome); ! if (m_localVM.runProc(m_resman, dontUseConsole, "bundled")) ! return true; ! ! if (m_localVM.run(m_resman, "bundled")) ! return true; } --- 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; } *************** *** 88,141 **** DEBUG("- Trying registry: " + m_registryVms[i].toString()); ! if (internalRun(m_registryVms[i], dontUseConsole, preferSingleProcess, "registry") == true) return true; DEBUG("Couldn't use this VM, now trying something else"); } ! } else if (*i == "jview") ! { ! DEBUG("- Trying to launch the application with JVIEW"); ! if (m_jviewVm.runProc(m_resman, dontUseConsole)) ! { ! return true; ! } ! ! } else if (*i == "javahome") { ! DEBUG("- Trying to use JAVAHOME"); ! if (m_javahomeVm.size()>0) ! { ! DEBUG("JAVAHOME exists..." + m_javahomeVm[0].toString()); ! if (internalRun(m_javahomeVm[0], dontUseConsole, preferSingleProcess, "jrehome")) ! return true; ! } ! } else if (*i == "jrepath") ! { ! DEBUG("- Trying to use JRE_HOME"); ! if (m_jrepathVm.size()>0) ! { ! if (internalRun(m_jrepathVm[0], dontUseConsole, preferSingleProcess, "jrehome")) ! return true; ! } ! } else if (*i == "exepath") ! { ! DEBUG("- Trying to use PATH"); ! SunJVMLauncher launcher; ! return launcher.runProc(m_resman, ! dontUseConsole, "path"); ! ! // string exename = dontUseConsole?"javaw.exe":"java.exe"; ! // SunJVMLauncher launcher; ! // launcher.VmVersion = launcher.guessVersionByProcess("java.exe"); ! // if (launcher.VmVersion.isValid() ! // && (!min.isValid() || (min <= launcher.VmVersion)) ! // && (!max.isValid() || (launcher.VmVersion <= max))) ! // { ! // DEBUG("Found valid java machine " + exename + " on PATH (" + launcher.VmVersion.toString() + ")"); ! // Version v12("1.2.0"); ! // if (launcher.runExe(exename, false, m_resman, dontUseConsole, (launcher.VmVersion<v12)?"1.1":"1.2", "path")) ! // return true; ! // } ! } } --- 96,137 ---- DEBUG("- Trying registry: " + m_registryVms[i].toString()); ! if (internalRun(m_registryVms[i], "registry") == true) return true; + DEBUG("Couldn't use this VM, now trying something else"); } ! } ! else if ((*i == "jview") && m_acceptExe) ! { ! DEBUG("- Trying to launch the application with JVIEW"); ! if (m_jviewVm.runProc(m_resman, ! m_useConsole)) { ! return true; ! } ! } ! else if ((*i == "javahome") && (m_javahomeVm.size()>0)) ! { ! DEBUG("- Trying to use JAVAHOME"); ! if (internalRun(m_javahomeVm[0], "jrehome")) ! return true; ! } ! else if ((*i == "jrepath") && (m_jrepathVm.size()>0)) ! { ! DEBUG("- Trying to use JRE_HOME"); ! if (internalRun(m_jrepathVm[0], "jrehome")) ! return true; ! } ! else if (*i == "exepath") ! { ! DEBUG("- Trying to use PATH"); ! SunJVMLauncher launcher; ! if (launcher.runProc(m_resman, m_useConsole, "path")) ! { ! m_exitCode = m_localVM.getExitCode(); ! return true; ! } ! } } *************** *** 145,185 **** ! bool JavaMachineManager::internalRun(SunJVMLauncher& launcher, bool noConsole, bool preferSingleProcess, const string& org) { ! // Need a console, and spawning a process is OK ? Then exec ! // [java/jre].exe. ! if ((noConsole == false) && (preferSingleProcess==false)) ! { ! return launcher.runProc(m_resman, noConsole, org); ! } ! ! // No need for a console, and need a single process ? Use the DLL ! // and create a JVM with it ! if (noConsole && preferSingleProcess) { ! DEBUG("Trying to run the JVM as a DLL call (executing in this process)..."); ! if (launcher.run(m_resman, org) == true) return true; - - DEBUG("Couldn't use the DLL at " + launcher.RuntimeLibPath); } ! // If we have an embedded jar, always prefer the exec process ! // launching, as it garantees that the temporary jar is cleaned up ! // on exit (due to a bug in the JVM DLL that prevents it to ! // terminate nicely). ! if (m_resman.useEmbeddedJar()) { ! if (launcher.runProc(m_resman, noConsole, org) == false) ! return launcher.run(m_resman, org); } ! else // Otherwise, preferring the JVM DLL call first is better ! // (it spares a new process) { ! if (launcher.run(m_resman, org) == false) ! return launcher.runProc(m_resman, noConsole, org); } ! ! return true; } --- 141,168 ---- ! bool JavaMachineManager::internalRun(SunJVMLauncher& launcher, const string& org) { ! if (m_acceptDLL && m_preferDLL) { ! if (launcher.run(m_resman, org)) return true; } ! if (m_acceptExe) { ! if (launcher.runProc(m_resman, m_useConsole, org)) ! { ! m_exitCode = m_localVM.getExitCode(); ! return true; ! } } ! ! if (m_acceptDLL && !m_preferDLL) { ! if (launcher.run(m_resman, org)) ! return true; } ! ! return false; } *************** *** 208,209 **** --- 191,217 ---- return NULL; } + + void JavaMachineManager::setUseConsole(bool useConsole) + { + m_useConsole = useConsole; + } + + void JavaMachineManager::setAcceptExe(bool acceptExe) + { + m_acceptExe = acceptExe; + } + + void JavaMachineManager::setAcceptDLL(bool acceptDLL) + { + m_acceptDLL = acceptDLL;; + } + + void JavaMachineManager::setPreferDLL(bool prefDLL) + { + m_preferDLL = prefDLL; + } + + int JavaMachineManager::getExitCode() + { + return m_exitCode; + } Index: ResourceManager.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/ResourceManager.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** ResourceManager.cpp 28 Apr 2007 08:43:43 -0000 1.22 --- ResourceManager.cpp 1 May 2007 19:40:16 -0000 1.23 *************** *** 191,198 **** bool ResourceManager::getBooleanProperty(const std::string& key) const { ! std::string prop = getProperty(key); if (StringUtils::parseInt(prop)==1) return true; return false; } --- 191,202 ---- bool ResourceManager::getBooleanProperty(const std::string& key) const { ! std::string prop = getProperty(key, "0"); ! if (StringUtils::parseInt(prop)==1) return true; + if (StringUtils::toLowerCase(prop) == "true") + return true; + return false; } Index: SunJVMLauncher.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMLauncher.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** SunJVMLauncher.cpp 30 Apr 2007 20:54:32 -0000 1.27 --- SunJVMLauncher.cpp 1 May 2007 19:40:16 -0000 1.28 *************** *** 122,126 **** } ! bool SunJVMLauncher::runProc(ResourceManager& resource, bool noConsole, const string& origin) { std::string classname = resource.getProperty(string(ResourceManager::KEY_MAINCLASSNAME)); --- 122,126 ---- } ! bool SunJVMLauncher::runProc(ResourceManager& resource, bool useConsole, const string& origin) { std::string classname = resource.getProperty(string(ResourceManager::KEY_MAINCLASSNAME)); *************** *** 151,155 **** SunJVMExe exe(this->JavaHome, VmVersion); setupVM(resource, &exe); ! return exe.run(classname, !noConsole); } --- 151,160 ---- SunJVMExe exe(this->JavaHome, VmVersion); setupVM(resource, &exe); ! if (exe.run(classname, useConsole)) ! { ! m_exitCode = exe.getExitCode(); ! return true; ! } ! return false; } *************** *** 204,207 **** --- 209,217 ---- } + int SunJVMLauncher::getExitCode() + { + return m_exitCode; + } + // bool SunJVMLauncher::setupVM12DLL(ResourceManager& resource, const string& origin) Index: SunJVMExe.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMExe.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SunJVMExe.cpp 28 Apr 2007 08:43:43 -0000 1.1 --- SunJVMExe.cpp 1 May 2007 19:40:16 -0000 1.2 *************** *** 94,97 **** --- 94,98 ---- DEBUG("Started successfully"); proc.join(); + m_exitCode = proc.getExitCode(); return true; } *************** *** 210,211 **** --- 211,217 ---- return StringUtils::join(cp, ";"); } + + int SunJVMExe::getExitCode() + { + return m_exitCode; + } |