LOGIN   :::   RECOVER PASS   :::   GET ACCOUNT    
Browse
  • Projects
  • Code (CVS)
  • Forums
  • News
  • Articles
  • Polls
  •  
    OpenCores
  • FAQ
  • CVS HowTo
  • Mission
  • Media
  • Tools
  • Advertise
  • Mirrors
  • Logos
  • Contact us
  • Job Opportunity
  •  
    Tools
  • Search
      
  • Download Cores (CVSGet)
  •  
    More
  • Wishbone
  • Perlilog
  • EDA tools
  • OpenTech CD
  •  
    Navigation: All forums > Cvs-checkins > Message List > Message Post

    Message

    Reply | Reply all
    Date Prev | Date Next | Thread Prev | Thread Next Date Index | Thread Index

    From: cvs at opencores.org<cvs@o...>
    Date: Mon Feb 25 03:49:22 CET 2008
    Subject: [cvs-checkins] MODIFIED: jop ...
    Top
    Date: 00/08/02 25:03:49

    Modified: jop/java/tools/src/joptimizer/framework CmdLine.java
    JOPtimizer.java
    Added: jop/java/tools/src/joptimizer/framework ConfigLoader.java
    Log:
    loading arch config from property-file

    allow to load configfile from cmdline


    Revision Changes Path
    1.3 jop/java/tools/src/joptimizer/framework/CmdLine.java

    http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/joptimizer/framework/CmdLine.java.diff?r1=1.2&r2=1.3

    (In the diff below, changes in quantity of whitespace are not shown.)

    Index: CmdLine.java
    ===================================================================
    RCS file: /cvsroot/stefant/jop/java/tools/src/joptimizer/framework/CmdLine.java,v
    retrieving revision 1.2
    retrieving revision 1.3
    diff -u -b -r1.2 -r1.3
    --- CmdLine.java 15 Feb 2008 21:09:27 -0000 1.2
    +++ CmdLine.java 25 Feb 2008 02:49:22 -0000 1.3
    @@ -22,6 +22,8 @@
    import com.jopdesign.libgraph.struct.FieldInfo;
    import com.jopdesign.libgraph.struct.MethodInfo;
    import joptimizer.config.ArgOption;
    +import joptimizer.config.ArgumentException;
    +import joptimizer.config.ConfigurationException;
    import joptimizer.config.JopConfig;
    import joptimizer.framework.actions.Action;
    import joptimizer.framework.actions.ActionCollection;
    @@ -32,6 +34,7 @@
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintStream;
    +import java.util.Arrays;
    import java.util.Collection;
    import java.util.HashSet;
    import java.util.Iterator;
    @@ -95,6 +98,7 @@
    public void printHelp(PrintStream out) {
    out.println(" help Show this help.");
    out.println(" exit Terminate the program.");
    + out.println(" load <configfile> Load all values from a property-file as options.");
    out.println(" list <type> List one of the following:");
    out.println(" actions list of all actions.");
    out.println(" execactions list all actions executed by runall.");
    @@ -105,6 +109,7 @@
    out.println(" info <classname> Print some infos about the structure of a class.");
    out.println(" get <var> Get the value of an option.");
    out.println(" set <var> <val> Set an option to a given value.");
    + out.println(" unset <var> Unset the given option.");
    out.println(" run <action> Execute an action on all loaded classes.");
    out.println(" run <action> <class> [<method>] ");
    out.println(" Run an action only on a single class or a single method.");
    @@ -112,8 +117,9 @@
    out.println(" on the current optimization level.");
    out.println(" classpath <path> Set classpath to new path.");
    out.println(" mainclass <cls> Set main classname.");
    - out.println(" rootclasses <cls> Set new list of root classes.");
    - out.println(" reload Reload root classes from current classpath.");
    + out.println(" rootclasses <cls> Set new list of root classes and reloads systemclasses");
    + out.println(" from the architecture configuration.");
    + out.println(" reload Reload root classes from the current classpath.");
    }

    public void printConfig(PrintStream out) {
    @@ -281,6 +287,26 @@
    out.println();
    }

    + public void loadConfigFile(String filename, PrintStream out) {
    +
    + ConfigLoader configLoader = new ConfigLoader( ConfigLoader.getDefaultOptions(joptimizer) );
    + try {
    + configLoader.loadOptionFile(filename);
    + } catch (ArgumentException e) {
    + out.println("Could not load configuration file: " + e.getMessage());
    + if (logger.isInfoEnabled()) {
    + logger.info("Could not load configuration file {" + filename + "}.", e);
    + }
    + }
    +
    + try {
    + configLoader.storeConfig(joptimizer);
    + } catch (ConfigurationException e) {
    + out.println("Could not load options: " + e.getMessage());
    + logger.info("Could not load options.", e);
    + }
    + }
    +
    public void runAction(Action action, String[] args, int firstArg, PrintStream out) {

    ClassInfo classInfo = null;
    @@ -319,6 +345,7 @@
    /**
    * exec a command.
    * @param args the command as args[0] and its options
    + * @param out the printstream to print the output to. * @return true if this is an exit command, else false. */ public boolean execCmd(String[] args, PrintStream out) { @@ -350,6 +377,12 @@ out.println("Unknown action: "+args[1]); return false; } + } else if ( "load".equals(args[0]) ) { + if ( args.length < 2 ) { + out.println("Missing filename."); + return false; + } + loadConfigFile(args[1], out); } else if ( "info".equals(args[0]) ) { if ( args.length < 2 ) { out.println("Missing classname."); @@ -377,11 +410,10 @@ Set rootClasses = new HashSet(args.length + 2); JopConfig jopConfig = joptimizer.getJopConfig(); + rootClasses.add(jopConfig.getMainClassName()); rootClasses.addAll(jopConfig.getArchConfig().getSystemClasses()); - for (int i = 1; i < args.length; i++ ) { - rootClasses.add(args[i]); - } + rootClasses.addAll(Arrays.asList(args).subList(1, args.length)); jopConfig.setRootClasses(rootClasses); @@ -390,7 +422,12 @@ out.println("Syntax is: set <option> <value>"); return false; } + try { joptimizer.getJopConfig().setOption(args[1], args[2]); + } catch (ConfigurationException e) { + out.println("Could not set option: " + e.getMessage()); + logger.info("Could not set option.", e); + } } else if ( "get".equals(args[0]) ) { for (int i = 1; i < args.length; i++) { @@ -402,6 +439,18 @@ } } + } else if ( "unset".equals(args[0]) ) { + if ( args.length != 2 ) { + out.println("Syntax is: unset <option>"); + return false; + } + try { + joptimizer.getJopConfig().setOption(args[1], null); + } catch (ConfigurationException e) { + out.println("Could not unset option: " + e.getMessage()); + logger.info("Could not unset option.", e); + } + } else if ( "run".equals(args[0]) ) { if ( args.length < 2 ) { out.println("Missing action name."); 1.4 jop/java/tools/src/joptimizer/framework/JOPtimizer.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/joptimizer/framework/JOPtimizer.java.diff?r1=1.3&r2=1.4 (In the diff below, changes in quantity of whitespace are not shown.) Index: JOPtimizer.java =================================================================== RCS file: /cvsroot/stefant/jop/java/tools/src/joptimizer/framework/JOPtimizer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -b -r1.3 -r1.4 --- JOPtimizer.java 17 Feb 2008 20:47:30 -0000 1.3 +++ JOPtimizer.java 25 Feb 2008 02:49:22 -0000 1.4 @@ -153,11 +153,26 @@ } + /** + * Create and load classInfos from classnames. Excluded classes will not be created. + * + * @param classNames a list of strings of classnames to load. + * @return a collection of {@link ClassInfo}s. + * @throws TypeException + */ public Collection createClasses(Collection classNames) throws TypeException { List classes = new ArrayList(classNames.size()); for (Iterator it = classNames.iterator(); it.hasNext();) { String className = it.next().toString(); + + String reason = jopConfig.doExcludeClassName(className); + if ( reason == null ) { classes.add(appStruct.createClassInfo(className)); + } else { + if ( logger.isInfoEnabled() ) { + logger.info(reason); + } + } } return classes; } 1.1 jop/java/tools/src/joptimizer/framework/ConfigLoader.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/joptimizer/framework/ConfigLoader.java?rev=1.1&content-type=text/x-cvsweb-markup Index: ConfigLoader.java =================================================================== /* * Copyright (c) 2007,2008, Stefan Hepp * * This file is part of JOPtimizer. * * JOPtimizer is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * JOPtimizer is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package joptimizer.framework; import joptimizer.config.ArgOption; import joptimizer.config.ArgumentException; import joptimizer.config.ConfigurationException; import joptimizer.config.JopConfig; import joptimizer.config.StringOption; import org.apache.log4j.Logger; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; /** * @author Stefan Hepp, e0026640@s... */ public class ConfigLoader { public static final String CONF_CLASSPATH = "cp"; private Map options; private Properties config; private static final Logger logger = Logger.getLogger(ConfigLoader.class); /** * Create a new configuration loader with an empty configuration. * @param optionList a list of {@link joptimizer.config.ArgOption}s which can be loaded. */ public ConfigLoader(Collection optionList) { config = new Properties(); initOptions(optionList); } private void initOptions(Collection optionList) { options = new LinkedHashMap(); for (Iterator it = optionList.iterator(); it.hasNext();) { ArgOption option = (ArgOption) it.next(); options.put(option.getFullName(), option); } } public static List getDefaultOptions(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()); return optionList; } public Properties getConfig() { return config; } public void storeConfig(JOPtimizer joptimizer) throws ConfigurationException { String classPath = config.getProperty(CONF_CLASSPATH, "."); joptimizer.getAppStruct().setClassPath(classPath); joptimizer.getJopConfig().setProperties(config); } public void loadOptionFile(String filename) throws ArgumentException { Properties propfile = new Properties(); 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); } } public int loadOption(String arg, String[] args, int pos) 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; } }

     
    Copyright (c) 1999 OPENCORES.ORG. All rights reserved.