source: release-kits/wirk3/src/wirk3.cpp@ 17368

Last change on this file since 17368 was 17368, checked in by oranfry, 16 years ago

show helpful error message instead of crashing

File size: 6.4 KB
RevLine 
[15023]1#include <windows.h>
2
3#include <fstream>
4#include <iostream>
5#include <string>
6
7using namespace std;
8
9void 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
[17045]20void show_help() {
21
22 cout << "Wirk3 - Windows Release Kit for Greenstone3" << endl;
23 cout << "Helps you to create releases from the Repository" << endl << endl;
24
25 cout << "usage: wirk3 [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
[15023]46int main(int argc, char** argv ) {
47
48 string classpath, command;
49
[17368]50 //some checks
51 bool ok = true;
52 if ( getenv( "JAVA_HOME" ) == NULL ) {
53 cerr << "Please set JAVA_HOME before running wirk3" << endl;
54 ok = false;
55 }
56 if ( getenv( "WIRK3_HOME" ) == NULL ) {
57 cerr << "Please set WIRK2_HOME before running wirk3" << endl;
58 ok = false;
59 }
60 if ( !ok ) {
61 return -1;
62 }
63
[15023]64 //influential environment variables
65 string JAVA_HOME = getenv( "JAVA_HOME" );
66 string WIRK3_HOME = getenv( "WIRK3_HOME" );
67 //string PWD = getenv( "CD" );
[15356]68
69 //get the pwd
70 string pwd;
71 system( "CD > cd.dat" );
72 ifstream file( "cd.dat" ) ;
73 getline(file, pwd);
74 file.close();
75 system( "del cd.dat" );
[15023]76
77 //set the classpath
[17339]78 classpath = pwd + "\\installer\\classes;" + JAVA_HOME + "\\lib\\tools.jar;" + WIRK3_HOME + "\\lib\\serializer.jar;" + WIRK3_HOME + "\\lib\\xalan.jar;" + WIRK3_HOME + "\\lib\\xercesImpl.jar;" + WIRK3_HOME + "\\lib\\xml-apis.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-antlr.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-apache-bcel.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-apache-bsf.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-apache-log4j.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-apache-oro.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-apache-regexp.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-apache-resolver.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-commons-logging.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-commons-net.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-icontract.jar;" + WIRK3_HOME + "\\packages\\ant-1.6.5\\lib\\ant-jai.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-javamail.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-jdepend.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-jmf.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-jsch.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-junit.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-launcher.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-netrexx.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-nodeps.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-starteam.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-stylebook.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-swing.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-trax.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-vaj.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-weblogic.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-xalan1.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\ant-xslp.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\xercesImpl.jar;" + WIRK3_HOME + "\\packages\\ant\\lib\\xml-apis.jar;" + WIRK3_HOME + "\\packages\\ant-installer\\lib\\ai-icons-amaranth.jar;" + WIRK3_HOME + "\\packages\\ant-installer\\lib\\ai-icons-bluecurve.jar;" + WIRK3_HOME + "\\packages\\ant-installer\\lib\\ai-icons-crystalsvg.jar;" + WIRK3_HOME + "\\packages\\ant-installer\\lib\\ai-icons-eclipse.jar;" + WIRK3_HOME + "\\packages\\ant-installer\\lib\\ai-icons-krystaline.jar;" + WIRK3_HOME + "\\packages\\ant-installer\\lib\\ant-installer-ext.jar;" + WIRK3_HOME + "\\packages\\ant-installer\\lib\\ant-installer.jar;" + WIRK3_HOME + "\\packages\\ant-installer\\lib\\jgoodies-edited-1_2_2.jar;" + WIRK3_HOME + "\\packages\\ant-installer\\lib\\xercesImpl.jar;" + WIRK3_HOME + "\\packages\\ant-installer\\lib\\xml-apis.jar;" + WIRK3_HOME + "\\packages\\ant-installer\\classes;" + WIRK3_HOME + "\\ant-scripts\\tasks\\svnant\\lib\\svnjavahl.jar;" + WIRK3_HOME + "\\ant-scripts\\tasks\\svnant\\lib\\svnant.jar;" + WIRK3_HOME + "\\ant-scripts\\tasks\\svnant\\lib\\svnClientAdapter.jar";
[15023]79 putenv( ("CLASSPATH=" + classpath).c_str() );
[17368]80 putenv( "SystemDrive=C:" );
[15023]81
82 //create the command
[17339]83 command = "\"\"" + WIRK3_HOME + "\\packages\\ant\\bin\\ant.bat\" -f \"" + WIRK3_HOME + "\\ant-scripts\\build.xml\" -addressing \"-Dwirk3.home=" + WIRK3_HOME + "\"";
[15023]84 //pass on the arguments
85 string a;
[16930]86 bool simMode = false;
[15023]87 for ( int i=0; i < argc; i++ ) {
88 a = argv[i];
89
[17048]90 if ( a.compare("-help") == 0 || a.compare("--help") == 0 ) {
[17045]91 show_help();
[15023]92 return 0;
[17048]93 } else if ( a.compare("-cp") == 0 || a.compare("--cp") == 0 ) {
[15023]94 cout << classpath;
95 return 0;
[16930]96 } else if ( a.compare("-sim") == 0) {
97 command = command + " " + a;
98 simMode = true;
[15023]99 } else {
100 command = command + " " + a;
101 }
102
103 }
[15356]104
[16930]105 //create directories
106 if ( !simMode ) {
107 system( "IF NOT EXIST installer\\classes MKDIR installer\\classes" );
108 }
109
[15023]110
[15356]111 //use forward slashes for everything else
112 //replace_all( pwd, "\\", "/" );
113
[15023]114 //set the basedir in the command
[17339]115 command = command + " \"-Dbasedir=";
116 command = command + pwd + "\"\"";
[15356]117
[15023]118 //command = command + ".";
119
[15095]120 cout
121 << "O-----------------------------------------O" << endl
122 << "| |" << endl
123 << "| WiRK3 |" << endl
124 << "| Windows Release Kit for Greenstone3 |" << endl
125 << "| |" << endl
126 << "O-----------------------------------------O" << endl
127 ;
[15023]128
129 cout << "pwd: " << pwd << endl;
[17339]130 cout << "command: " << command.c_str() << endl;
[15023]131
132 system( command.c_str() );
133
134 return 0;
135
[16750]136}
Note: See TracBrowser for help on using the repository browser.