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 | if( inputDir == null || outputDir == null ){
|
---|
67 | usage();
|
---|
68 | System.exit(0);
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 | /* check if index dir exists */
|
---|
73 | File in = new File(inputDir);
|
---|
74 | if (!in.isDirectory()) {
|
---|
75 | System.err.println("input directory ("+inputDir+") not a directory, exiting...");
|
---|
76 | System.exit(0);
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**** check if output directory exist, if not create it ****/
|
---|
80 |
|
---|
81 | File f = new File(outputDir);
|
---|
82 | if( !f.exists() ){
|
---|
83 | try {
|
---|
84 | f.mkdirs();
|
---|
85 | } catch (Exception e) {
|
---|
86 | System.err.println("Couldn't create output directory "+outputDir);
|
---|
87 | System.err.println(e);
|
---|
88 | System.exit(0);
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | // new mg requires a .mg_getrc to work
|
---|
93 | // lets put it in the output dir
|
---|
94 | File rc_file = new File(f, ".mg_getrc");
|
---|
95 | if (!rc_file.exists()) {
|
---|
96 | // if its there, assume it is correct
|
---|
97 | try {
|
---|
98 | rc_file.createNewFile();
|
---|
99 | BufferedWriter rc_out = new BufferedWriter(new FileWriter(rc_file, true));
|
---|
100 | String data_line = collName+"\tDIR2\t"+inputDir;
|
---|
101 | rc_out.write(data_line, 0, data_line.length());
|
---|
102 | rc_out.newLine();
|
---|
103 | rc_out.flush();
|
---|
104 | rc_out.close();
|
---|
105 | } catch (Exception ex) {
|
---|
106 | System.err.println(ex);
|
---|
107 | System.err.println("Unable to create file "+rc_file.getPath()+", cancelling build");
|
---|
108 | System.exit(0);
|
---|
109 | }
|
---|
110 | }
|
---|
111 | /*
|
---|
112 | if( !f.exists() ){
|
---|
113 | System.out.println("Creating output directory..");
|
---|
114 |
|
---|
115 | StringTokenizer strt = new StringTokenizer(outputDir,"/");
|
---|
116 | String d = "";
|
---|
117 | while(strt.hasMoreTokens()){
|
---|
118 | String str = strt.nextToken();
|
---|
119 | if( str.indexOf(".") == -1 ){
|
---|
120 | d += "/" + str;
|
---|
121 | if( !(new File(d)).exists() ){
|
---|
122 | try{
|
---|
123 | Runtime rt = Runtime.getRuntime();
|
---|
124 | Process proc = rt.exec("mkdir " + d);
|
---|
125 | int exitVal = proc.waitFor();
|
---|
126 | }catch(Exception ex){ex.printStackTrace();}
|
---|
127 | }
|
---|
128 | }
|
---|
129 | }
|
---|
130 | }
|
---|
131 | */
|
---|
132 | try{
|
---|
133 | //String command = /*GSDL3_HOME +*/ "/packages/VIS/" + "MG/mg/mg-1.2.1/bin/mgbuild -d " + outputDir + " -i " + inputDir + " " + collName;
|
---|
134 | //String command = "mgbuild -d " + outputDir + " -i " + inputDir + " " + collName;
|
---|
135 | // requires .mg_getrc file
|
---|
136 | String []env = new String [1];
|
---|
137 | env[0] = "MG_GETRC="+outputDir+".mg_getrc";
|
---|
138 | String command = "mgbuild -d " + outputDir + " " + collName;
|
---|
139 | System.out.println("Executing.. " + command);
|
---|
140 | Process proc = Runtime.getRuntime().exec(command, env);
|
---|
141 | proc.waitFor();
|
---|
142 | System.out.println(proc.exitValue());
|
---|
143 | }
|
---|
144 | catch(IOException ex){ex.printStackTrace();}
|
---|
145 | catch (InterruptedException ex){ System.out.println(ex); ex.printStackTrace();
|
---|
146 | }
|
---|
147 | }
|
---|
148 | }
|
---|