Search in sources :

Example 1 with ClassInfoNotFoundException

use of com.jopdesign.common.misc.ClassInfoNotFoundException in project jop by jop-devel.

the class AppInfo method reloadClasses.

/**
     * Reload all currently loaded classInfos from disk, using the current classpath.
     * @param checkExcludes if true, reevaluate excludes, else reload all classes even if excluded.
     * @throws ClassInfoNotFoundException if a class could not be reloaded.
     */
public void reloadClasses(boolean checkExcludes) throws ClassInfoNotFoundException {
    List<String> clsNames = new LinkedList<String>(classes.keySet());
    clear(false);
    for (String clsName : clsNames) {
        if (checkExcludes && isExcluded(clsName)) {
            continue;
        }
        performLoadClass(clsName, false);
    }
    // reload mainMethod
    if (mainMethod != null) {
        ClassInfo mainClass = classes.get(mainMethod.getClassInfo().getClassName());
        if (mainClass == null) {
            mainMethod = null;
            throw new ClassInfoNotFoundException("Could not find main class.");
        }
        mainMethod = mainClass.getMethodInfo(mainMethod.getMemberID().getMethodSignature());
        if (mainMethod == null) {
            throw new ClassInfoNotFoundException("Could not find main method in main class");
        }
    }
    reloadClassHierarchy();
}
Also used : ClassInfoNotFoundException(com.jopdesign.common.misc.ClassInfoNotFoundException) CallString(com.jopdesign.common.code.CallString) LinkedList(java.util.LinkedList)

Example 2 with ClassInfoNotFoundException

use of com.jopdesign.common.misc.ClassInfoNotFoundException in project jop by jop-devel.

the class AppInfo method performLoadClass.

private ClassInfo performLoadClass(String className, boolean required) throws ClassInfoNotFoundException {
    // try to load the class
    ClassInfo cls = null;
    try {
        cls = tryLoadClass(className);
        classes.put(className, cls);
        for (AppEventHandler mgr : eventHandlers) {
            mgr.onCreateClass(cls, true);
        }
    } catch (IOException e) {
        if (required || !ignoreMissingClasses) {
            throw new ClassInfoNotFoundException("Class '" + className + "' could not be loaded: " + e.getMessage(), e);
        } else
            cls = null;
    }
    return cls;
}
Also used : ClassInfoNotFoundException(com.jopdesign.common.misc.ClassInfoNotFoundException) IOException(java.io.IOException)

Example 3 with ClassInfoNotFoundException

use of com.jopdesign.common.misc.ClassInfoNotFoundException in project jop by jop-devel.

the class AppSetup method getMainMethod.

private MethodInfo getMainMethod(String signature) throws Config.BadConfigurationException {
    ClassInfo clsInfo;
    String clsName;
    MemberID sMain = getMainSignature(signature);
    clsName = sMain.getClassName();
    if (clsName == null) {
        throw new BadConfigurationException("You need to specify a classname for the main method.");
    }
    try {
        clsInfo = appInfo.loadClass(clsName, true, false);
    } catch (ClassInfoNotFoundException e) {
        throw new BadConfigurationException("Class for '" + signature + "' could not be loaded: " + e.getMessage(), e);
    }
    // check if we have a full signature
    if (sMain.hasMethodSignature()) {
        MethodInfo method = clsInfo.getMethodInfo(sMain.getMethodSignature());
        if (method == null) {
            throw new BadConfigurationException("Method '" + sMain.getMethodSignature() + "' not found in '" + clsName + "'.");
        }
        return method;
    }
    // try to find main method
    String mainName = sMain.getMemberName();
    if (mainName == null) {
        mainName = config.getOption(Config.MAIN_METHOD_NAME);
        if (mainName != null) {
            mainName = MemberID.parse(mainName).getMethodSignature();
        }
    }
    Collection<MethodInfo> methods = clsInfo.getMethodByName(mainName);
    if (methods.isEmpty()) {
        throw new BadConfigurationException("'No method '" + mainName + "' found in '" + clsName + "'.");
    }
    if (methods.size() > 1) {
        StringBuilder s = new StringBuilder(String.format("Multiple candidates for '%s' in '%s', please specify with a signature: ", mainName, clsName));
        for (MethodInfo m : methods) {
            s.append("\n");
            s.append(m.getMemberID());
        }
        throw new BadConfigurationException(s.toString());
    }
    return methods.iterator().next();
}
Also used : MemberID(com.jopdesign.common.type.MemberID) ClassInfoNotFoundException(com.jopdesign.common.misc.ClassInfoNotFoundException) BadConfigurationException(com.jopdesign.common.config.Config.BadConfigurationException)

Aggregations

ClassInfoNotFoundException (com.jopdesign.common.misc.ClassInfoNotFoundException)3 CallString (com.jopdesign.common.code.CallString)1 BadConfigurationException (com.jopdesign.common.config.Config.BadConfigurationException)1 MemberID (com.jopdesign.common.type.MemberID)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1