Ignore:
Timestamp:
2008-03-26T15:30:33+13:00 (16 years ago)
Author:
oranfry
Message:

added a hint option to search4j

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release-kits/shared/search4j/search4j.cpp

    r15103 r15133  
    3131bool verbose = false;
    3232bool use_minimum = false;
     33string hint = "";
    3334
    3435enum JvmProperty {
     
    257258        << "find:     find java and print out information about it" << endl
    258259        << endl
    259         << "          search4j [-v|-e] [-m VERSION_STRING]" << endl
    260         << "          eg: search4j -m 1.4.1_01 -e" << endl
     260        << "          search4j [-v|-e]" << endl
     261        << "          eg: search4j -e" << endl
    261262        << endl
    262263        << "          by default, print JAVA_HOME. E.g., C:\\Program Files\\jre1.5.0_15, or" << endl
    263264        << "          if -v is specified, print the java version string. E.g. 1.5.0_15, or" << endl
    264265        << "          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
    265         << "          if -m option is used, find a java of the given version or newer, or fail" << endl
    266266        << endl
    267267        << "compare:  compare the found java with the given java version string" << endl
     
    280280        << endl
    281281        << "          specify the location of the jar relative to the current directory" << endl
    282         << "          if -m option is used, find a java of the given version or newer" << endl
    283282        << endl
    284283        << "Global Options:" << endl
     284        << "          -m VERSION_STRING: (minimum) find a java of the given version or newer, or fail" << endl
     285        << "          -h LOCATION: (hint) as a last resort look for java in LOCATION (treated as a JAVA_HOME)" << endl
    285286        << "          --verbose : have search4j print out information about what its doing" << endl
    286287        << "          --help : display this usage screen" << endl
     
    330331        javaHome = getenv( "JAVA_HOME" );
    331332        if ( javaHome != NULL ) {
    332             if ( verbose ) cout << "(" << javaHome << ")";
     333            if ( verbose ) cout << "(" << javaHome << ") ";
    333334            jvm.setJavaHome( javaHome );
    334335            if ( jvm.check() ) {
     
    350351        javaHome = getenv( "JRE_HOME" );
    351352        if ( javaHome != NULL ) {
    352             if ( verbose ) cout << "(" << javaHome << ")";
     353            if ( verbose ) cout << "(" << javaHome << ") ";
    353354            jvm.setJavaHome( javaHome );
    354355            if ( jvm.check() ) {
     
    423424    #endif
    424425
     426    if ( !jvmFound ) {
     427        //try the hint
     428        if ( verbose ) cout << " - trying hint: ";
     429        if ( strcmp(hint.c_str(),"") != 0  ) {
     430            if ( verbose ) cout << "(" << hint << ") ";
     431            jvm.setJavaHome( hint );
     432            if ( jvm.check() ) {
     433                if ( use_minimum ) {
     434                    if ( jvm.compare( minimum ) >= 0 ) {
     435                        jvmFound = true;
     436                    }
     437                } else {
     438                    jvmFound = true;
     439                }
     440            }
     441        }
     442        if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; }
     443    }
     444
     445
    425446    return jvmFound;
    426447}
     
    453474            if ( i == argc-1 ) {
    454475                usage();
    455                 return 0;
     476                return -1;
    456477            } else {
    457478                arg1 = argv[++i];
    458479            }
    459480
    460             } else if ( strcmp(argv[i], "-m") == 0 ) {
     481        } else if ( strcmp(argv[i], "-m") == 0 ) {
    461482            if ( i == argc-1 ) {
    462483                usage();
    463                 return 0;
     484                return -1;
    464485            } else {
    465486                if ( !minimum.setVersionFromString( argv[++i] ) ) {
     
    471492
    472493        } else if ( strcmp(argv[i], "-l") == 0 ) {
    473             action = Launch;
    474             arg1 = argv[++i];
     494            if ( i == argc-1 ) {
     495                usage();
     496                return -1;
     497            } else {
     498                action = Launch;
     499                arg1 = argv[++i];
     500            }
     501
     502        } else if ( strcmp(argv[i], "-h") == 0 ) {
     503            if ( i == argc-1 ) {
     504                usage();
     505                return -1;
     506            } else {
     507                hint = argv[++i];
     508            }
    475509
    476510        } else {
Note: See TracChangeset for help on using the changeset viewer.