|
Message
From: cvs at opencores.org<cvs@o...>
Date: Mon Feb 25 03:49:22 CET 2008
Subject: [cvs-checkins] MODIFIED: jop ...
Date: 00/08/02 25:03:49 Modified: jop/java/tools/src/joptimizer jop.conf cmdline.conf JOPtimizerRunner.java Log: loading arch config from property-file allow to load configfile from cmdline Revision Changes Path 1.9 jop/java/tools/src/joptimizer/jop.conf http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/joptimizer/jop.conf.diff?r1=1.8&r2=1.9 (In the diff below, changes in quantity of whitespace are not shown.) Index: jop.conf =================================================================== RCS file: /cvsroot/stefant/jop/java/tools/src/joptimizer/jop.conf,v retrieving revision 1.8 retrieving revision 1.9 diff -u -b -r1.8 -r1.9 --- jop.conf 24 Feb 2008 20:19:13 -0000 1.8 +++ jop.conf 25 Feb 2008 02:49:21 -0000 1.9 @@ -1,4 +1,5 @@ # Set default classpath and output-dir +arch=jop cp=java/target/dist/classes/ writeclasses.out=java/target/dist/classes/ ignore-errors=true 1.9 jop/java/tools/src/joptimizer/cmdline.conf http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/joptimizer/cmdline.conf.diff?r1=1.8&r2=1.9 (In the diff below, changes in quantity of whitespace are not shown.) Index: cmdline.conf =================================================================== RCS file: /cvsroot/stefant/jop/java/tools/src/joptimizer/cmdline.conf,v retrieving revision 1.8 retrieving revision 1.9 diff -u -b -r1.8 -r1.9 --- cmdline.conf 24 Feb 2008 20:19:13 -0000 1.8 +++ cmdline.conf 25 Feb 2008 02:49:21 -0000 1.9 @@ -1,4 +1,5 @@ # Set default classpath and output-dir +arch=jop cp=${JOP_HOME}/java/target/dist/classes.orig/ writeclasses.out=${JOP_HOME}/java/target/dist/classes/ ignore-errors=true 1.7 jop/java/tools/src/joptimizer/JOPtimizerRunner.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/joptimizer/JOPtimizerRunner.java.diff?r1=1.6&r2=1.7 (In the diff below, changes in quantity of whitespace are not shown.) Index: JOPtimizerRunner.java =================================================================== RCS file: /cvsroot/stefant/jop/java/tools/src/joptimizer/JOPtimizerRunner.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -b -r1.6 -r1.7 --- JOPtimizerRunner.java 17 Feb 2008 20:47:29 -0000 1.6 +++ JOPtimizerRunner.java 25 Feb 2008 02:49:21 -0000 1.7 @@ -21,27 +21,20 @@ import com.jopdesign.libgraph.struct.TypeException; import joptimizer.config.ArgOption; import joptimizer.config.ArgumentException; +import joptimizer.config.ConfigurationException; import joptimizer.config.JopConfig; -import joptimizer.config.StringOption; import joptimizer.framework.CmdLine; +import joptimizer.framework.ConfigLoader; import joptimizer.framework.JOPtimizer; import joptimizer.framework.actions.ActionException; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; import java.io.PrintStream; -import java.io.Reader; import java.net.URL; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; -import java.util.Map; -import java.util.Properties; import java.util.Set; /** @@ -53,35 +46,12 @@
public static Logger logger = Logger.getLogger(JOPtimizerRunner.class);
- private static Map options;
+ private static List options;
private static String mainClass;
private static boolean doCmdLine;
private static boolean doSkipLoad;
- public static final String CONF_LOGCONF_FILE = "logconf";
- public static final String CONF_CLASSPATH = "cp";
-
- private static void initArguments(JOPtimizer joptimizer) {
-
- List optionList = new LinkedList();
-
- optionList.add(new StringOption(null, CONF_CLASSPATH,
- "Set the classpath, default is '.'.", "classpath"));
-
- JopConfig.createOptions(optionList);
-
- optionList.addAll(joptimizer.getActionFactory().createActionArguments());
-
- // hash options by name
- options = new LinkedHashMap();
- for (int i = 0; i < optionList.size(); i++) {
- ArgOption option = (ArgOption) optionList.get(i);
- options.put(option.getFullName(), option);
- }
-
- }
-
/**
* Print out a usage text about this tool.
*
@@ -103,7 +73,7 @@
out.println(" -config <configfile> An url to a properties-file which may contain");
out.println(" any of the following options.");
- for (Iterator it = options.values().iterator(); it.hasNext();) {
+ for (Iterator it = options.iterator(); it.hasNext();) {
ArgOption option = (ArgOption) it.next();
if ( option.isVisible() ) {
option.printHelp(" -", out);
@@ -118,12 +88,12 @@
* The last classname will be set in mainClass.
*
* @param args the arguments to read.
- * @param config the configuration which will be updated with the parsed options.
+ * @param config the configuration loader which will be used to parse and store the options.
* @param startClasses a set of classnames which will be filled with the given start class names.
* @throws ArgumentException
* @return false, if the program should terminate without executing anything, else true.
*/
- public static boolean parseArguments(String[] args, Properties config, Set startClasses) throws ArgumentException {
+ public static boolean parseArguments(String[] args, ConfigLoader config, Set startClasses) throws ArgumentException {
for (int i = 0; i < args.length; i++) {
@@ -141,45 +111,15 @@
if ( args.length <= i + 1 ) {
throw new ArgumentException("Missing configfile argument for '-config'.");
}
-
- Properties propfile = new Properties();
- String filename = args[++i];
- try {
- if ( logger.isInfoEnabled() ) {
- logger.info("Reading configuration file {"+filename+"}.");
- }
-
- // not using class.getResource() here as the config file is usually outside the classpath.
- URL file = new URL(filename);
- Reader reader = new BufferedReader(new InputStreamReader(file.openStream()));
- propfile.load(reader);
-
- } catch (IOException e) {
- if (logger.isDebugEnabled()) {
- logger.debug("Error loading configfile {" + filename + "}.", e);
- }
- throw new ArgumentException("Could not load configfile {"+filename+"}: " + e.getMessage());
- }
-
- // Quick hack to allow usage of environment variables in config.
- for (Iterator it = propfile.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- String arg = entry.getKey().toString();
-
- if (logger.isInfoEnabled() ) {
- logger.info("Found option {"+entry.getKey()+"} with value {"+entry.getValue()+"}");
- }
-
- loadOption(arg, new String[] {arg, entry.getValue().toString()}, 0, config);
- }
-
+ config.loadOptionFile(args[++i]);
continue;
}
// check if argument is a configuration option
+ // TODO handling of quotes and '='
if ( args[i].startsWith("-") ) {
String arg = args[i].substring(1);
- i+= loadOption(arg, args, i, config);
+ i+= config.loadOption(arg, args, i);
continue;
}
@@ -192,21 +132,6 @@
return true;
}
- private static int loadOption(String arg, String[] args, int pos, Properties config) throws ArgumentException {
-
- int ret;
- ArgOption option = (ArgOption) options.get(arg);
-
- if ( option != null ) {
-
- ret = option.parse(arg, args, pos, config);
-
- } else {
- throw new ArgumentException("Unrecognized option '" + arg + "'.");
- }
- return ret;
- }
-
/**
* initialize log4j from a configfile.
* @param configFile the filename of a log4j property file
@@ -230,7 +155,7 @@
JopConfig jopConfig = new JopConfig();
JOPtimizer joptimizer = new JOPtimizer(jopConfig);
- initArguments(joptimizer);
+ options = ConfigLoader.getDefaultOptions(joptimizer);
// need at least one argument for root class.
if ( args.length == 0 ) {
@@ -238,7 +163,7 @@
return;
}
- Properties config = new Properties();
+ ConfigLoader config = new ConfigLoader( options );
Set rootClasses = new HashSet();
// parse args into properties, set rootclasses
@@ -257,13 +182,17 @@
System.exit(2);
}
- String classPath = config.getProperty(CONF_CLASSPATH, ".");
- joptimizer.getAppStruct().setClassPath(classPath);
+ try {
+ config.storeConfig(joptimizer);
+ } catch (ConfigurationException e) {
+ System.err.println("Could not parse options: " + e.getMessage());
+ logger.info("Could not parse options.", e);
+ System.exit(2);
+ }
// setup config
rootClasses.addAll(jopConfig.getArchConfig().getSystemClasses());
- jopConfig.setProperties(config);
jopConfig.setMainClassName(mainClass);
jopConfig.setRootClasses(rootClasses);
|
 |