Changeset 18237 for other-projects


Ignore:
Timestamp:
12/17/08 17:38:47 (12 years ago)
Author:
oranfry
Message:

added new options to search4j to only return a jre or only return a jre, and an option to display the type of the found jvm (whether jre or jdk)

Location:
other-projects/trunk/search4j
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • other-projects/trunk/search4j/libsearch4j.cpp

    r17302 r18237  
    131131    /* Close pipe and return return value of pPipe. */
    132132    int code = pclose( pPipe );
    133 
    134133    return code;
    135134
     
    148147    javaHome = jh;
    149148    setVersionFromExeOuput();
     149    setIsJdkFromJavacPresence();
    150150}
    151151
     
    231231int Jvm::getMinor() { return minor; }
    232232int Jvm::getUpdate() { return update; }
     233
     234bool Jvm::getIsJdk() { return isJdk; }
     235bool Jvm::getIsJre() { return !isJdk; }
    233236
    234237void Jvm::setVersionFromExeOuput() {
     
    256259    }
    257260}
    258    
     261void 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
    259275//end of Jvm class methods
    260276
     
    293309* return a Jvm object which represents the jvm on disk
    294310*/
    295 bool find( Jvm &jvm, bool use_minimum, Jvm minimum, string phint, string hint, bool verbose ) {
     311bool find( Jvm &jvm, bool use_minimum, Jvm minimum, bool jreOnly, bool jdkOnly, string phint, string hint, bool verbose ) {
    296312   
    297313    if ( verbose ) cout << "Searching for a JVM" << endl;
     
    316332                }
    317333            }
     334            if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) {
     335                jvmFound = false;
     336            }
     337
    318338        }
    319339        if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; }
     
    337357                }
    338358            }
     359            if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) {
     360                jvmFound = false;
     361            }
     362
    339363        }
    340364        if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; }
     
    358382                }
    359383            }
     384            if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) {
     385                jvmFound = false;
     386            }
     387
    360388        }
    361389        if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; }
     
    419447                        }
    420448                    }
     449                    if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) {
     450                        jvmFound = false;
     451                    }
    421452                }
    422453                RegCloseKey(hKey);
     
    443474                }
    444475            }
     476            if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) {
     477                jvmFound = false;
     478            }
     479
    445480        }
    446481        if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; }
  • other-projects/trunk/search4j/libsearch4j.h

    r17302 r18237  
    33#include <string>
    44#include <sstream>
     5#include <sys/stat.h>
    56using namespace std;
    67#ifdef WINDOWS
     
    2728    string javaHome;
    2829    bool isJdk;
    29     bool healthy;   
     30    bool healthy;
    3031
    3132    public:
     
    4647    int getUpdate();
    4748
     49    bool getIsJre();
     50    bool getIsJdk();
     51
    4852    private:
    4953    void setVersionFromExeOuput();
     54    void setIsJdkFromJavacPresence();
    5055
    5156};
     
    5358
    5459
    55 bool find( Jvm &jvm, bool use_minimum, Jvm minimum, string phint, string hint, bool verbose );
     60bool 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  
    1818    JavaHome,
    1919    Version,
    20     Executable
     20    Executable,
     21    Type
    2122};
    2223
     
    3839    else if ( jp == Executable )
    3940        return "Executable";
     41    else if ( jp == Type )
     42        return "Type";
     43
    4044    return "Unknown";
    4145}
     
    4953    bool use_minimum = false;
    5054    bool useJavaw = false;
    51     Jvm minimum;
     55    bool jdkOnly = false;
     56    bool jreOnly = false;
     57    Jvm minimum;
    5258    JvmProperty jvmProperty = JavaHome;
    5359    Action action = Find;
     
    5662    //parse commandline arguments
    5763    for (int i=1; i<argc; i++) {
     64
     65        //be verbose
    5866        if ( strcmp(argv[i], "--verbose") == 0 ) {
    5967            verbose = true;
     68
     69        //show help
    6070        } else if ( strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "--usage") == 0 ) {
    6171            usage();
    6272            return 0;
     73
     74        //show version
    6375        } else if ( strcmp(argv[i], "-v") == 0 ) {
    6476            jvmProperty = Version;
     77
     78        //show path to executable
    6579        } else if ( strcmp(argv[i], "-e") == 0 ) {
    6680            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
    6787        } else if ( strcmp(argv[i], "-c") == 0 ) {
    6888            action = Compare;
     
    7494            }
    7595
     96        //find only javas at or above the given version
    7697        } else if ( strcmp(argv[i], "-m") == 0 ) {
    7798            if ( i == argc-1 ) {
     
    86107            }
    87108
     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
    88118        } else if ( strcmp(argv[i], "-l") == 0 ) {
    89119            if ( i == argc-1 ) {
     
    95125            }
    96126
     127        //take the given priority hint
    97128        } else if ( strcmp(argv[i], "-p") == 0 ) {
    98129            if ( i == argc-1 ) {
     
    103134            }
    104135
     136        // take the following hint
    105137        } else if ( strcmp(argv[i], "-h") == 0 ) {
    106138            if ( i == argc-1 ) {
     
    110142                hint = argv[++i];
    111143            }
    112            
     144
    113145        #ifdef WINDOWS
     146        //show the path to the javaw executable
    114147        } else if ( strcmp(argv[i], "-w") == 0 ) {
    115148            useJavaw = true;
     
    129162    //find java
    130163    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 );
    132165
    133166    //check if it was found
     
    145178    if ( action == Find ) {
    146179
    147         if ( verbose ) cout << "Property to print: " << jvmPropertyToString( jvmProperty ) << endl;     
     180        if ( verbose ) cout << "Property to print: " << jvmPropertyToString( jvmProperty ) << endl;
    148181
    149182        //found - print out info about it
     
    162195            cout << foundJvm.getExecutable() << endl;
    163196            #endif
     197        } else if ( jvmProperty == Type ) {
     198            if ( foundJvm.getIsJdk() ) {
     199        cout << "JDK" << endl;
     200            } else {
     201          cout << "JRE" << endl;
     202            }
    164203        } else {
    165204            return -1; //should never happen
     
    221260        << "find:     find java and print out information about it" << endl
    222261        << endl
    223         << "          search4j [-v|-e]" << endl
     262        << "          search4j [-v|-e|-t]" << endl
    224263        << "          eg: search4j -e" << endl
    225264        << endl
     
    227266        << "          if -v is specified, print the java version string. E.g. 1.5.0_15, or" << endl
    228267        << "          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
    229269        << endl
    230270        << "compare:  compare the found java with the given java version string" << endl
     
    246286        << "Global Options:" << endl
    247287        << "          -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
    248290        << "          -p LOCATION: (priority hint) first look for java in LOCATION (treated as a JAVA_HOME)" << endl
    249291        << "          -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.