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 | }
|
---|
19 |
|
---|
20 | void show_help() {
|
---|
21 |
|
---|
22 | cout << "WirkXXX - Windows Release Kit for GreenstoneXXX" << endl;
|
---|
23 | cout << "Helps you to create releases from the Repository" << endl << endl;
|
---|
24 |
|
---|
25 | cout << "usage: wirkXXX [args]" << endl;
|
---|
26 | cout << " -sim" << endl;
|
---|
27 | cout << " simulation only, don't actually do anything" << endl << endl;
|
---|
28 |
|
---|
29 | cout << " -help" << endl;
|
---|
30 | cout << " show this help screen" << endl << endl;
|
---|
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;
|
---|
42 | cout << " show the classpath being used by wirkXXX" << endl << endl;
|
---|
43 |
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | int main(int argc, char** argv ) {
|
---|
48 |
|
---|
49 | string classpath, command;
|
---|
50 |
|
---|
51 | //some checks
|
---|
52 | bool ok = true;
|
---|
53 | if ( getenv( "JAVA_HOME" ) == NULL ) {
|
---|
54 | cerr << "Please set JAVA_HOME before running wirkXXX" << endl;
|
---|
55 | ok = false;
|
---|
56 | }
|
---|
57 | if ( getenv( "WIRKXXX_HOME" ) == NULL ) {
|
---|
58 | cerr << "Please set WIRKXXX_HOME before running wirkXXX" << endl;
|
---|
59 | ok = false;
|
---|
60 | }
|
---|
61 | if ( !ok ) {
|
---|
62 | return -1;
|
---|
63 | }
|
---|
64 |
|
---|
65 | //load environment variables
|
---|
66 | string JAVA_HOME = getenv( "JAVA_HOME" );
|
---|
67 | string WIRKXXX_HOME = getenv( "WIRKXXX_HOME" );
|
---|
68 | putenv( ("ANT_HOME=" + WIRKXXX_HOME + "\\core\\ant").c_str() );
|
---|
69 |
|
---|
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" );
|
---|
77 |
|
---|
78 | //create the command
|
---|
79 | command = WIRKXXX_HOME + "\\core\\ant\\bin\\ant.bat -f \"" + WIRKXXX_HOME + "\\ant-scripts\\build.xml\" -addressing \"-Dwirk3.home=" + WIRKXXX_HOME + "\"";
|
---|
80 |
|
---|
81 | //pass on the arguments
|
---|
82 | string a;
|
---|
83 | bool simMode = false;
|
---|
84 | for ( int i=0; i < argc; i++ ) {
|
---|
85 | a = argv[i];
|
---|
86 |
|
---|
87 | if ( a.compare("-help") == 0 || a.compare("--help") == 0 ) {
|
---|
88 | show_help();
|
---|
89 | return 0;
|
---|
90 | } else if ( a.compare("-cp") == 0 || a.compare("--cp") == 0 ) {
|
---|
91 | cout << classpath;
|
---|
92 | return 0;
|
---|
93 | } else if ( a.compare("-sim") == 0) {
|
---|
94 | command = command + " " + a;
|
---|
95 | simMode = true;
|
---|
96 | } else {
|
---|
97 | command = command + " " + a;
|
---|
98 | }
|
---|
99 |
|
---|
100 | }
|
---|
101 |
|
---|
102 | //set the basedir in the command
|
---|
103 | command = command + " \"-Dbasedir=" + pwd + "\"";
|
---|
104 |
|
---|
105 | cout
|
---|
106 | << "O-----------------------------------------O" << endl
|
---|
107 | << "| |" << endl
|
---|
108 | << "| WiRKXXX |" << endl
|
---|
109 | << "| Windows Release Kit for GreenstoneXXX |" << endl
|
---|
110 | << "| |" << endl
|
---|
111 | << "O-----------------------------------------O" << endl
|
---|
112 | ;
|
---|
113 |
|
---|
114 | cout << "pwd: " << pwd << endl;
|
---|
115 | cout << "command: " << command << endl;
|
---|
116 |
|
---|
117 | system( command.c_str() );
|
---|
118 |
|
---|
119 | return 0;
|
---|
120 |
|
---|
121 | }
|
---|