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 << "Wirk2 - Windows Release Kit for Greenstone2" << endl;
|
---|
23 | cout << "Helps you to create releases from the Repository" << endl << endl;
|
---|
24 |
|
---|
25 | cout << "usage: wirk2 [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 wirk2" << endl << endl;
|
---|
43 |
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | int main(int argc, char** argv ) {
|
---|
48 |
|
---|
49 | string classpath, command;
|
---|
50 |
|
---|
51 | //influential environment variables
|
---|
52 | string JAVA_HOME = getenv( "JAVA_HOME" );
|
---|
53 | string WIRK2_HOME = getenv( "WIRK2_HOME" );
|
---|
54 | //string PWD = getenv( "CD" );
|
---|
55 |
|
---|
56 | //get the pwd
|
---|
57 | string pwd;
|
---|
58 | system( "CD > cd.dat" );
|
---|
59 | ifstream file( "cd.dat" ) ;
|
---|
60 | getline(file, pwd);
|
---|
61 | file.close();
|
---|
62 | system( "del cd.dat" );
|
---|
63 |
|
---|
64 |
|
---|
65 | //set the classpath
|
---|
66 | classpath = pwd + "\\installer\\classes;" + JAVA_HOME + "\\lib\\tools.jar;" + WIRK2_HOME + "\\lib\\serializer.jar;" + WIRK2_HOME + "\\lib\\xalan.jar;" + WIRK2_HOME + "\\lib\\xercesImpl.jar;" + WIRK2_HOME + "\\lib\\xml-apis.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-antlr.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-apache-bcel.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-apache-bsf.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-apache-log4j.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-apache-oro.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-apache-regexp.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-apache-resolver.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-commons-logging.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-commons-net.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-icontract.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-jai.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-javamail.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-jdepend.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-jmf.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-jsch.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-junit.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-launcher.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-netrexx.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-nodeps.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-starteam.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-stylebook.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-swing.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-trax.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-vaj.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-weblogic.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-xalan1.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\ant-xslp.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\xercesImpl.jar;" + WIRK2_HOME + "\\packages\\ant\\lib\\xml-apis.jar;" + WIRK2_HOME + "\\packages\\ant-installer\\lib\\ai-icons-amaranth.jar;" + WIRK2_HOME + "\\packages\\ant-installer\\lib\\ai-icons-bluecurve.jar;" + WIRK2_HOME + "\\packages\\ant-installer\\lib\\ai-icons-crystalsvg.jar;" + WIRK2_HOME + "\\packages\\ant-installer\\lib\\ai-icons-eclipse.jar;" + WIRK2_HOME + "\\packages\\ant-installer\\lib\\ai-icons-krystaline.jar;" + WIRK2_HOME + "\\packages\\ant-installer\\lib\\ant-installer-ext.jar;" + WIRK2_HOME + "\\packages\\ant-installer\\lib\\ant-installer.jar;" + WIRK2_HOME + "\\packages\\ant-installer\\lib\\jgoodies-edited-1_2_2.jar;" + WIRK2_HOME + "\\packages\\ant-installer\\lib\\xercesImpl.jar;" + WIRK2_HOME + "\\packages\\ant-installer\\lib\\xml-apis.jar;" + WIRK2_HOME + "\\packages\\ant-installer\\classes";
|
---|
67 | putenv( ("CLASSPATH=" + classpath).c_str() );
|
---|
68 |
|
---|
69 | //check that it worked
|
---|
70 | //string changed_classpath = getenv("CLASSPATH");
|
---|
71 | //cout << "classpath: " << changed_classpath << endl;
|
---|
72 |
|
---|
73 | //create the command
|
---|
74 | command = WIRK2_HOME + "\\packages\\ant\\bin\\ant.bat -f " + WIRK2_HOME + "\\ant-scripts\\build.xml -addressing -Dwirk2.home=" + WIRK2_HOME;
|
---|
75 | //pass on the arguments
|
---|
76 | string a;
|
---|
77 | bool simMode = false;
|
---|
78 | for ( int i=0; i < argc; i++ ) {
|
---|
79 | a = argv[i];
|
---|
80 |
|
---|
81 | if ( a.compare("-help") == 0 || a.compare("--help") == 0 ) {
|
---|
82 | show_help();
|
---|
83 | return 0;
|
---|
84 | } else if ( a.compare("-cp") == 0 || a.compare("--cp") == 0 ) {
|
---|
85 | cout << classpath;
|
---|
86 | return 0;
|
---|
87 | } else if ( a.compare("-sim") == 0) {
|
---|
88 | command = command + " " + a;
|
---|
89 | simMode = true;
|
---|
90 | } else {
|
---|
91 | command = command + " " + a;
|
---|
92 | }
|
---|
93 |
|
---|
94 | }
|
---|
95 |
|
---|
96 | //create directories
|
---|
97 | if ( !simMode ) {
|
---|
98 | system( "IF NOT EXIST installer\\classes MKDIR installer\\classes" );
|
---|
99 | }
|
---|
100 |
|
---|
101 | //use forward slashes for everything else
|
---|
102 | //replace_all( pwd, "\\", "/" );
|
---|
103 |
|
---|
104 | //set the basedir in the command
|
---|
105 | command = command + " -Dbasedir=";
|
---|
106 | command = command + pwd;
|
---|
107 |
|
---|
108 |
|
---|
109 |
|
---|
110 | //command = command + ".";
|
---|
111 |
|
---|
112 | cout
|
---|
113 | << "O-----------------------------------------O" << endl
|
---|
114 | << "| |" << endl
|
---|
115 | << "| WiRK2 |" << endl
|
---|
116 | << "| Windows Release Kit for Greenstone2 |" << endl
|
---|
117 | << "| |" << endl
|
---|
118 | << "O-----------------------------------------O" << endl
|
---|
119 | ;
|
---|
120 |
|
---|
121 | cout << "pwd: " << pwd << endl;
|
---|
122 | cout << "command: " << command << endl;
|
---|
123 |
|
---|
124 | system( command.c_str() );
|
---|
125 |
|
---|
126 | return 0;
|
---|
127 |
|
---|
128 | }
|
---|