FileDocCategorySizeDatePackage
RTExitHook.javaAPI DocAndroid 1.5 API3930Wed May 06 22:41:16 BST 2009com.vladium.emma.rt

RTExitHook

public final class RTExitHook extends Object implements Runnable
author
Vlad Roubtsov, (C) 2003

Fields Summary
private final File
m_outFile
private final boolean
m_merge
private Class
m_RT
private com.vladium.emma.data.ICoverageData
m_cdata
private static final String
CLOSURE_RESOURCE
Constructors Summary
RTExitHook(Class RT, com.vladium.emma.data.ICoverageData cdata, File outFile, boolean merge)

        m_RT = RT;
        m_cdata = cdata;
        
        m_outFile = outFile;
        m_merge = merge;
    
Methods Summary
public static voidcreateClassLoaderClosure()

        Properties closureMap = null;
        
        InputStream in = null;
        try
        {
            // note that this does not use ClassLoaderResolver by design
            // (closure loading must not load any app classes that are outside
            /// the closure list)
            
            in = RTExitHook.class.getResourceAsStream (CLOSURE_RESOURCE);
            if (in != null)
            {
                closureMap = new Properties ();
                closureMap.load (in);
            }
            else
            {
                throw new Error ("packaging failure: closure resource not found");
            }
        }
        catch (Exception e)
        {
            e.printStackTrace (System.out);
            
            throw new Error ("packaging failure: " + e.toString ());
        }
        finally
        {
            if (in != null) try { in.close (); } catch (IOException ignore) { ignore.printStackTrace (); }
        }
        in = null;
        
        final String closureList = closureMap.getProperty ("closure");
        if (closureList == null)
        {
            throw new Error ("packaging failure: no closure mapping");
        }
        
        // note that this uses the current classloader (only), consistently
        // with the getResourceAsStream() above:
        
        final ClassLoader loader = RTExitHook.class.getClassLoader ();
        
        final StringTokenizer tokenizer = new StringTokenizer (closureList, ",");
        while (tokenizer.hasMoreTokens ())
        {
            final String className = tokenizer.nextToken ();
            
            try
            {
                Class.forName (className, true, loader);
            }
            catch (Exception e)
            {
                throw new Error ("packaging failure: class [" + className + "] not found {" + e.toString () + "}");
            }
        }
    
public synchronized voidrun()

        if (m_cdata != null)
        {
            RTCoverageDataPersister.dumpCoverageData (m_cdata, true, m_outFile, m_merge);
            
            m_RT = null;
            m_cdata = null;
        }