Ignore:
Timestamp:
2008-12-17T17:38:47+13:00 (15 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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.