[15023] | 1 | #include <windows.h>
|
---|
| 2 |
|
---|
| 3 | #include <fstream>
|
---|
| 4 | #include <iostream>
|
---|
| 5 | #include <string>
|
---|
| 6 |
|
---|
| 7 | using namespace std;
|
---|
| 8 |
|
---|
| 9 | void replace_all ( std::string & str, std::string const & pattern, std::string const & replacement ) {
|
---|
| 10 |
|
---|
| 11 | std::string::size_type start = str.find( pattern, 0 );
|
---|
| 12 |
|
---|
| 13 | while ( start != str.npos ) {
|
---|
| 14 | str.replace( start, pattern.size(), replacement );
|
---|
| 15 | start = str.find( pattern, start+replacement.size() );
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | }
|
---|
[16948] | 19 |
|
---|
| 20 | void show_help() {
|
---|
| 21 |
|
---|
[19452] | 22 | cout << "WirkXXX - Windows Release Kit for GreenstoneXXX" << endl;
|
---|
[16948] | 23 | cout << "Helps you to create releases from the Repository" << endl << endl;
|
---|
| 24 |
|
---|
[19452] | 25 | cout << "usage: wirkXXX [args]" << endl;
|
---|
[16948] | 26 | cout << " -sim" << endl;
|
---|
[17043] | 27 | cout << " simulation only, don't actually do anything" << endl << endl;
|
---|
[16948] | 28 |
|
---|
| 29 | cout << " -help" << endl;
|
---|
[17043] | 30 | cout << " show this help screen" << endl << endl;
|
---|
[16948] | 31 |
|
---|
| 32 | cout << " -from <target>" << endl;
|
---|
| 33 | cout << " start execution from the target with the given target address" << endl << endl;
|
---|
| 34 |
|
---|
| 35 | cout << " -to <target>" << endl;
|
---|
| 36 | cout << " stop execution just before the target with the given target address" << endl << endl;
|
---|
| 37 |
|
---|
| 38 | cout << " -descend <target>" << endl;
|
---|
| 39 | cout << " execute only the target with the given address, including subtargets" << endl << endl;
|
---|
| 40 |
|
---|
| 41 | cout << " -cp" << endl;
|
---|
[19452] | 42 | cout << " show the classpath being used by wirkXXX" << endl << endl;
|
---|
[16948] | 43 |
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[15023] | 46 |
|
---|
| 47 | int main(int argc, char** argv ) {
|
---|
| 48 |
|
---|
| 49 | string classpath, command;
|
---|
| 50 |
|
---|
[17379] | 51 | //some checks
|
---|
| 52 | bool ok = true;
|
---|
| 53 | if ( getenv( "JAVA_HOME" ) == NULL ) {
|
---|
[19452] | 54 | cerr << "Please set JAVA_HOME before running wirkXXX" << endl;
|
---|
[17379] | 55 | ok = false;
|
---|
| 56 | }
|
---|
[19452] | 57 | if ( getenv( "WIRKXXX_HOME" ) == NULL ) {
|
---|
| 58 | cerr << "Please set WIRKXXX_HOME before running wirkXXX" << endl;
|
---|
[17379] | 59 | ok = false;
|
---|
| 60 | }
|
---|
| 61 | if ( !ok ) {
|
---|
| 62 | return -1;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | //load environment variables
|
---|
[15023] | 66 | string JAVA_HOME = getenv( "JAVA_HOME" );
|
---|
[19452] | 67 | string WIRKXXX_HOME = getenv( "WIRKXXX_HOME" );
|
---|
| 68 | putenv( ("ANT_HOME=" + WIRKXXX_HOME + "\\core\\ant").c_str() );
|
---|
[19324] | 69 |
|
---|
[15356] | 70 | //get the pwd
|
---|
| 71 | string pwd;
|
---|
| 72 | system( "CD > cd.dat" );
|
---|
| 73 | ifstream file( "cd.dat" ) ;
|
---|
| 74 | getline(file, pwd);
|
---|
| 75 | file.close();
|
---|
| 76 | system( "del cd.dat" );
|
---|
[17379] | 77 |
|
---|
[15023] | 78 | //create the command
|
---|
[19452] | 79 | command = WIRKXXX_HOME + "\\core\\ant\\bin\\ant.bat -f \"" + WIRKXXX_HOME + "\\ant-scripts\\build.xml\" -addressing \"-Dwirk3.home=" + WIRKXXX_HOME + "\"";
|
---|
| 80 |
|
---|
[15023] | 81 | //pass on the arguments
|
---|
| 82 | string a;
|
---|
[16931] | 83 | bool simMode = false;
|
---|
[15023] | 84 | for ( int i=0; i < argc; i++ ) {
|
---|
| 85 | a = argv[i];
|
---|
[19452] | 86 |
|
---|
[16948] | 87 | if ( a.compare("-help") == 0 || a.compare("--help") == 0 ) {
|
---|
| 88 | show_help();
|
---|
[15023] | 89 | return 0;
|
---|
[16948] | 90 | } else if ( a.compare("-cp") == 0 || a.compare("--cp") == 0 ) {
|
---|
[15023] | 91 | cout << classpath;
|
---|
| 92 | return 0;
|
---|
[16931] | 93 | } else if ( a.compare("-sim") == 0) {
|
---|
| 94 | command = command + " " + a;
|
---|
| 95 | simMode = true;
|
---|
[15023] | 96 | } else {
|
---|
| 97 | command = command + " " + a;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | }
|
---|
[15356] | 101 |
|
---|
[15023] | 102 | //set the basedir in the command
|
---|
[19452] | 103 | command = command + " \"-Dbasedir=" + pwd + "\"";
|
---|
[15356] | 104 |
|
---|
[15095] | 105 | cout
|
---|
| 106 | << "O-----------------------------------------O" << endl
|
---|
| 107 | << "| |" << endl
|
---|
[19452] | 108 | << "| WiRKXXX |" << endl
|
---|
| 109 | << "| Windows Release Kit for GreenstoneXXX |" << endl
|
---|
[15095] | 110 | << "| |" << endl
|
---|
| 111 | << "O-----------------------------------------O" << endl
|
---|
| 112 | ;
|
---|
[15023] | 113 |
|
---|
| 114 | cout << "pwd: " << pwd << endl;
|
---|
| 115 | cout << "command: " << command << endl;
|
---|
| 116 |
|
---|
| 117 | system( command.c_str() );
|
---|
| 118 |
|
---|
| 119 | return 0;
|
---|
| 120 |
|
---|
[16190] | 121 | }
|
---|