001: /*
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found in file GTPL, or at
004: * http://www.globus.org/toolkit/download/license.html. This notice must
005: * appear in redistributions of this file, with or without modification.
006: *
007: * Redistributions of this Software, with or without modification, must
008: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009: * some other similar material which is provided with the Software (if
010: * any).
011: *
012: * Copyright 1999-2004 University of Chicago and The University of
013: * Southern California. All rights reserved.
014: */
015:
016: package org.griphyn.vdl.toolkit;
017:
018: import java.io.*;
019: import java.util.*;
020: import org.griphyn.common.util.Version;
021: import org.griphyn.vdl.dax.*;
022: import org.griphyn.vdl.classes.LFN;
023: import org.griphyn.vdl.parser.DAXParser;
024: import org.griphyn.vdl.util.Logging;
025: import org.griphyn.vdl.directive.Derive;
026: import gnu.getopt.*;
027:
028: /**
029: * The shell planner. This class is the command-line tool for
030: * generating shell scripts from a DAX.
031: *
032: * @author Jens-S. Vöckler
033: * @author Yong Zhao
034: * @version $Revision: 50 $
035: *
036: */
037: public class Planner extends Toolkit {
038: /**
039: * Constructs a new instance object with the given application name.
040: */
041: public Planner(String appName) {
042: super (appName);
043: }
044:
045: /**
046: * Prints the usage string onto stdout.
047: */
048: public void showUsage() {
049: String linefeed = System.getProperty("line.separator", "\r\n");
050:
051: System.out
052: .println("$Id: Planner.java 50 2007-05-19 00:48:32Z gmehta $"
053: + linefeed
054: + "VDS version "
055: + Version.instance().toString() + linefeed);
056:
057: System.out.println("Usage: " + this .m_application
058: + " [general] [-o dir] [-k fn] [-b] [-n] dax");
059:
060: System.out
061: .println(linefeed
062: + " -V|--version print version information and exit."
063: + linefeed
064: + " -v|--verbose increases the verbosity level."
065: + linefeed
066: + " -o|--output dir directory where scripts are created, defaults to test."
067: + linefeed
068: + " -b|--build enters build mode, default is make mode."
069: + linefeed
070: + " -n|--no-register does not register produced files at all."
071: + linefeed
072: + " -k|--kickstart fn uses kickstart from the specified location fn."
073: + linefeed);
074: }
075:
076: /**
077: * Creates a set of commandline options.
078: */
079: protected LongOpt[] generateValidOptions() {
080: LongOpt[] lo = new LongOpt[7];
081:
082: lo[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
083: lo[1] = new LongOpt("version", LongOpt.NO_ARGUMENT, null, 'V');
084: lo[2] = new LongOpt("verbose", LongOpt.NO_ARGUMENT, null, 'v');
085:
086: lo[3] = new LongOpt("build", LongOpt.NO_ARGUMENT, null, 'b');
087: lo[4] = new LongOpt("output", LongOpt.REQUIRED_ARGUMENT, null,
088: 'o');
089: lo[5] = new LongOpt("no-register", LongOpt.NO_ARGUMENT, null,
090: 'n');
091: lo[6] = new LongOpt("kickstart", LongOpt.REQUIRED_ARGUMENT,
092: null, 'k');
093:
094: return lo;
095: }
096:
097: /**
098: * Get the DAX and generate shell scripts in the designated directory.
099: * It also decides whether to run in a 'make' or 'build' mode
100: */
101: public static void main(String[] args) {
102: int result = 0;
103:
104: // register the logger for search
105: try {
106: Planner me = new Planner("shplanner");
107:
108: // get the commandline options
109: Getopt opts = new Getopt(me.m_application, args,
110: "hbk:no:Vv", me.generateValidOptions());
111: opts.setOpterr(false);
112: String dir = "test"; // where to produce files, default is "test"
113: boolean build = false;
114: boolean register = true;
115: String kickstart = null;
116: int verbosity = 0;
117:
118: int option = 0;
119: while ((option = opts.getopt()) != -1) {
120: switch (option) {
121: case 'v':
122: verbosity = me.increaseVerbosity();
123: break;
124:
125: case 'V':
126: System.out
127: .println("$Id: Planner.java 50 2007-05-19 00:48:32Z gmehta $");
128: System.out.println("VDS version "
129: + Version.instance().toString());
130: return;
131:
132: case 'b':
133: build = true;
134: break;
135:
136: case 'k':
137: kickstart = opts.getOptarg();
138: break;
139:
140: case 'o':
141: dir = opts.getOptarg();
142: break;
143:
144: case 'n':
145: register = false;
146: break;
147:
148: case 'h':
149: default:
150: me.showUsage();
151: return;
152: }
153: }
154:
155: // did the user specify exactly one DAX file?
156: String daxfn = null;
157: if (opts.getOptind() >= args.length
158: || opts.getOptind() < args.length - 1)
159: throw new RuntimeException(
160: "You must specify exactly one (1) input file");
161: else
162: daxfn = args[opts.getOptind()];
163:
164: // do something about verbosity
165: if (verbosity > 0)
166: me.m_logger.register("planner", System.out, verbosity);
167:
168: // the directory name to hold shell scripts
169: if (dir == null || dir.length() == 0) {
170: me.m_logger
171: .log("planner", 0,
172: "Output directory not specified, using default: test");
173: dir = "test";
174: }
175:
176: // check the dax file
177: FileInputStream fs = new FileInputStream(daxfn);
178: Derive derive = new Derive();
179:
180: if (!derive.genShellScripts(fs, dir, build, register,
181: kickstart)) {
182: me.m_logger.log("default", 0,
183: "ERROR: Failed to generate shell scripts!");
184: result = 1;
185: }
186: } catch (RuntimeException rte) {
187: System.err.println(rte.getMessage());
188: result = 1;
189: } catch (Exception e) {
190: e.printStackTrace();
191: result = 2;
192: }
193:
194: if (result != 0)
195: System.exit(result);
196: }
197: }
|