Search in sources :

Example 1 with SourceLineStorage

use of com.jopdesign.common.tools.SourceLineStorage in project jop by jop-devel.

the class AppSetup method writeClasses.

/**
     * Write the AppInfo classes to the directory specified by the {@link Config#WRITE_CLASSPATH} option.
     */
public void writeClasses() {
    writeClasses(Config.WRITE_CLASSPATH);
    // writing the source line infos *after* all other classes have been written so that timestamp checks works
    if (config.hasOption(Config.WRITE_SOURCELINES)) {
        String filename = config.getOption(Config.WRITE_SOURCELINES);
        if (filename != null && !"".equals(filename.trim())) {
            File storage = new File(filename);
            new SourceLineStorage(storage).storeSourceInfos();
        }
    }
}
Also used : SourceLineStorage(com.jopdesign.common.tools.SourceLineStorage) File(java.io.File)

Example 2 with SourceLineStorage

use of com.jopdesign.common.tools.SourceLineStorage 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)

Aggregations

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