FileDocCategorySizeDatePackage
InstrProcessor.javaAPI DocAndroid 1.5 API10874Wed May 06 22:41:16 BST 2009com.vladium.emma.instr

InstrProcessor

public abstract class InstrProcessor extends com.vladium.emma.Processor implements IPathEnumerator.IPathHandler
author
Vlad Roubtsov, (C) 2003

Fields Summary
public static final String
PROPERTY_EXCLUDE_SYNTHETIC_METHODS
public static final String
PROPERTY_EXCLUDE_BRIDGE_METHODS
public static final String
PROPERTY_DO_SUID_COMPENSATION
public static final String
DEFAULT_EXCLUDE_SYNTHETIC_METHODS
public static final String
DEFAULT_EXCLUDE_BRIDGE_METHODS
public static final String
DEFAULT_DO_SUID_COMPENSATION
protected File[]
m_instrPath
protected boolean
m_dependsMode
protected boolean
m_canonical
protected com.vladium.emma.filter.IInclExclFilter
m_coverageFilter
protected OutMode
m_outMode
protected File
m_outDir
protected File
m_mdataOutFile
protected Boolean
m_mdataOutMerge
protected int
m_classCopies
protected int
m_classInstrs
protected static final String
CLASSES
protected static final String
LIB
protected static final boolean
IN_CLASSES
protected static final boolean
IN_LIB
Constructors Summary
protected InstrProcessor()

        m_dependsMode = true;
    
Methods Summary
public static com.vladium.emma.instr.InstrProcessorcreate()

    
        
    
        return new InstrProcessorST ();
    
protected final voidcreateDir(java.io.File dir, boolean mkall)

        if (mkall)
        {
            if (! dir.mkdirs () && ! dir.exists ())
                throw new EMMARuntimeException (IAppErrorCodes.OUT_MKDIR_FAILURE, new Object [] {dir.getAbsolutePath ()}); 
        }
        else
        {
            if (! dir.mkdir () && ! dir.exists ())
                throw new EMMARuntimeException (IAppErrorCodes.OUT_MKDIR_FAILURE, new Object [] {dir.getAbsolutePath ()});
        } 
    
protected final java.io.FilegetFullOutDir(java.io.File pathDir, boolean isClass)

        if (m_outMode == OutMode.OUT_MODE_OVERWRITE)
        {
            return pathDir;
        }
        else if (m_outMode == OutMode.OUT_MODE_COPY)
        {
            return m_outDir;
        }
        else if (m_outMode == OutMode.OUT_MODE_FULLCOPY)
        {
            return isClass ? Files.newFile (m_outDir, CLASSES) : Files.newFile (m_outDir, LIB);
        }
        else throw new IllegalStateException ("invalid out mode state: " + m_outMode);
    
protected final java.io.FilegetFullOutFile(java.io.File pathDir, java.io.File file, boolean isClass)

        return Files.newFile (getFullOutDir (pathDir, isClass), file.getPath ());
    
protected voidreset()

        m_classCopies = m_classInstrs = 0;
    
public final synchronized voidsetDependsMode(boolean enable)

        m_dependsMode = enable;
    
public final synchronized voidsetInclExclFilter(java.lang.String[] specs)

param
specs [null is equivalent to no filtering (everything is included)]

        if (specs == null)
            m_coverageFilter = null;
        else
            m_coverageFilter = IInclExclFilter.Factory.create (specs);
    
public final synchronized voidsetInstrOutDir(java.lang.String dir)

param
dir [null unsets the previous setting]

        if (dir == null)
            m_outDir = null;
        else
        {
            final File _outDir = new File (dir);
            if (_outDir.exists () && ! _outDir.isDirectory ())
                throw new IllegalArgumentException ("not a directory: [" + _outDir.getAbsolutePath () + "]");
                
            m_outDir = _outDir;
        }
    
public final synchronized voidsetInstrPath(java.lang.String[] path, boolean canonical)

param
path [null is equivalent to an empty array]
param
canonical

        if ((path == null) || (path.length == 0))
            m_instrPath = IConstants.EMPTY_FILE_ARRAY;
        else
            m_instrPath = Files.pathToFiles (path, canonical);
            
        m_canonical = canonical;
    
public final synchronized voidsetMetaOutFile(java.lang.String fileName)

param
fileName [null unsets the previous override setting]

        if (fileName == null)
            m_mdataOutFile = null;
        else
        {
            final File _file = new File (fileName);
                
            if (_file.exists () && ! _file.isFile ())
                throw new IllegalArgumentException ("not a file: [" + _file.getAbsolutePath () + "]");
                
            m_mdataOutFile = _file;
        }
    
public final synchronized voidsetMetaOutMerge(java.lang.Boolean merge)

param
merge [null unsets the previous override setting]

        m_mdataOutMerge = merge;
    
public final synchronized voidsetOutMode(com.vladium.emma.instr.InstrProcessor$OutMode mode)

param
mode [may not be null]

        if (mode == null)
            throw new IllegalArgumentException ("null input: mode");
            
        m_outMode = mode;
    
protected voidvalidateState()

        super.validateState ();
        
        if ((m_instrPath == null) || (m_instrPath.length == 0))
            throw new IllegalStateException ("instrumentation path not set");
            
        // [m_coverageFilter can be null]

        if (m_outMode == null)
            throw new IllegalStateException ("output mode not set");
        
        if (m_outMode != OutMode.OUT_MODE_OVERWRITE)
        { 
            if (m_outDir == null)
                throw new IllegalStateException ("output directory not set");
                        
            // for non-overwrite modes output directory must not overlap
            // with the instr path:
            
            // [the logic below does not quite catch all possibilities due to
            // Class-Path: manifest attributes and dir nesting, but it should
            // intercept most common mistakes]
            
            if ($assert.ENABLED)
            {
                $assert.ASSERT (m_outDir != null, "m_outDir = null");
                $assert.ASSERT (m_instrPath != null, "m_instrPath = null");
            }
            
            final File canonicalOutDir = Files.canonicalizeFile (m_outDir);
            final File [] canonicalInstrPath;
            
            if (m_canonical)
                canonicalInstrPath = m_instrPath;
            else
            {
                canonicalInstrPath = new File [m_instrPath.length];
                
                for (int ip = 0; ip < canonicalInstrPath.length; ++ ip)
                {
                    canonicalInstrPath [ip] = Files.canonicalizeFile (m_instrPath [ip]);
                }
            }
            
            // FR_SF988785: detect if the user attempted to use a parent of m_outDir as one of
            // the input directories (prevents spurious "already instrumented" errors)
            
            final int instrPathLength = canonicalInstrPath.length;
            for (File dir = canonicalOutDir; dir != null; dir = dir.getParentFile ()) // getParentFile() does no real I/O
            {
                for (int ip = 0; ip < instrPathLength; ++ ip)
                {
                    if (dir.equals (canonicalInstrPath [ip]))
                        throw new IllegalStateException ("output directory [" + canonicalOutDir + "] cannot be one of the instrumentation path directories (or a child thereof)");
                }
            }
        }
        
        // [m_mdataOutFile can be null]
        // [m_mdataOutMerge can be null]