[15690] | 1 | /*
|
---|
| 2 | * Library of functions for the Search4j utility
|
---|
| 3 | */
|
---|
| 4 |
|
---|
[15892] | 5 | #include "libsearch4j.h"
|
---|
[15690] | 6 |
|
---|
[15892] | 7 |
|
---|
[15690] | 8 | #ifdef WINDOWS
|
---|
| 9 | //minimal launch4j stuff
|
---|
| 10 | #define NO_JAVA_FOUND 0
|
---|
| 11 | #define FOUND_JRE 1
|
---|
| 12 | #define FOUND_SDK 2
|
---|
[15897] | 13 |
|
---|
[15690] | 14 | //windows functions
|
---|
| 15 | #define popen _popen
|
---|
| 16 | #define pclose _pclose
|
---|
| 17 | #define strcmp _stricmp
|
---|
[15892] | 18 |
|
---|
[15690] | 19 | #endif /* WINDOWS */
|
---|
| 20 |
|
---|
| 21 | void replace_all ( std::string & str, std::string const & pattern, std::string const & replacement ) {
|
---|
| 22 |
|
---|
| 23 | std::string::size_type start = str.find( pattern, 0 );
|
---|
| 24 |
|
---|
| 25 | while ( start != str.npos ) {
|
---|
| 26 | str.replace( start, pattern.size(), replacement );
|
---|
| 27 | start = str.find( pattern, start+replacement.size() );
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | }
|
---|
| 31 |
|
---|
[15892] | 32 |
|
---|
| 33 | int process( string command, bool render ) {
|
---|
| 34 |
|
---|
| 35 | #ifdef WINDOWS
|
---|
| 36 |
|
---|
| 37 | STARTUPINFO si;
|
---|
| 38 | PROCESS_INFORMATION pi;
|
---|
| 39 | memset(&pi, 0, sizeof(pi));
|
---|
| 40 | memset(&si, 0, sizeof(si));
|
---|
| 41 | si.cb = sizeof(si);
|
---|
[15690] | 42 |
|
---|
[15892] | 43 | DWORD dwExitCode = -1;
|
---|
| 44 | char* cmd = (char*)command.c_str();
|
---|
| 45 |
|
---|
| 46 | bool result;
|
---|
| 47 | if ( render ) {
|
---|
| 48 | result = CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
|
---|
| 49 | } else {
|
---|
| 50 | result = CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | if ( result ) {
|
---|
| 54 | WaitForSingleObject(pi.hProcess, INFINITE);
|
---|
| 55 | GetExitCodeProcess(pi.hProcess, &dwExitCode);
|
---|
| 56 | CloseHandle(pi.hThread);
|
---|
| 57 | CloseHandle(pi.hProcess);
|
---|
| 58 | }
|
---|
| 59 | return dwExitCode;
|
---|
| 60 |
|
---|
| 61 | #else
|
---|
| 62 |
|
---|
| 63 | return system( command.c_str() );
|
---|
| 64 |
|
---|
| 65 | #endif
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | int process_and_catch_output( string command, string &output ) {
|
---|
[15690] | 71 |
|
---|
| 72 | #ifdef WINDOWS
|
---|
[15892] | 73 |
|
---|
| 74 | char cmd[1024] = "cmd.exe /c ";
|
---|
| 75 | strcat(cmd, command.c_str());
|
---|
| 76 | strcat(cmd, " > cmd_output.txt 2>&1");
|
---|
| 77 | //cerr << "command: " << cmd << endl;
|
---|
| 78 | int code = process( cmd, false );
|
---|
| 79 | if ( code!= 0 )
|
---|
| 80 | return code;
|
---|
| 81 |
|
---|
| 82 | string line;
|
---|
| 83 | ifstream myfile("cmd_output.txt");
|
---|
| 84 | if ( !myfile.is_open() ) {
|
---|
[15690] | 85 | return -1;
|
---|
[15892] | 86 | }
|
---|
[15690] | 87 |
|
---|
[15892] | 88 | while ( !myfile.eof() ) {
|
---|
| 89 | getline(myfile,line);
|
---|
| 90 | output.append( line );
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | myfile.close();
|
---|
| 94 |
|
---|
| 95 | _unlink( "cmd_output.txt" );
|
---|
| 96 |
|
---|
| 97 | return code;
|
---|
| 98 |
|
---|
| 99 | #else
|
---|
| 100 |
|
---|
| 101 | FILE *pPipe;
|
---|
| 102 |
|
---|
| 103 | char cmd[1024];
|
---|
| 104 | strcpy(cmd, command.c_str());
|
---|
| 105 | strcat(cmd, " 2>&1" );
|
---|
| 106 |
|
---|
| 107 | //if ( verbose ) cout << "process(): running '" << command << "'" << endl;
|
---|
[15690] | 108 | if( (pPipe = popen( cmd, "r" )) == NULL ) {
|
---|
| 109 | //if ( verbose ) cout << "could not start process" << endl;
|
---|
| 110 | pclose( pPipe );
|
---|
| 111 | return -1;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
[15892] | 114 | //if ( verbose ) cout << "started process" << endl;
|
---|
| 115 |
|
---|
[15690] | 116 | /* Read pipe until end of file. */
|
---|
| 117 | while( !feof( pPipe ) ) {
|
---|
| 118 | char psBuffer[128];
|
---|
| 119 | //if ( verbose ) cout << "get some data" << endl;
|
---|
| 120 | if( fgets( psBuffer, 128, pPipe ) != NULL ) {
|
---|
| 121 |
|
---|
| 122 | //if ( verbose ) cout << "got: " << psBuffer << endl;
|
---|
| 123 | output.append( psBuffer );
|
---|
| 124 |
|
---|
| 125 | } else {
|
---|
| 126 | //if ( verbose ) cout << "none left" << endl;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | /* Close pipe and return return value of pPipe. */
|
---|
| 132 | int code = pclose( pPipe );
|
---|
| 133 | return code;
|
---|
[15892] | 134 |
|
---|
| 135 | #endif
|
---|
| 136 |
|
---|
[15690] | 137 | }
|
---|
[15892] | 138 |
|
---|
| 139 | //Jvm class methods
|
---|
[15690] | 140 |
|
---|
[20709] | 141 | Jvm::Jvm()
|
---|
| 142 | : era_(1), major_(0), minor_(0), update_(0),
|
---|
| 143 | javaHome_(),
|
---|
| 144 | isJdk_(false), healthy_(false)
|
---|
| 145 | {}
|
---|
[15892] | 146 |
|
---|
[20709] | 147 | Jvm::~Jvm()
|
---|
| 148 | {
|
---|
| 149 | // javaHome automatically destructed
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 |
|
---|
[15892] | 153 | void Jvm::setJavaHome( string jh ) {
|
---|
[20709] | 154 | healthy_ = true;
|
---|
| 155 | javaHome_ = jh;
|
---|
[18237] | 156 | setVersionFromExeOuput();
|
---|
| 157 | setIsJdkFromJavacPresence();
|
---|
[15892] | 158 | }
|
---|
[15690] | 159 |
|
---|
[15892] | 160 | string Jvm::getJavaHome() {
|
---|
[20709] | 161 | return javaHome_;
|
---|
[15892] | 162 | }
|
---|
| 163 |
|
---|
| 164 | string Jvm::getExecutable() {
|
---|
| 165 | string exec = "";
|
---|
[20709] | 166 | exec.append( javaHome_ );
|
---|
[15892] | 167 |
|
---|
| 168 | #ifdef WINDOWS
|
---|
| 169 | exec.append( "\\bin\\java.exe" );
|
---|
| 170 | #endif
|
---|
| 171 |
|
---|
| 172 | #ifndef WINDOWS
|
---|
| 173 | exec.append( "/bin/java" );
|
---|
| 174 | #endif
|
---|
[15690] | 175 |
|
---|
[15892] | 176 | return exec;
|
---|
| 177 | }
|
---|
[15690] | 178 |
|
---|
[15892] | 179 | #ifdef WINDOWS
|
---|
| 180 | string Jvm::getWinExecutable() {
|
---|
| 181 | string exec = "";
|
---|
[20709] | 182 | exec.append( javaHome_ );
|
---|
[15892] | 183 | exec.append( "\\bin\\javaw.exe" );
|
---|
| 184 | return exec;
|
---|
| 185 | }
|
---|
| 186 | #endif
|
---|
[15690] | 187 |
|
---|
| 188 |
|
---|
[15892] | 189 | string Jvm::getVersion() {
|
---|
| 190 | stringstream ss;
|
---|
[20709] | 191 | ss << era_ << "." << major_ << "." << minor_ << "_" << update_;
|
---|
[15892] | 192 | return ss.str();
|
---|
| 193 | }
|
---|
[15690] | 194 |
|
---|
[15892] | 195 | bool Jvm::check() {
|
---|
[20709] | 196 | return healthy_;
|
---|
[15892] | 197 | }
|
---|
[15690] | 198 |
|
---|
[15892] | 199 | bool Jvm::setVersionFromString( string version ) {
|
---|
[20709] | 200 | era_ = atoi( version.substr(0,1).c_str() );
|
---|
| 201 | major_ = atoi( version.substr(2,1).c_str() );
|
---|
| 202 | minor_ = atoi( version.substr(4,1).c_str() );
|
---|
| 203 | update_ = atoi( version.substr(6,2).c_str() );
|
---|
[15892] | 204 | return true;
|
---|
| 205 | }
|
---|
[15690] | 206 |
|
---|
[15892] | 207 | int Jvm::compare( Jvm otherJvm ) {
|
---|
| 208 | //era
|
---|
[20709] | 209 | if ( era_ > otherJvm.getEra() )
|
---|
[15892] | 210 | return 1;
|
---|
[20709] | 211 | else if ( era_ < otherJvm.getEra() )
|
---|
[15892] | 212 | return -1;
|
---|
| 213 |
|
---|
| 214 | //major
|
---|
[20709] | 215 | if ( major_ > otherJvm.getMajor() )
|
---|
[15892] | 216 | return 1;
|
---|
[20709] | 217 | else if ( major_ < otherJvm.getMajor() )
|
---|
[15892] | 218 | return -1;
|
---|
[15690] | 219 |
|
---|
[15892] | 220 | //minor
|
---|
[20709] | 221 | if ( minor_ > otherJvm.getMinor() )
|
---|
[15892] | 222 | return 1;
|
---|
[20709] | 223 | else if ( minor_ < otherJvm.getMinor() )
|
---|
[15892] | 224 | return -1;
|
---|
[15690] | 225 |
|
---|
[15892] | 226 | //update
|
---|
[20709] | 227 | if ( update_ > otherJvm.getUpdate() )
|
---|
[15892] | 228 | return 1;
|
---|
[20709] | 229 | else if ( update_ < otherJvm.getUpdate() )
|
---|
[15892] | 230 | return -1;
|
---|
[15690] | 231 |
|
---|
[15892] | 232 | //all the same so far, must be exactly the same
|
---|
| 233 | return 0;
|
---|
[15690] | 234 |
|
---|
[15892] | 235 | }
|
---|
[15690] | 236 |
|
---|
[20709] | 237 | int Jvm::getEra() { return era_; }
|
---|
| 238 | int Jvm::getMajor() { return major_; }
|
---|
| 239 | int Jvm::getMinor() { return minor_; }
|
---|
| 240 | int Jvm::getUpdate() { return update_; }
|
---|
[18237] | 241 |
|
---|
[20709] | 242 | bool Jvm::getIsJdk() { return isJdk_; }
|
---|
| 243 | bool Jvm::getIsJre() { return !isJdk_; }
|
---|
[15690] | 244 |
|
---|
[15892] | 245 | void Jvm::setVersionFromExeOuput() {
|
---|
| 246 | string command = "", output = "";
|
---|
| 247 | command.append( "\"" );
|
---|
| 248 | command.append( getExecutable() );
|
---|
| 249 | command.append( "\"" );
|
---|
| 250 | command.append(" -version");
|
---|
[15690] | 251 |
|
---|
[15892] | 252 | //cerr << "command: " << command << endl;
|
---|
| 253 | int result = process_and_catch_output( command, output );
|
---|
| 254 | //cerr << "output: " << output << endl;
|
---|
[15690] | 255 |
|
---|
[15892] | 256 | if ( result == 0 ) {
|
---|
| 257 | if ( strcmp( output.substr( 0, 12 ).c_str() , "java version" ) == 0 || true ) {
|
---|
[20709] | 258 | era_ = atoi( output.substr(14,1).c_str() );
|
---|
| 259 | major_ = atoi( output.substr(16,1).c_str() );
|
---|
| 260 | minor_ = atoi( output.substr(18,1).c_str() );
|
---|
| 261 | update_ = atoi( output.substr(20,2).c_str() );
|
---|
[15690] | 262 | } else {
|
---|
[20709] | 263 | healthy_=false;
|
---|
[15690] | 264 | }
|
---|
[15892] | 265 | } else {
|
---|
[20709] | 266 | healthy_ = false;
|
---|
[15690] | 267 | }
|
---|
[15892] | 268 | }
|
---|
[18237] | 269 | void Jvm::setIsJdkFromJavacPresence() {
|
---|
| 270 | string javacFile = "";
|
---|
[20709] | 271 | javacFile.append( javaHome_ );
|
---|
[18237] | 272 |
|
---|
| 273 | #ifdef WINDOWS
|
---|
| 274 | javacFile.append( "\\bin\\javac.exe" );
|
---|
| 275 | #endif
|
---|
| 276 | #ifndef WINDOWS
|
---|
| 277 | javacFile.append( "/bin/javac" );
|
---|
| 278 | #endif
|
---|
| 279 | struct stat stFileInfo;
|
---|
[20709] | 280 | isJdk_ = ( stat(javacFile.c_str(),&stFileInfo) == 0 );
|
---|
[18237] | 281 | }
|
---|
| 282 |
|
---|
[15892] | 283 | //end of Jvm class methods
|
---|
| 284 |
|
---|
[15690] | 285 |
|
---|
| 286 | #ifdef WINDOWS
|
---|
| 287 | int regSearch(HKEY hKey, const char* keyName, int searchType, char* foundJavaVer ) {
|
---|
| 288 | DWORD x = 0;
|
---|
| 289 | unsigned long size = 1024;
|
---|
| 290 | FILETIME time;
|
---|
| 291 | char buffer[1024] = {0};
|
---|
| 292 |
|
---|
| 293 | int foundJava = NO_JAVA_FOUND;
|
---|
| 294 |
|
---|
| 295 | while (RegEnumKeyEx(
|
---|
| 296 | hKey, // handle to key to enumerate
|
---|
| 297 | x++, // index of subkey to enumerate
|
---|
| 298 | buffer, // address of buffer for subkey name
|
---|
| 299 | &size, // address for size of subkey buffer
|
---|
| 300 | NULL, // reserved
|
---|
| 301 | NULL, // address of buffer for class string
|
---|
| 302 | NULL, // address for size of class buffer
|
---|
| 303 | &time) == ERROR_SUCCESS) {
|
---|
| 304 | strcpy(foundJavaVer, buffer);
|
---|
| 305 | foundJava = searchType;
|
---|
| 306 | size = 1024;
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 | return foundJava;
|
---|
| 310 |
|
---|
| 311 | }
|
---|
| 312 | #endif
|
---|
| 313 |
|
---|
| 314 | /*
|
---|
| 315 | * function to find java
|
---|
| 316 | * implements the logic drawn on the dl lab whiteboard in feb 08
|
---|
| 317 | * return a Jvm object which represents the jvm on disk
|
---|
| 318 | */
|
---|
[20709] | 319 | bool find( Jvm &jvm, bool use_minimum, const Jvm& minimum, bool jreOnly, bool jdkOnly, string phint, string hint, bool verbose ) {
|
---|
[15690] | 320 |
|
---|
| 321 | if ( verbose ) cout << "Searching for a JVM" << endl;
|
---|
[15892] | 322 |
|
---|
[20709] | 323 | char *javaHomeEnv = "";
|
---|
[15690] | 324 | bool jvmFound = false;
|
---|
| 325 |
|
---|
| 326 | if ( !jvmFound ) {
|
---|
[15892] | 327 |
|
---|
[17302] | 328 | //try the priority hint
|
---|
| 329 | if ( verbose ) cout << " - trying priority hint: ";
|
---|
| 330 | if ( strcmp(phint.c_str(),"") != 0 ) {
|
---|
| 331 | if ( verbose ) cout << "(" << phint << ") ";
|
---|
| 332 | jvm.setJavaHome( phint );
|
---|
| 333 | if ( jvm.check() ) {
|
---|
| 334 | if ( use_minimum ) {
|
---|
| 335 | if ( jvm.compare( minimum ) >= 0 ) {
|
---|
| 336 | jvmFound = true;
|
---|
| 337 | }
|
---|
| 338 | } else {
|
---|
| 339 | jvmFound = true;
|
---|
| 340 | }
|
---|
[18237] | 341 | }
|
---|
| 342 | if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) {
|
---|
| 343 | jvmFound = false;
|
---|
[17302] | 344 | }
|
---|
[18237] | 345 |
|
---|
[17302] | 346 | }
|
---|
| 347 | if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; }
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | if ( !jvmFound ) {
|
---|
| 351 |
|
---|
[15690] | 352 | //try JAVA_HOME
|
---|
| 353 | if ( verbose ) cout << " - trying JAVA_HOME: ";
|
---|
[20709] | 354 | javaHomeEnv = getenv( "JAVA_HOME" );
|
---|
| 355 | if ( javaHomeEnv != NULL ) {
|
---|
| 356 | if ( verbose ) cout << "(" << javaHomeEnv << ") ";
|
---|
| 357 | jvm.setJavaHome( javaHomeEnv );
|
---|
[15690] | 358 | if ( jvm.check() ) {
|
---|
| 359 | if ( use_minimum ) {
|
---|
| 360 | if ( jvm.compare( minimum ) >= 0 ) {
|
---|
| 361 | jvmFound = true;
|
---|
| 362 | }
|
---|
| 363 | } else {
|
---|
| 364 | jvmFound = true;
|
---|
| 365 | }
|
---|
[18237] | 366 | }
|
---|
| 367 | if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) {
|
---|
| 368 | jvmFound = false;
|
---|
[15690] | 369 | }
|
---|
[18237] | 370 |
|
---|
[15690] | 371 | }
|
---|
| 372 | if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; }
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 | if ( !jvmFound ) {
|
---|
[15892] | 376 |
|
---|
[15690] | 377 | //try JRE_HOME
|
---|
| 378 | if ( verbose ) cout << " - trying JRE_HOME: ";
|
---|
[20709] | 379 | javaHomeEnv = getenv( "JRE_HOME" );
|
---|
| 380 | if ( javaHomeEnv != NULL ) {
|
---|
| 381 | if ( verbose ) cout << "(" << javaHomeEnv << ") ";
|
---|
| 382 | jvm.setJavaHome( javaHomeEnv );
|
---|
[15690] | 383 | if ( jvm.check() ) {
|
---|
| 384 | if ( use_minimum ) {
|
---|
| 385 | if ( jvm.compare( minimum ) >= 0 ) {
|
---|
| 386 | jvmFound = true;
|
---|
| 387 | }
|
---|
| 388 | } else {
|
---|
| 389 | jvmFound = true;
|
---|
| 390 | }
|
---|
[18237] | 391 | }
|
---|
| 392 | if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) {
|
---|
| 393 | jvmFound = false;
|
---|
[15690] | 394 | }
|
---|
[18237] | 395 |
|
---|
[15690] | 396 | }
|
---|
| 397 | if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; }
|
---|
| 398 | }
|
---|
| 399 |
|
---|
| 400 | #ifdef WINDOWS
|
---|
| 401 | if ( !jvmFound ) {
|
---|
[15892] | 402 |
|
---|
[15690] | 403 | //try the registry - this code based on launch4j code
|
---|
[15892] | 404 | char foundJavaVer[8192] = {0};
|
---|
[15690] | 405 | int foundJava = NO_JAVA_FOUND;
|
---|
| 406 |
|
---|
[15892] | 407 | if ( verbose ) cout << " - trying the registry: "; cout.flush();
|
---|
[15690] | 408 | HKEY hKey;
|
---|
| 409 | const char jre[] = "SOFTWARE\\JavaSoft\\Java Runtime Environment";
|
---|
| 410 | const char sdk[] = "SOFTWARE\\JavaSoft\\Java Development Kit";
|
---|
| 411 |
|
---|
| 412 | if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT(jre), 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &hKey) == ERROR_SUCCESS ) {
|
---|
| 413 | foundJava = regSearch(hKey, jre, FOUND_JRE, foundJavaVer);
|
---|
| 414 | RegCloseKey(hKey);
|
---|
| 415 | }
|
---|
| 416 |
|
---|
| 417 | if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT(sdk), 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &hKey) == ERROR_SUCCESS ) {
|
---|
| 418 | foundJava = regSearch(hKey, sdk, FOUND_SDK, foundJavaVer);
|
---|
| 419 | RegCloseKey(hKey);
|
---|
| 420 | }
|
---|
| 421 |
|
---|
| 422 | if ( foundJava != NO_JAVA_FOUND ) {
|
---|
| 423 | char path[1024] = {0};
|
---|
| 424 | char keyBuffer[1024];
|
---|
| 425 | unsigned long datatype;
|
---|
| 426 | unsigned long bufferlength = 1024;
|
---|
| 427 | if (foundJava == FOUND_JRE) {
|
---|
| 428 | strcpy(keyBuffer, jre);
|
---|
| 429 | } else {
|
---|
| 430 | strcpy(keyBuffer, sdk);
|
---|
| 431 | }
|
---|
[15892] | 432 |
|
---|
[15690] | 433 | strcat(keyBuffer, "\\");
|
---|
| 434 | strcat(keyBuffer, foundJavaVer);
|
---|
[15892] | 435 |
|
---|
[15690] | 436 | if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT(keyBuffer), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
|
---|
| 437 | unsigned char buffer[1024] = {0};
|
---|
| 438 | if (RegQueryValueEx(hKey, "JavaHome", NULL, &datatype, buffer, &bufferlength) == ERROR_SUCCESS) {
|
---|
| 439 | int i = 0;
|
---|
| 440 | do {
|
---|
| 441 | path[i] = buffer[i];
|
---|
| 442 | } while (path[i++] != 0);
|
---|
| 443 | if (foundJava == FOUND_SDK) {
|
---|
| 444 | strcat(path, "\\jre");
|
---|
| 445 | }
|
---|
[15892] | 446 | if ( verbose ) cerr << "path: " << path << endl ;
|
---|
[15690] | 447 | jvm.setJavaHome( path );
|
---|
| 448 | if ( jvm.check() ) {
|
---|
| 449 | if ( use_minimum ) {
|
---|
| 450 | if ( jvm.compare( minimum ) >= 0 ) {
|
---|
| 451 | jvmFound = true;
|
---|
| 452 | }
|
---|
| 453 | } else {
|
---|
| 454 | jvmFound = true;
|
---|
| 455 | }
|
---|
[18237] | 456 | }
|
---|
| 457 | if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) {
|
---|
| 458 | jvmFound = false;
|
---|
[15690] | 459 | }
|
---|
| 460 | }
|
---|
| 461 | RegCloseKey(hKey);
|
---|
| 462 | }
|
---|
| 463 | }
|
---|
| 464 | if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; }
|
---|
| 465 | }
|
---|
| 466 | #endif
|
---|
| 467 |
|
---|
| 468 | if ( !jvmFound ) {
|
---|
[15892] | 469 |
|
---|
[15690] | 470 | //try the hint
|
---|
| 471 | if ( verbose ) cout << " - trying hint: ";
|
---|
| 472 | if ( strcmp(hint.c_str(),"") != 0 ) {
|
---|
| 473 | if ( verbose ) cout << "(" << hint << ") ";
|
---|
| 474 | jvm.setJavaHome( hint );
|
---|
| 475 | if ( jvm.check() ) {
|
---|
| 476 | if ( use_minimum ) {
|
---|
| 477 | if ( jvm.compare( minimum ) >= 0 ) {
|
---|
| 478 | jvmFound = true;
|
---|
| 479 | }
|
---|
| 480 | } else {
|
---|
| 481 | jvmFound = true;
|
---|
| 482 | }
|
---|
[18237] | 483 | }
|
---|
| 484 | if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) {
|
---|
| 485 | jvmFound = false;
|
---|
[15690] | 486 | }
|
---|
[18237] | 487 |
|
---|
[15690] | 488 | }
|
---|
| 489 | if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; }
|
---|
| 490 | }
|
---|
| 491 |
|
---|
| 492 |
|
---|
| 493 | return jvmFound;
|
---|
| 494 | }
|
---|