Changeset 18237 for other-projects/trunk
- Timestamp:
- 2008-12-17T17:38:47+13:00 (15 years ago)
- Location:
- other-projects/trunk/search4j
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/trunk/search4j/libsearch4j.cpp
r17302 r18237 131 131 /* Close pipe and return return value of pPipe. */ 132 132 int code = pclose( pPipe ); 133 134 133 return code; 135 134 … … 148 147 javaHome = jh; 149 148 setVersionFromExeOuput(); 149 setIsJdkFromJavacPresence(); 150 150 } 151 151 … … 231 231 int Jvm::getMinor() { return minor; } 232 232 int Jvm::getUpdate() { return update; } 233 234 bool Jvm::getIsJdk() { return isJdk; } 235 bool Jvm::getIsJre() { return !isJdk; } 233 236 234 237 void Jvm::setVersionFromExeOuput() { … … 256 259 } 257 260 } 258 261 void Jvm::setIsJdkFromJavacPresence() { 262 string javacFile = ""; 263 javacFile.append( javaHome ); 264 265 #ifdef WINDOWS 266 javacFile.append( "\\bin\\javac.exe" ); 267 #endif 268 #ifndef WINDOWS 269 javacFile.append( "/bin/javac" ); 270 #endif 271 struct stat stFileInfo; 272 isJdk = ( stat(javacFile.c_str(),&stFileInfo) == 0 ); 273 } 274 259 275 //end of Jvm class methods 260 276 … … 293 309 * return a Jvm object which represents the jvm on disk 294 310 */ 295 bool find( Jvm &jvm, bool use_minimum, Jvm minimum, string phint, string hint, bool verbose ) {311 bool find( Jvm &jvm, bool use_minimum, Jvm minimum, bool jreOnly, bool jdkOnly, string phint, string hint, bool verbose ) { 296 312 297 313 if ( verbose ) cout << "Searching for a JVM" << endl; … … 316 332 } 317 333 } 334 if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) { 335 jvmFound = false; 336 } 337 318 338 } 319 339 if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; } … … 337 357 } 338 358 } 359 if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) { 360 jvmFound = false; 361 } 362 339 363 } 340 364 if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; } … … 358 382 } 359 383 } 384 if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) { 385 jvmFound = false; 386 } 387 360 388 } 361 389 if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; } … … 419 447 } 420 448 } 449 if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) { 450 jvmFound = false; 451 } 421 452 } 422 453 RegCloseKey(hKey); … … 443 474 } 444 475 } 476 if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) { 477 jvmFound = false; 478 } 479 445 480 } 446 481 if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; } -
other-projects/trunk/search4j/libsearch4j.h
r17302 r18237 3 3 #include <string> 4 4 #include <sstream> 5 #include <sys/stat.h> 5 6 using namespace std; 6 7 #ifdef WINDOWS … … 27 28 string javaHome; 28 29 bool isJdk; 29 bool healthy; 30 bool healthy; 30 31 31 32 public: … … 46 47 int getUpdate(); 47 48 49 bool getIsJre(); 50 bool getIsJdk(); 51 48 52 private: 49 53 void setVersionFromExeOuput(); 54 void setIsJdkFromJavacPresence(); 50 55 51 56 }; … … 53 58 54 59 55 bool find( Jvm &jvm, bool use_minimum, Jvm minimum, string phint, string hint, bool verbose );60 bool find( Jvm &jvm, bool use_minimum, Jvm minimum, bool jreOnly, bool jdeOnly, string phint, string hint, bool verbose ); -
other-projects/trunk/search4j/search4j.cpp
r17302 r18237 18 18 JavaHome, 19 19 Version, 20 Executable 20 Executable, 21 Type 21 22 }; 22 23 … … 38 39 else if ( jp == Executable ) 39 40 return "Executable"; 41 else if ( jp == Type ) 42 return "Type"; 43 40 44 return "Unknown"; 41 45 } … … 49 53 bool use_minimum = false; 50 54 bool useJavaw = false; 51 Jvm minimum; 55 bool jdkOnly = false; 56 bool jreOnly = false; 57 Jvm minimum; 52 58 JvmProperty jvmProperty = JavaHome; 53 59 Action action = Find; … … 56 62 //parse commandline arguments 57 63 for (int i=1; i<argc; i++) { 64 65 //be verbose 58 66 if ( strcmp(argv[i], "--verbose") == 0 ) { 59 67 verbose = true; 68 69 //show help 60 70 } else if ( strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "--usage") == 0 ) { 61 71 usage(); 62 72 return 0; 73 74 //show version 63 75 } else if ( strcmp(argv[i], "-v") == 0 ) { 64 76 jvmProperty = Version; 77 78 //show path to executable 65 79 } else if ( strcmp(argv[i], "-e") == 0 ) { 66 80 jvmProperty = Executable; 81 82 //show whether jre or jdk 83 } else if ( strcmp(argv[i], "-t") == 0 ) { 84 jvmProperty = Type; 85 86 //compare found java with the given version string 67 87 } else if ( strcmp(argv[i], "-c") == 0 ) { 68 88 action = Compare; … … 74 94 } 75 95 96 //find only javas at or above the given version 76 97 } else if ( strcmp(argv[i], "-m") == 0 ) { 77 98 if ( i == argc-1 ) { … … 86 107 } 87 108 109 //find only jdks 110 } else if ( strcmp(argv[i], "-d") == 0 ) { 111 jdkOnly = true; 112 113 //find only jres 114 } else if ( strcmp(argv[i], "-r") == 0 ) { 115 jreOnly = true; 116 117 //launch the named jar with the found java 88 118 } else if ( strcmp(argv[i], "-l") == 0 ) { 89 119 if ( i == argc-1 ) { … … 95 125 } 96 126 127 //take the given priority hint 97 128 } else if ( strcmp(argv[i], "-p") == 0 ) { 98 129 if ( i == argc-1 ) { … … 103 134 } 104 135 136 // take the following hint 105 137 } else if ( strcmp(argv[i], "-h") == 0 ) { 106 138 if ( i == argc-1 ) { … … 110 142 hint = argv[++i]; 111 143 } 112 144 113 145 #ifdef WINDOWS 146 //show the path to the javaw executable 114 147 } else if ( strcmp(argv[i], "-w") == 0 ) { 115 148 useJavaw = true; … … 129 162 //find java 130 163 Jvm foundJvm; 131 bool found = find( foundJvm, use_minimum, minimum, phint, hint, verbose );164 bool found = find( foundJvm, use_minimum, minimum, jreOnly, jdkOnly, phint, hint, verbose ); 132 165 133 166 //check if it was found … … 145 178 if ( action == Find ) { 146 179 147 if ( verbose ) cout << "Property to print: " << jvmPropertyToString( jvmProperty ) << endl; 180 if ( verbose ) cout << "Property to print: " << jvmPropertyToString( jvmProperty ) << endl; 148 181 149 182 //found - print out info about it … … 162 195 cout << foundJvm.getExecutable() << endl; 163 196 #endif 197 } else if ( jvmProperty == Type ) { 198 if ( foundJvm.getIsJdk() ) { 199 cout << "JDK" << endl; 200 } else { 201 cout << "JRE" << endl; 202 } 164 203 } else { 165 204 return -1; //should never happen … … 221 260 << "find: find java and print out information about it" << endl 222 261 << endl 223 << " search4j [-v|-e ]" << endl262 << " search4j [-v|-e|-t]" << endl 224 263 << " eg: search4j -e" << endl 225 264 << endl … … 227 266 << " if -v is specified, print the java version string. E.g. 1.5.0_15, or" << endl 228 267 << " if -e is specified, print the path the to the java executable. E.g. C:\\Program Files\\jre1.5.0_15\\bin\\java.exe" << endl 268 << " if -t is specified, print whether the found java is a JRE or a JDK" << endl 229 269 << endl 230 270 << "compare: compare the found java with the given java version string" << endl … … 246 286 << "Global Options:" << endl 247 287 << " -m VERSION_STRING: (minimum) find a java of the given version or newer, or fail" << endl 288 << " -d : find only jdks" << endl 289 << " -r : find only jres" << endl 248 290 << " -p LOCATION: (priority hint) first look for java in LOCATION (treated as a JAVA_HOME)" << endl 249 291 << " -h LOCATION: (hint) as a last resort look for java in LOCATION (treated as a JAVA_HOME)" << endl
Note:
See TracChangeset
for help on using the changeset viewer.