Search in sources :

Example 1 with ClassPath

use of org.apache.bcel.util.ClassPath in project jop by jop-devel.

the class AppSetup method getMainSignature.

private MemberID getMainSignature(String signature) throws BadConfigurationException {
    MemberID sMain;
    ClassPath path = new ClassPath(config.getOption(Config.CLASSPATH));
    MemberID sMainMethod = MemberID.parse(config.getOption(Config.MAIN_METHOD_NAME), path);
    if (signature == null || "".equals(signature)) {
        sMain = sMainMethod;
    } else {
        // try to parse the signature
        sMain = MemberID.parse(signature, path);
        // use --mm if only main class has been given
        if (!sMain.hasMemberName()) {
            if (!sMainMethod.hasMemberName()) {
                throw new BadConfigurationException("Option '" + Config.MAIN_METHOD_NAME.getKey() + "' needs to specify a method name.");
            }
            sMain = new MemberID(sMain.getClassName(), sMainMethod.getMemberName(), sMainMethod.getDescriptor());
        }
    }
    return sMain;
}
Also used : MemberID(com.jopdesign.common.type.MemberID) ClassPath(org.apache.bcel.util.ClassPath) BadConfigurationException(com.jopdesign.common.config.Config.BadConfigurationException)

Example 2 with ClassPath

use of org.apache.bcel.util.ClassPath in project jop by jop-devel.

the class OldAppInfo method parseOptions.

public String[] parseOptions(String[] args) {
    List<String> retList = new LinkedList<String>();
    System.out.println(args);
    try {
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-cp")) {
                i++;
                classpath = new ClassPath(args[i]);
                continue;
            }
            if (args[i].equals("-o")) {
                i++;
                outFile = args[i];
                continue;
            }
            if (args[i].equals("-sp")) {
                i++;
                srcPath = args[i];
                continue;
            }
            if (args[i].equals("-mm")) {
                i++;
                mainMethodName = args[i];
                continue;
            }
            if (args[i].charAt(0) == '-') {
                // an option we don't know
                retList.add(args[i]);
                i++;
                while (i < args.length) {
                    if (args[i].charAt(0) != '-') {
                        retList.add(args[i]);
                    } else {
                        break;
                    }
                }
            } else {
                // it's a class
                clsArgs.add(args[i]);
            }
            // The last class contains the main method
            // We also allow / notation as used with JCC
            mainClass = args[i].replace('/', '.');
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    String[] sa = new String[retList.size()];
    return retList.toArray(sa);
}
Also used : ClassPath(org.apache.bcel.util.ClassPath) LinkedList(java.util.LinkedList) IOException(java.io.IOException)

Example 3 with ClassPath

use of org.apache.bcel.util.ClassPath in project jop by jop-devel.

the class AppSetup method setupAppInfo.

/**
     * Setup AppInfo using the config previously initialized with {@link #setupConfig(String[])}.
     * 
     * @param args the arguments containing the name of the main method and additional roots without config options.
     * @param loadTransitiveHull if true, load the transitive hull of the root classes too.
     */
