1 | package vishnu.builder;
|
---|
2 |
|
---|
3 | import java.io.*;
|
---|
4 | import java.util.*;
|
---|
5 |
|
---|
6 | public class MGWrapper extends Indexer
|
---|
7 | {
|
---|
8 | private static void usage()
|
---|
9 | {
|
---|
10 | System.out.println("java Indexer MGWrapper -i InputDirectory \n -o OutputDirectory \n -c CollectionName");
|
---|
11 | }
|
---|
12 |
|
---|
13 |
|
---|
14 | public static void main(String[] args)
|
---|
15 | {
|
---|
16 | String in = null;
|
---|
17 | String out = null;
|
---|
18 | String coll = null;
|
---|
19 |
|
---|
20 | if( args.length == 0 ){
|
---|
21 | usage();
|
---|
22 | System.exit(0);
|
---|
23 | }
|
---|
24 |
|
---|
25 | int a = 0;
|
---|
26 | while( a < args.length ){
|
---|
27 | if( args[a].equals("-i") )
|
---|
28 | in = args[++a];
|
---|
29 | if( args[a].equals("-o") )
|
---|
30 | out = args[++a];
|
---|
31 | if( args[a].equals("-c") )
|
---|
32 | coll = args[++a];
|
---|
33 | a++;
|
---|
34 | }
|
---|
35 |
|
---|
36 | if (out==null || in==null|| coll==null) {
|
---|
37 | usage();
|
---|
38 | System.exit(0);
|
---|
39 | }
|
---|
40 | if (!out.endsWith(File.separator)) {
|
---|
41 | out += File.separator;
|
---|
42 | }
|
---|
43 | if (!in.endsWith(File.separator)) {
|
---|
44 | in += File.separator;
|
---|
45 | }
|
---|
46 |
|
---|
47 | out = out + "mg_index" + File.separator;
|
---|
48 |
|
---|
49 | MGWrapper mgw = new MGWrapper();
|
---|
50 | mgw.setCollectionName(coll);
|
---|
51 | mgw.setOutputDirectory(out);
|
---|
52 | mgw.setInputDirectory(in);
|
---|
53 | mgw.startIndexing();
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | public MGWrapper()
|
---|
58 | {
|
---|
59 | super("Managing Gigabytes Indexer");
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | public void startIndexing()
|
---|
64 | {
|
---|
65 |
|
---|
66 | initialize();
|
---|
67 | // new mg requires a .mg_getrc to work
|
---|
68 | // lets put it in the output dir
|
---|
69 | File rc_file = new File(outputDir, ".mg_getrc");
|
---|
70 | if (!rc_file.exists()) {
|
---|
71 | // if its there, assume it is correct
|
---|
72 | try {
|
---|
73 | rc_file.createNewFile();
|
---|
74 | BufferedWriter rc_out = new BufferedWriter(new FileWriter(rc_file, true));
|
---|
75 | String data_line = collName+"\tDIR2\t"+inputDir;
|
---|
76 | rc_out.write(data_line, 0, data_line.length());
|
---|
77 | rc_out.newLine();
|
---|
78 | rc_out.flush();
|
---|
79 | rc_out.close();
|
---|
80 | } catch (Exception ex) {
|
---|
81 | System.err.println(ex);
|
---|
82 | System.err.println("Unable to create file "+rc_file.getPath()+", cancelling build");
|
---|
83 | System.exit(0);
|
---|
84 | }
|
---|
85 | }
|
---|
86 | /*
|
---|
87 | if( !f.exists() ){
|
---|
88 | System.out.println("Creating output directory..");
|
---|
89 |
|
---|
90 | StringTokenizer strt = new StringTokenizer(outputDir,"/");
|
---|
91 | String d = "";
|
---|
92 | while(strt.hasMoreTokens()){
|
---|
93 | String str = strt.nextToken();
|
---|
94 | if( str.indexOf(".") == -1 ){
|
---|
95 | d += "/" + str;
|
---|
96 | if( !(new File(d)).exists() ){
|
---|
97 | try{
|
---|
98 | Runtime rt = Runtime.getRuntime();
|
---|
99 | Process proc = rt.exec("mkdir " + d);
|
---|
100 | int exitVal = proc.waitFor();
|
---|
101 | }catch(Exception ex){ex.printStackTrace();}
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|
106 | */
|
---|
107 | try{
|
---|
108 | //String command = /*GSDL3_HOME +*/ "/packages/VIS/" + "MG/mg/mg-1.2.1/bin/mgbuild -d " + outputDir + " -i " + inputDir + " " + collName;
|
---|
109 | //String command = "mgbuild -d " + outputDir + " -i " + inputDir + " " + collName;
|
---|
110 | // requires .mg_getrc file
|
---|
111 | String []env = new String [1];
|
---|
112 | env[0] = "MG_GETRC="+outputDir+".mg_getrc";
|
---|
113 | String command = "mgbuild -d " + outputDir + " " + collName;
|
---|
114 | System.out.println("Executing.. " + command);
|
---|
115 | Process proc = Runtime.getRuntime().exec(command, env);
|
---|
116 | proc.waitFor();
|
---|
117 | System.out.println(proc.exitValue());
|
---|
118 | }
|
---|
119 | catch(IOException ex){ex.printStackTrace();}
|
---|
120 | catch (InterruptedException ex){ System.out.println(ex); ex.printStackTrace();
|
---|
121 | }
|
---|
122 | }
|
---|
123 | }
|
---|