public void setupAppInfo(String[] args, boolean loadTransitiveHull) {
    CustomAttribute.registerDefaultReader();
    appInfo.setClassPath(new ClassPath(config.getOption(Config.CLASSPATH)));
    appInfo.setExitOnMissingClass(!config.getOption(Config.VERBOSE));
    // handle class loading options if set
    if (config.hasOption(Config.LIBRARY_CLASSES)) {
        List<String> libs = Config.splitStringList(config.getOption(Config.LIBRARY_CLASSES));
        for (String lib : libs) {
            appInfo.addLibrary(lib.replaceAll("/", "."));
        }
    }
    if (config.hasOption(Config.IGNORE_CLASSES)) {
        List<String> ignore = Config.splitStringList(config.getOption(Config.IGNORE_CLASSES));
        for (String cls : ignore) {
            appInfo.addLibrary(cls.replaceAll("/", "."));
        }
    }
    if (config.hasOption(Config.EXCLUDE_LIBRARIES)) {
        appInfo.setLoadLibraries(!config.getOption(Config.EXCLUDE_LIBRARIES));
    }
    if (config.hasOption(Config.EXCLUDE_NATIVES)) {
        appInfo.setLoadNatives(!config.getOption(Config.EXCLUDE_NATIVES));
    }
    appInfo.setCallstringLength(config.getOption(Config.CALLSTRING_LENGTH).intValue());
    for (String hwObject : Config.splitStringList(config.getOption(Config.HW_OBJECTS))) {
        appInfo.addHwObjectName(hwObject);
    }
    if (getDebugGroup().isSet(Config.DUMP_CACHEKEY)) {
        appInfo.setDumpCacheKeyFile(getDebugGroup().getOption(Config.DUMP_CACHEKEY));
    }
    // register handler
    for (String toolName : tools.keySet()) {
        if (useTool(toolName)) {
            AppEventHandler handler = tools.get(toolName).getEventHandler();
            if (handler != null) {
                appInfo.registerEventHandler(handler);
            }
        }
    }
    if (config.hasOption(Config.PROCESSOR_MODEL)) {
        initProcessorModel(config.getOption(Config.PROCESSOR_MODEL));
    }
    // add system classes as roots
    List<String> roots = Config.splitStringList(config.getOption(Config.ROOTS));
    for (String root : roots) {
        ClassInfo rootInfo = appInfo.loadClass(root.replaceAll("/", "."));
        if (rootInfo == null) {
            System.out.flush();
            System.err.println("Error loading root class '" + root + "'.");
            System.exit(4);
        }
        appInfo.addRoot(rootInfo);
    }
    // check arguments
    String mainClassName = null;
    if (args.length > 0 && !"".equals(args[0])) {
        mainClassName = args[0];
    } else if (config.hasOption(Config.MAIN_METHOD_NAME)) {
        mainClassName = MemberID.parse(config.getOption(Config.MAIN_METHOD_NAME)).getClassName();
    } else {
        System.out.flush();
        System.err.println("You need to specify a main class or entry method.");
        if (config.getOptions().containsOption(Config.SHOW_HELP)) {
            System.err.println("Use '--help' to show a usage message.");
        }
        System.exit(2);
    }
    // try to find main entry method
    try {
        MethodInfo main = getMainMethod(mainClassName.replaceAll("/", "."));
        appInfo.setMainMethod(main);
    } catch (Config.BadConfigurationException e) {
        System.out.flush();
        System.err.println(e.getMessage());
        if (config.getOptions().containsOption(Config.SHOW_HELP)) {
            System.err.println("Use '--help' to show a usage message.");
        }
        System.exit(2);
    }
    // load other root classes
    for (int i = 1; i < args.length; i++) {
        ClassInfo clsInfo = appInfo.loadClass(args[i].replaceAll("/", "."));
        appInfo.addRoot(clsInfo);
    }
    // notify the tools about the root classes
    try {
        for (String tool : tools.keySet()) {
            if (useTool(tool)) {
                tools.get(tool).onSetupRoots(this, appInfo);
            }
        }
    } catch (Config.BadConfigurationException e) {
        System.out.flush();
        System.err.println(e.getMessage());
        if (config.getOptions().containsOption(Config.SHOW_HELP)) {
            System.err.println("Use '--help' to show a usage message.");
        }
        System.exit(2);
    }
    // load and initialize all app classes
    if (loadTransitiveHull) {
        loadClassInfos();
        // register source line loader before other event handlers
        if (config.hasOption(Config.LOAD_SOURCELINES)) {
            String filename = config.getOption(Config.LOAD_SOURCELINES);
            if (filename != null && !"".equals(filename.trim())) {
                File storage = new File(filename);
                if (storage.exists()) {
                    new SourceLineStorage(storage).loadSourceInfos();
                }
            }
        }
    }
    // let modules process their config options
    try {
        for (String tool : tools.keySet()) {
            if (useTool(tool)) {
                tools.get(tool).onSetupAppInfo(this, appInfo);
            }
        }
    } catch (Config.BadConfigurationException e) {
        System.out.flush();
        System.err.println(e.getMessage());
        if (config.getOptions().containsOption(Config.SHOW_HELP)) {
            System.err.println("Use '--help' to show a usage message.");
        }
        System.exit(2);
    }
}
Also used : ClassPath(org.apache.bcel.util.ClassPath) BadConfigurationException(com.jopdesign.common.config.Config.BadConfigurationException) Config(com.jopdesign.common.config.Config) JOPConfig(com.jopdesign.common.processormodel.JOPConfig) LogConfig(com.jopdesign.common.logger.LogConfig) SourceLineStorage(com.jopdesign.common.tools.SourceLineStorage) File(java.io.File)

Example 4 with ClassPath

use of org.apache.bcel.util.ClassPath in project jop by jop-devel.

the class OldAppInfo method configure.

/** Configure the application (classpath, sourcepath, entry point) */
public void configure(String classpath, String sourcepath, String entryClass) {
    this.classpath = new ClassPath(classpath);
    this.srcPath = sourcepath;
    addClass(entryClass);
    this.mainClass = entryClass;
}
Also used : ClassPath(org.apache.bcel.util.ClassPath)

Aggregations

ClassPath (org.apache.bcel.util.ClassPath)4 BadConfigurationException (com.jopdesign.common.config.Config.BadConfigurationException)2 Config (com.jopdesign.common.config.Config)1 LogConfig (com.jopdesign.common.logger.LogConfig)1 JOPConfig (com.jopdesign.common.processormodel.JOPConfig)1 SourceLineStorage (com.jopdesign.common.tools.SourceLineStorage)1 MemberID (com.jopdesign.common.type.MemberID)1 File (java.io.File)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1