emma

)
 * JD-Core Version:    0.7.1
 */
package com.vladium.emma.rt;

import com.vladium.util.ByteArrayOStream;
import java.io.IOException;

public abstract interface IClassLoadHook
{
  public abstract boolean processClassDef(String paramString, byte[] paramArrayOfByte, int paramInt, ByteArrayOStream paramByteArrayOStream)
    throws IOException;
}

/* Location:
 * Qualified Name:     com.vladium.emma.rt.IClassLoadHook
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.vladium.emma.rt;

import com.vladium.emma.data.CoverageOptions;
import com.vladium.emma.data.IMetaData;
import com.vladium.emma.filter.IInclExclFilter;
import com.vladium.emma.instr.InstrVisitor;
import com.vladium.emma.instr.InstrVisitor.InstrResult;
import com.vladium.jcd.cls.ClassDef;
import com.vladium.jcd.compiler.ClassWriter;
import com.vladium.jcd.parser.ClassDefParser;
import com.vladium.util.ByteArrayOStream;
import com.vladium.util.Descriptors;
import java.io.IOException;

public final class InstrClassLoadHook
  implements IClassLoadHook
{
  private final IInclExclFilter m_filter;
  private final IMetaData m_metadata;
  private final InstrVisitor m_classDefProcessor;
  private final InstrVisitor.InstrResult m_instrResult;
  
  public InstrClassLoadHook(IInclExclFilter filter, IMetaData mdata)
  {
    if (mdata == null) {
      throw new IllegalArgumentException("null input: mdata");
    }
    m_filter = filter;
    m_metadata = mdata;
    
    CoverageOptions options = mdata.getOptions();
    m_classDefProcessor = new InstrVisitor(options);
    
    m_instrResult = new InstrVisitor.InstrResult();
  }
  
  public boolean processClassDef(String className, byte[] bytes, int length, ByteArrayOStream out)
    throws IOException
  {
    IInclExclFilter filter = m_filter;
    if ((filter == null) || (filter.included(className)))
    {
      ClassDef clsDef = ClassDefParser.parseClass(bytes, length);
      String classVMName = Descriptors.javaNameToVMName(className);
      
      Object lock = m_metadata.lock();
      boolean metadataExists;
      synchronized (lock)
      {
        metadataExists = m_metadata.hasDescriptor(classVMName);
      }
      boolean metadataExists;
      m_classDefProcessor.process(clsDef, false, true, !metadataExists, m_instrResult);
      
      boolean useOurs = m_instrResult.m_instrumented;
      if (m_instrResult.m_descriptor != null) {
        synchronized (lock)
        {
          if (!m_metadata.add(m_instrResult.m_descriptor, false)) {
            useOurs = false;
          }
        }
      }
      if (useOurs)
      {
        ClassWriter.writeClassTable(clsDef, out);
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     com.vladium.emma.rt.InstrClassLoadHook
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.vladium.emma.rt;

import com.vladium.util.ByteArrayOStream;

final class InstrClassLoader$PoolEntry
{
  ByteArrayOStream m_baos;
  final byte[] m_buf;
  
  InstrClassLoader$PoolEntry(int baosCapacity, int bufSize)
  {
    m_baos = new ByteArrayOStream(baosCapacity);
    m_buf = new byte[bufSize];
  }
  
  void trim(int baosCapacity, int baosMaxCapacity)
  {
    if (m_baos.capacity() > baosMaxCapacity) {
      m_baos = new ByteArrayOStream(baosCapacity);
    }
  }
}

/* Location:
 * Qualified Name:     com.vladium.emma.rt.InstrClassLoader.PoolEntry
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.vladium.emma.rt;

import com.vladium.emma.filter.IInclExclFilter;
import com.vladium.logging.Logger;
import com.vladium.util.ByteArrayOStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.CodeSource;
import java.util.Map;

public final class InstrClassLoader
  extends URLClassLoader
{
  public static final String PROPERTY_FORCED_DELEGATION_FILTER = "clsload.forced_delegation_filter";
  public static final String PROPERTY_THROUGH_DELEGATION_FILTER = "clsload.through_delegation_filter";
  private final ClassLoader m_parent;
  private final IInclExclFilter m_forcedDelegationFilter;
  private final IInclExclFilter m_throughDelegationFilter;
  private final Map m_cache;
  private final IClassLoadHook m_hook;
  private final PoolEntry[] m_bufPool;
  private final Logger m_log;
  private int m_nestLevel;
  private int m_cacheHits;
  private int m_cacheMisses;
  private static final int BAOS_INIT_SIZE = 32768;
  private static final int BAOS_MAX_SIZE = 1048576;
  private static final int BAOS_POOL_SIZE = 8;
  
  public InstrClassLoader(ClassLoader parent, File[] classpath, IInclExclFilter forcedDelegationFilter, IInclExclFilter throughDelegationFilter, IClassLoadHook hook, Map cache)
    throws MalformedURLException
  {
    super(filesToURLs(classpath), null);
    
    m_hook = hook;
    m_cache = cache;
    
    m_forcedDelegationFilter = forcedDelegationFilter;
    m_throughDelegationFilter = throughDelegationFilter;
    
    m_parent = parent;
    m_bufPool = new PoolEntry[8];
    
    m_log = Logger.getLogger();
  }
  
  public final synchronized Class loadClass(String name, boolean resolve)
    throws ClassNotFoundException
  {
    boolean trace1 = m_log.atTRACE1();
    if (trace1) {
      m_log.trace1("loadClass", "(" + name + ", " + resolve + "): nest level " + m_nestLevel);
    }
    Class c = null;
    
    c = findLoadedClass(name);
    if (c == null)
    {
      Class parentsVersion = null;
      if (m_parent != null) {
        try
        {
          parentsVersion = m_parent.loadClass(name);
          if ((parentsVersion.getClassLoader() != m_parent) || (m_forcedDelegationFilter == null) || (m_forcedDelegationFilter.included(name)))
          {
            c = parentsVersion;
            if (trace1) {
              m_log.trace1("loadClass", "using parent's version for [" + name + "]");
            }
          }
        }
        catch (ClassNotFoundException cnfe)
        {
          if ((m_forcedDelegationFilter == null) || (m_forcedDelegationFilter.included(name))) {
            throw cnfe;
          }
        }
      }
      if (c == null) {
        try
        {
          c = findClass(name);
        }
        catch (ClassNotFoundException cnfe)
        {
          if (parentsVersion != null)
          {
            boolean delegate = (m_throughDelegationFilter == null) || (m_throughDelegationFilter.included(name));
            if (delegate)
            {
              c = parentsVersion;
              if (trace1) {
                m_log.trace1("loadClass", "[delegation filter] using parent's version for [" + name + "]");
              }
            }
            else
            {
              throw cnfe;
            }
          }
          else
          {
            throw cnfe;
          }
        }
      }
    }
    if (c == null) {
      throw new ClassNotFoundException(name);
    }
    if (resolve) {
      resolveClass(c);
    }
    return c;
  }
  
  public final URL getResource(String name)
  {
    boolean trace1 = m_log.atTRACE1();
    if (trace1) {
      m_log.trace1("getResource", "(" + name + "): nest level " + m_nestLevel);
    }
    URL result = super.getResource(name);
    if ((trace1) && (result != null)) {
      m_log.trace1("loadClass", "[" + name + "] found in " + result);
    }
    return result;
  }
  
  protected final Class findClass(String name)
    throws ClassNotFoundException
  {
    boolean trace1 = m_log.atTRACE1();
    if (trace1) {
      m_log.trace1("findClass", "(" + name + "): nest level " + m_nestLevel);
    }
    boolean useClassCache = m_cache != null;
    ClassPathCacheEntry entry = useClassCache ? (ClassPathCacheEntry)m_cache.remove(name) : null;
    
    URL classURL = null;
    if (entry != null)
    {
      m_cacheHits += 1;
      try
      {
        classURL = new URL(m_srcURL);
      }
      catch (MalformedURLException murle) {}
      PoolEntry buf = null;
      try
      {
        buf = acquirePoolEntry();
        ByteArrayOStream baos = m_baos;
        
        byte[] bytes = m_bytes;
        int length = bytes.length;
        if ((m_hook != null) && (m_hook.processClassDef(name, bytes, length, baos)))
        {
          bytes = baos.getByteArray();
          length = baos.size();
          if (trace1) {
            m_log.trace1("findClass", "defining [cached] instrumented [" + name + "] {" + length + " bytes }");
          }
        }
        else if (trace1)
        {
          m_log.trace1("findClass", "defining [cached] [" + name + "] {" + length + " bytes }");
        }
        return defineClass(name, bytes, length, classURL);
      }
      catch (IOException ioe)
      {
        throw new ClassNotFoundException(name);
      }
      finally
      {
        if (buf != null) {
          releasePoolEntry(buf);
        }
      }
    }
    if (useClassCache) {
      m_cacheMisses += 1;
    }
    String classResource = name.replace('.', '/') + ".class";
    
    classURL = getResource(classResource);
    if ((trace1) && (classURL != null)) {
      m_log.trace1("findClass", "[" + name + "] found in " + classURL);
    }
    if (classURL == null) {
      throw new ClassNotFoundException(name);
    }
    InputStream in = null;
    PoolEntry buf = null;
    try
    {
      in = classURL.openStream();
      
      buf = acquirePoolEntry();
      ByteArrayOStream baos = m_baos;
      
      readFully(in, baos, m_buf);
      in.close();
      in = null;
      
      byte[] bytes = baos.getByteArray();
      int length = baos.size();
      
      baos.reset();
      if ((m_hook != null) && (m_hook.processClassDef(name, bytes, length, baos)))
      {
        bytes = baos.getByteArray();
        length = baos.size();
        if (trace1) {
          m_log.trace1("findClass", "defining instrumented [" + name + "] {" + length + " bytes }");
        }
      }
      else if (trace1)
      {
        m_log.trace1("findClass", "defining [" + name + "] {" + length + " bytes }");
      }
      return defineClass(name, bytes, length, classURL);
    }
    catch (IOException ioe)
    {
      throw new ClassNotFoundException(name);
    }
    finally
    {
      if (buf != null) {
        releasePoolEntry(buf);
      }
      if (in != null) {
        try
        {
          in.close();
        }
        catch (Exception ignore) {}
      }
    }
  }
  
  public void debugDump(PrintWriter out)
  {
    if (out != null) {
      out.println(this + ": " + m_cacheHits + " class cache hits, " + m_cacheMisses + " misses");
    }
  }
  
  private static final class PoolEntry
  {
    ByteArrayOStream m_baos;
    final byte[] m_buf;
    
    PoolEntry(int baosCapacity, int bufSize)
    {
      m_baos = new ByteArrayOStream(baosCapacity);
      m_buf = new byte[bufSize];
    }
    
    void trim(int baosCapacity, int baosMaxCapacity)
    {
      if (m_baos.capacity() > baosMaxCapacity) {
        m_baos = new ByteArrayOStream(baosCapacity);
      }
    }
  }
  
  private Class defineClass(String className, byte[] bytes, int length, URL srcURL)
  {
    CodeSource csrc = new CodeSource(srcURL, null);
    
    int lastDot = className.lastIndexOf('.');
    if (lastDot >= 0)
    {
      String packageName = className.substring(0, lastDot);
      
      Package pkg = getPackage(packageName);
      if (pkg == null) {
        definePackage(packageName, "EMMA", "2.0", "(C) Vladimir Roubtsov", "EMMA", "2.0", "(C) Vladimir Roubtsov", srcURL);
      }
    }
    return defineClass(className, bytes, 0, length, csrc);
  }
  
  private static URL[] filesToURLs(File[] classpath)
    throws MalformedURLException
  {
    if ((classpath == null) || (classpath.length == 0)) {
      return EMPTY_URL_ARRAY;
    }
    URL[] result = new URL[classpath.length];
    for (int f = 0; f < result.length; f++) {
      result[f] = classpath[f].toURL();
    }
    return result;
  }
  
  private static void readFully(InputStream in, ByteArrayOStream out, byte[] buf)
    throws IOException
  {
    int read;
    while ((read = in.read(buf)) >= 0) {
      out.write(buf, 0, read);
    }
  }
  
  private PoolEntry acquirePoolEntry()
  {
    PoolEntry result;
    PoolEntry result;
    if (m_nestLevel >= 8)
    {
      result = new PoolEntry(32768, 32768);
    }
    else
    {
      result = m_bufPool[m_nestLevel];
      if (result == null)
      {
        result = new PoolEntry(32768, 32768);
        m_bufPool[m_nestLevel] = result;
      }
      else
      {
        m_baos.reset();
      }
    }
    m_nestLevel += 1;
    
    return result;
  }
  
  private void releasePoolEntry(PoolEntry buf)
  {
    if (--m_nestLevel < 8) {
      buf.trim(32768, 1048576);
    }
  }
  
  private static final URL[] EMPTY_URL_ARRAY = new URL[0];
}

/* Location:
 * Qualified Name:     com.vladium.emma.rt.InstrClassLoader
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.vladium.emma.rt;

import com.vladium.emma.EMMAProperties;
import com.vladium.emma.IAppConstants;
import com.vladium.emma.data.DataFactory;
import com.vladium.emma.data.ICoverageData;
import com.vladium.logging.Logger;
import com.vladium.util.IProperties;
import com.vladium.util.Property;
import com.vladium.util.exit.ExitHookManager;
import java.io.File;

public abstract class RT
  implements IAppConstants
{
  private static ICoverageData s_cdata;
  private static Runnable s_exitHook;
  private static IProperties s_appProperties;
  private static final ExitHookManager EXIT_HOOK_MANAGER;
  private static final boolean DEBUG = false;
  
  public static synchronized ICoverageData reset(boolean createCoverageData, boolean createExitHook)
  {
    ClassLoader loader = RT.class.getClassLoader();
    if (loader == null) {
      loader = ClassLoader.getSystemClassLoader();
    }
    IProperties appProperties = null;
    try
    {
      appProperties = EMMAProperties.getAppProperties(loader);
    }
    catch (Throwable t)
    {
      t.printStackTrace(System.out);
    }
    s_appProperties = appProperties;
    if (EXIT_HOOK_MANAGER != null) {
      if (s_exitHook != null)
      {
        EXIT_HOOK_MANAGER.removeExitHook(s_exitHook);
        s_exitHook = null;
      }
    }
    ICoverageData cdata = s_cdata;
    if (createCoverageData)
    {
      cdata = DataFactory.newCoverageData();
      s_cdata = cdata;
    }
    else
    {
      s_cdata = null;
    }
    if (EXIT_HOOK_MANAGER != null) {
      if ((createExitHook) && (cdata != null))
      {
        Runnable exitHook = new RTExitHook(RT.class, cdata, getCoverageOutFile(), getCoverageOutMerge());
        
        RTExitHook.createClassLoaderClosure();
        if (EXIT_HOOK_MANAGER.addExitHook(exitHook)) {
          s_exitHook = exitHook;
        }
      }
    }
    return cdata;
  }
  
  public static void r(boolean[][] coverage, String classVMName, long stamp)
  {
    ICoverageData cdata = getCoverageData();
    if (cdata != null) {
      synchronized (cdata.lock())
      {
        cdata.addClass(coverage, classVMName, stamp);
      }
    }
  }
  
  public static synchronized ICoverageData getCoverageData()
  {
    return s_cdata;
  }
  
  public static synchronized IProperties getAppProperties()
  {
    return s_appProperties;
  }
  
  public static synchronized void dumpCoverageData(File outFile, boolean merge, boolean stopDataCollection)
  {
    outFile = outFile != null ? outFile : getCoverageOutFile();
    
    ICoverageData cdata = s_cdata;
    if (stopDataCollection) {
      s_cdata = null;
    }
    RTCoverageDataPersister.dumpCoverageData(cdata, !stopDataCollection, outFile, merge);
  }
  
  public static synchronized void dumpCoverageData(File outFile, boolean stopDataCollection)
  {
    outFile = outFile != null ? outFile : getCoverageOutFile();
    
    ICoverageData cdata = s_cdata;
    if (stopDataCollection) {
      s_cdata = null;
    }
    RTCoverageDataPersister.dumpCoverageData(cdata, !stopDataCollection, outFile, getCoverageOutMerge());
  }
  
  private static File getCoverageOutFile()
  {
    IProperties appProperties = getAppProperties();
    if (appProperties != null)
    {
      String property = appProperties.getProperty("coverage.out.file", "coverage.ec");
      
      return new File(property);
    }
    return new File("coverage.ec");
  }
  
  private static boolean getCoverageOutMerge()
  {
    IProperties appProperties = getAppProperties();
    if (appProperties != null)
    {
      String property = appProperties.getProperty("coverage.out.merge", EMMAProperties.DEFAULT_COVERAGE_DATA_OUT_MERGE.toString());
      
      return Property.toBoolean(property);
    }
    return EMMAProperties.DEFAULT_COVERAGE_DATA_OUT_MERGE.booleanValue();
  }
  
  static
  {
    ExitHookManager temp = null;
    try
    {
      temp = ExitHookManager.getSingleton();
    }
    catch (Throwable t)
    {
      t.printStackTrace(System.out);
    }
    EXIT_HOOK_MANAGER = temp;
    if (RTSettings.isStandaloneMode())
    {
      reset(true, true);
      
      Logger log = Logger.getLogger();
      if (log.atINFO()) {
        log.info("collecting runtime coverage data ...");
      }
    }
    else
    {
      reset(false, false);
    }
  }
}

/* Location:
 * Qualified Name:     com.vladium.emma.rt.RT
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.vladium.emma.rt;

import com.vladium.emma.data.DataFactory;
import com.vladium.emma.data.ICoverageData;
import com.vladium.logging.Logger;
import java.io.File;

abstract class RTCoverageDataPersister
{
  static void dumpCoverageData(ICoverageData cdata, boolean useSnapshot, File outFile, boolean merge)
  {
    try
    {
      if (cdata != null)
      {
        Logger log = Logger.getLogger();
        boolean info = log.atINFO();
        
        long start = info ? System.currentTimeMillis() : 0L;
        
        ICoverageData cdataView = useSnapshot ? cdata.shallowCopy() : cdata;
        synchronized (Object.class)
        {
          DataFactory.persist(cdataView, outFile, merge);
        }
        if (info)
        {
          long end = System.currentTimeMillis();
          
          log.info("runtime coverage data " + (merge ? "merged into" : "written to") + " [" + outFile.getAbsolutePath() + "] {in " + (end - start) + " ms}");
        }
      }
    }
    catch (Throwable t)
    {
      t.printStackTrace();
      
      throw new RuntimeException("EMMA failed to dump coverage data: " + t.toString());
    }
  }
}

/* Location:
 * Qualified Name:     com.vladium.emma.rt.RTCoverageDataPersister
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.vladium.emma.rt;

import com.vladium.emma.data.ICoverageData;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.StringTokenizer;

final class RTExitHook
  implements Runnable
{
  private final File m_outFile;
  private final boolean m_merge;
  private Class m_RT;
  private ICoverageData m_cdata;
  private static final String CLOSURE_RESOURCE = "RTExitHook.closure";
  
  public synchronized void run()
  {
    if (m_cdata != null)
    {
      RTCoverageDataPersister.dumpCoverageData(m_cdata, true, m_outFile, m_merge);
      
      m_RT = null;
      m_cdata = null;
    }
  }
  
  public static void createClassLoaderClosure()
  {
    Properties closureMap = null;
    
    InputStream in = null;
    try
    {
      in = RTExitHook.class.getResourceAsStream("RTExitHook.closure");
      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;
    
    String closureList = closureMap.getProperty("closure");
    if (closureList == null) {
      throw new Error("packaging failure: no closure mapping");
    }
    ClassLoader loader = RTExitHook.class.getClassLoader();
    
    StringTokenizer tokenizer = new StringTokenizer(closureList, ",");
    while (tokenizer.hasMoreTokens())
    {
      String className = tokenizer.nextToken();
      try
      {
        Class.forName(className, true, loader);
      }
      catch (Exception e)
      {
        throw new Error("packaging failure: class [" + className + "] not found {" + e.toString() + "}");
      }
    }
  }
  
  RTExitHook(Class RT, ICoverageData cdata, File outFile, boolean merge)
  {
    m_RT = RT;
    m_cdata = cdata;
    
    m_outFile = outFile;
    m_merge = merge;
  }
}

/* Location:
 * Qualified Name:     com.vladium.emma.rt.RTExitHook
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.vladium.emma.rt;

public abstract class RTSettings
{
  private static boolean s_not_standalone;
  
  public static synchronized boolean isStandaloneMode()
  {
    return !s_not_standalone;
  }
  
  public static synchronized void setStandaloneMode(boolean standalone)
  {
    s_not_standalone = !standalone;
  }
}

/* Location:
 * Qualified Name:     com.vladium.emma.rt.RTSettings
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.vladium.emma;

import com.vladium.emma.rt.AppRunner;
import com.vladium.util.ClassLoaderResolver;
import com.vladium.util.Strings;
import com.vladium.util.args.IOptsParser;
import com.vladium.util.args.IOptsParser.IOpt;
import com.vladium.util.args.IOptsParser.IOpts;
import java.io.File;
import java.io.IOException;
import java.util.jar.Attributes;
import java.util.jar.Attributes.Name;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

public final class runCommand
  extends Command
{
  private String[] m_classpath;
  private String[] m_srcpath;
  private boolean m_jarMode;
  private boolean m_scanCoveragePath;
  private String[] m_ixpath;
  private String[] m_appArgs;
  private boolean m_dumpRawData;
  private String m_outFileName;
  private Boolean m_outDataMerge;
  private String[] m_reportTypes;
  private static final boolean DEFAULT_TO_SYSTEM_CLASSPATH = false;
  
  public synchronized void run()
  {
    ClassLoader loader;
    try
    {
      loader = ClassLoaderResolver.getClassLoader();
    }
    catch (Throwable t)
    {
      ClassLoader loader;
      loader = getClass().getClassLoader();
    }
    try
    {
      IOptsParser parser = getOptParser(loader);
      IOptsParser.IOpts parsedopts = parser.parse(m_args);
      
      int usageRequestLevel = parsedopts.usageRequestLevel();
      if (usageRequestLevel > 0)
      {
        usageexit(parser, usageRequestLevel, null);
        return;
      }
      IOptsParser.IOpt[] opts = parsedopts.getOpts();
      if (opts == null)
      {
        parsedopts.error(m_out, 80);
        usageexit(parser, 1, null);
        return;
      }
      try
      {
        for (int o = 0; o < opts.length; o++)
        {
          IOptsParser.IOpt opt = opts[o];
          String on = opt.getCanonicalName();
          if (!processOpt(opt)) {
            if ("cp".equals(on)) {
              m_classpath = getListOptValue(opt, PATH_DELIMITERS, true);
            } else if ("jar".equals(on)) {
              m_jarMode = true;
            } else if ("f".equals(on)) {
              m_scanCoveragePath = getOptionalBooleanOptValue(opt);
            } else if ("sp".equals(on)) {
              m_srcpath = getListOptValue(opt, PATH_DELIMITERS, true);
            } else if ("raw".equals(on)) {
              m_dumpRawData = getOptionalBooleanOptValue(opt);
            } else if ("out".equals(on)) {
              m_outFileName = opt.getFirstValue();
            } else if ("merge".equals(on)) {
              m_outDataMerge = (getOptionalBooleanOptValue(opt) ? Boolean.TRUE : Boolean.FALSE);
            } else if ("r".equals(on)) {
              m_reportTypes = Strings.merge(opt.getValues(), ", \t\r\n", true);
            } else if ("ix".equals(on)) {
              m_ixpath = getListOptValue(opt, ", \t\r\n", true);
            }
          }
        }
        if (!processFilePropertyOverrides()) {
          return;
        }
        processCmdPropertyOverrides(parsedopts);
      }
      catch (IOException ioe)
      {
        throw new EMMARuntimeException("ARGS_IO_FAILURE", ioe);
      }
      String[] freeArgs = parsedopts.getFreeArgs();
      if (m_jarMode)
      {
        if ((freeArgs == null) || (freeArgs.length == 0))
        {
          usageexit(parser, 1, "missing jar file name");
          return;
        }
        File jarfile = new File(freeArgs[0]);
        try
        {
          jarMainClass = openJarFile(jarfile);
        }
        catch (IOException ioe)
        {
          String jarMainClass;
          throw new EMMARuntimeException("ARGS_IO_FAILURE", ioe);
        }
        String jarMainClass;
        if (jarMainClass == null)
        {
          exit(true, "failed to load Main-Class manifest attribute from [" + jarfile.getAbsolutePath() + "]", null, 2);
          return;
        }
        m_appArgs = new String[freeArgs.length];
        System.arraycopy(freeArgs, 1, m_appArgs, 1, freeArgs.length - 1);
        m_appArgs[0] = jarMainClass;
        
        m_classpath = new String[] { jarfile.getPath() };
      }
      else
      {
        if ((freeArgs == null) || (freeArgs.length == 0))
        {
          usageexit(parser, 1, "missing application class name");
          return;
        }
        m_appArgs = freeArgs;
      }
      if (m_classpath == null)
      {
        usageexit(parser, 1, "either '-cp' or '-jar' option is required");
        return;
      }
      if (m_reportTypes == null) {
        m_reportTypes = new String[] { "txt" };
      }
      String[] appargs = new String[m_appArgs.length - 1];
      System.arraycopy(m_appArgs, 1, appargs, 0, appargs.length);
      
      AppRunner processor = AppRunner.create(loader);
      processor.setAppName("EMMA");
      
      processor.setAppClass(m_appArgs[0], appargs);
      processor.setCoveragePath(m_classpath, true);
      processor.setScanCoveragePath(m_scanCoveragePath);
      processor.setSourcePath(m_srcpath);
      processor.setInclExclFilter(m_ixpath);
      processor.setDumpSessionData(m_dumpRawData);
      processor.setSessionOutFile(m_outFileName);
      processor.setSessionOutMerge(m_outDataMerge);
      
      processor.setReportTypes(m_reportTypes);
      processor.setPropertyOverrides(m_propertyOverrides);
      
      processor.run();
    }
    catch (EMMARuntimeException yre)
    {
      exit(true, yre.getMessage(), yre, 2);
      return;
    }
    catch (Throwable t)
    {
      exit(true, "unexpected failure: ", t, 2);
      return;
    }
    exit(false, null, null, 0);
  }
  
  protected runCommand(String usageToolName, String[] args)
  {
    super(usageToolName, args);
  }
  
  protected void initialize()
  {
    super.initialize();
  }
  
  protected String usageArgsMsg()
  {
    return "[options] class [args...] | -jar [options] jarfile [args...]";
  }
  
  private static String openJarFile(File file)
    throws IOException
  {
    JarFile jarfile = null;
    try
    {
      jarfile = new JarFile(file, false);
      
      Manifest manifest = jarfile.getManifest();
      if (manifest == null) {
        return null;
      }
      Attributes attributes = manifest.getMainAttributes();
      if (attributes == null) {
        return null;
      }
      String jarMainClass = attributes.getValue(Attributes.Name.MAIN_CLASS);
      
      return jarMainClass;
    }
    finally
    {
      if (jarfile != null) {
        try
        {
          jarfile.close();
        }
        catch (IOException ignore) {}
      }
    }
  }
}

/* Location:
 * Qualified Name:     com.vladium.emma.runCommand
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.vladium.jcd.cls;

public abstract class AbstractClassDefVisitor
  implements IClassDefVisitor
{
  public Object visit(ClassDef cls, Object ctx)
  {
    visit(cls.getConstants(), ctx);
    visit(cls.getInterfaces(), ctx);
    visit(cls.getFields(), ctx);
    visit(cls.getMethods(), ctx);
    visit(cls.getAttributes(), ctx);
    
    return ctx;
  }
  
  public Object visit(IAttributeCollection attributes, Object ctx)
  {
    return ctx;
  }
  
  public Object visit(IConstantCollection constants, Object ctx)
  {
    return ctx;
  }
  
  public Object visit(IFieldCollection fields, Object ctx)
  {
    return ctx;
  }
  
  public Object visit(IInterfaceCollection interfaces, Object ctx)
  {
    return ctx;
  }
  
  public Object visit(IMethodCollection methods, Object ctx)
  {
    return ctx;
  }
}

/* Location:
 * Qualified Name:     com.vladium.jcd.cls.AbstractClassDefVisitor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.vladium.jcd.cls;

import com.vladium.jcd.cls.attribute.Attribute_info;
import com.vladium.jcd.cls.attribute.BridgeAttribute_info;
import com.vladium.jcd.cls.attribute.InnerClassesAttribute_info;
import com.vladium.jcd.cls.attribute.SyntheticAttribute_info;
import com.vladium.jcd.lib.UDataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

final class AttributeCollection
  implements IAttributeCollection
{
  private List m_attributes;
  private transient int m_syntheticRefCount;
  private transient int m_bridgeRefCount;
  private transient int m_innerClassesAttributeOffset;
  private static final boolean DISALLOW_MULTIPLE_SYNTHETIC_ATTRIBUTES = false;
  
  public final Attribute_info get(int offset)
  {
    return (Attribute_info)m_attributes.get(offset);
  }
  
  public final boolean hasSynthetic()
  {
    return m_syntheticRefCount > 0;
  }
  
  public final boolean hasBridge()
  {
    return m_bridgeRefCount > 0;
  }
  
  public final InnerClassesAttribute_info getInnerClassesAttribute()
  {
    int innerClassesAttributeOffset = m_innerClassesAttributeOffset;
    if (innerClassesAttributeOffset < 0) {
      return null;
    }
    return (InnerClassesAttribute_info)get(innerClassesAttributeOffset);
  }
  
  public final int size()
  {
    return m_attributes.size();
  }
  
  public final long length()
  {
    long result = 2L;
    
    int _attributes_count = m_attributes.size();
    for (int i = 0; i < _attributes_count; i++) {
      result += get(i).length();
    }
    return result;
  }
  
  public Object clone()
  {
    try
    {
      AttributeCollection _clone = (AttributeCollection)super.clone();
      
      int attributes_count = m_attributes.size();
      m_attributes = new ArrayList(attributes_count);
      for (int a = 0; a < attributes_count; a++) {
        m_attributes.add(((Attribute_info)m_attributes.get(a)).clone());
      }
      return _clone;
    }
    catch (CloneNotSupportedException e)
    {
      throw new InternalError(e.toString());
    }
  }
  
  public void writeInClassFormat(UDataOutputStream out)
    throws IOException
  {
    int attributes_count = size();
    out.writeU2(attributes_count);
    for (int i = 0; i < attributes_count; i++) {
      get(i).writeInClassFormat(out);
    }
  }
  
  public void accept(IClassDefVisitor visitor, Object ctx)
  {
    visitor.visit(this, ctx);
  }
  
  public int add(Attribute_info attribute)
  {
    List attributes = m_attributes;
    
    int result = attributes.size();
    attributes.add(attribute);
    if ((attribute instanceof SyntheticAttribute_info))
    {
      m_syntheticRefCount += 1;
    }
    else if ((attribute instanceof InnerClassesAttribute_info))
    {
      if (m_innerClassesAttributeOffset >= 0) {
        throw new IllegalArgumentException("this attribute collection already has an InnerClasses attribute");
      }
      m_innerClassesAttributeOffset = result;
    }
    else if ((attribute instanceof BridgeAttribute_info))
    {
      m_bridgeRefCount += 1;
    }
    return result;
  }
  
  public Attribute_info set(int offset, Attribute_info attribute)
  {
    Attribute_info result = (Attribute_info)m_attributes.set(offset, attribute);
    if ((result instanceof SyntheticAttribute_info)) {
      m_syntheticRefCount -= 1;
    } else if ((result instanceof InnerClassesAttribute_info)) {
      m_innerClassesAttributeOffset = -1;
    } else if ((result instanceof BridgeAttribute_info)) {
      m_bridgeRefCount -= 1;
    }
    if ((attribute instanceof SyntheticAttribute_info)) {
      m_syntheticRefCount += 1;
    } else if ((attribute instanceof InnerClassesAttribute_info)) {
      m_innerClassesAttributeOffset = offset;
    } else if ((attribute instanceof BridgeAttribute_info)) {
      m_bridgeRefCount += 1;
    }
    return result;
  }
  
  public Attribute_info remove(int offset)
  {
    Attribute_info result = (Attribute_info)m_attributes.remove(offset);
    if ((result instanceof SyntheticAttribute_info)) {
      m_syntheticRefCount -= 1;
    } else if ((result instanceof InnerClassesAttribute_info)) {
      m_innerClassesAttributeOffset = -1;
    } else if ((result instanceof BridgeAttribute_info)) {
      m_bridgeRefCount -= 1;
    }
    return result;
  }
  
  AttributeCollection(int capacity)
  {
    m_attributes = (capacity < 0 ? new ArrayList() : new ArrayList(capacity));
    m_innerClassesAttributeOffset = -1;
  }
}

/* Location:
 * Qualified Name:     com.vladium.jcd.cls.AttributeCollection
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.vladium.jcd.cls;

final class ClassDef$ConstructorDescriptor
  implements Comparable
{
  final int m_modifiers;
  final String m_descriptor;
  
  public final int compareTo(Object obj)
  {
    return m_descriptor.compareTo(m_descriptor);
  }
  
  ClassDef$ConstructorDescriptor(int modifiers, String descriptor)
  {
    m_modifiers = modifiers;
    m_descriptor = descriptor;
  }
}

/* Location:
 * Qualified Name:     com.vladium.jcd.cls.ClassDef.ConstructorDescriptor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.vladium.jcd.cls;

final class ClassDef$FieldDescriptor
  implements Comparable
{
  final String m_name;
  final int m_modifiers;
  final String m_descriptor;
  
  public final int compareTo(Object obj)
  {
    return m_name.compareTo(m_name);
  }
  
  ClassDef$FieldDescriptor(String name, int modifiers, String descriptor)
  {
    m_name = name;
    m_modifiers = modifiers;
    m_descriptor = descriptor;
  }
}

/* Location:
 * Qualified Name:     com.vladium.jcd.cls.ClassDef.FieldDescriptor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.vladium.jcd.cls;

final class ClassDef$MethodDescriptor
  implements Comparable
{
  final String m_name;
  final int m_modifiers;
  final String m_descriptor;
  
  public final int compareTo(Object obj)
  {
    MethodDescriptor rhs = (MethodDescriptor)obj;
    
    int result = m_name.compareTo(m_name);
    if (result == 0) {
      result = m_descriptor.compareTo(m_descriptor);
    }
    return result;
  }
  
  ClassDef$MethodDescriptor(String name, int modifiers, String descriptor)
  {
    m_name = name;
    m_modifiers = modifiers;
    m_descriptor = descriptor;
  }
}

/* Location:
 * Qualified Name:     com.vladium.jcd.cls.ClassDef.MethodDescriptor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.vladium.jcd.cls;

import com.vladium.jcd.cls.attribute.AttributeElementFactory;
import com.vladium.jcd.cls.attribute.CodeAttribute_info;
import com.vladium.jcd.cls.attribute.InnerClassesAttribute_info;
import com.vladium.jcd.cls.constant.CONSTANT_Class_info;
import com.vladium.jcd.cls.constant.CONSTANT_Fieldref_info;
import com.vladium.jcd.cls.constant.CONSTANT_NameAndType_info;
import com.vladium.jcd.cls.constant.CONSTANT_String_info;
import com.vladium.jcd.cls.constant.CONSTANT_Utf8_info;
import com.vladium.jcd.compiler.IClassFormatOutput;
import com.vladium.jcd.lib.Types;
import com.vladium.jcd.lib.UDataOutputStream;
import com.vladium.util.ByteArrayOStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

public final class ClassDef
  implements Cloneable, IAccessFlags, IClassFormatOutput
{
  private long m_magic;
  private int[] m_version;
  private int m_access_flags;
  private int m_this_class_index;
  private int m_super_class_index;
  private IConstantCollection m_constants;
  private IInterfaceCollection m_interfaces;
  private IFieldCollection m_fields;
  private IMethodCollection m_methods;
  private IAttributeCollection m_attributes;
  private long m_declaredSUID;
  private static final boolean DEBUG_SUID = false;
  
  public ClassDef()
  {
    m_version = new int[2];
    
    m_constants = ElementFactory.newConstantCollection(-1);
    m_interfaces = ElementFactory.newInterfaceCollection(-1);
    m_fields = ElementFactory.newFieldCollection(-1);
    m_methods = ElementFactory.newMethodCollection(-1);
    m_attributes = ElementFactory.newAttributeCollection(-1);
  }
  
  public void accept(IClassDefVisitor visitor, Object ctx)
  {
    visitor.visit(this, ctx);
  }
  
  public long getMagic()
  {
    return m_magic;
  }
  
  public void setMagic(long magic)
  {
    m_magic = magic;
  }
  
  public int[] getVersion()
  {
    return m_version;
  }
  
  public void setVersion(int[] version)
  {
    m_version[0] = version[0];
    m_version[1] = version[1];
  }
  
  public final void setDeclaredSUID(long suid)
  {
    m_declaredSUID = suid;
  }
  
  public int getThisClassIndex()
  {
    return m_this_class_index;
  }
  
  public void setThisClassIndex(int this_class_index)
  {
    m_this_class_index = this_class_index;
  }
  
  public CONSTANT_Class_info getThisClass()
  {
    return (CONSTANT_Class_info)m_constants.get(m_this_class_index);
  }
  
  public CONSTANT_Class_info getSuperClass()
  {
    return (CONSTANT_Class_info)m_constants.get(m_super_class_index);
  }
  
  public String getName()
  {
    return getThisClass().getName(this);
  }
  
  public int getSuperClassIndex()
  {
    return m_super_class_index;
  }
  
  public void setSuperClassIndex(int super_class_index)
  {
    m_super_class_index = super_class_index;
  }
  
  public final int getAccessFlags()
  {
    return m_access_flags;
  }
  
  public final void setAccessFlags(int flags)
  {
    m_access_flags = flags;
  }
  
  public boolean isInterface()
  {
    return (m_access_flags & 0x200) != 0;
  }
  
  public boolean isSynthetic()
  {
    return m_attributes.hasSynthetic();
  }
  
  public boolean isNested(int[] nestedAccessFlags)
  {
    InnerClassesAttribute_info innerClassesAttribute = m_attributes.getInnerClassesAttribute();
    if (innerClassesAttribute == null) {
      return false;
    }
    return innerClassesAttribute.makesClassNested(m_this_class_index, nestedAccessFlags);
  }
  
  public IConstantCollection getConstants()
  {
    return m_constants;
  }
  
  public IInterfaceCollection getInterfaces()
  {
    return m_interfaces;
  }
  
  public IFieldCollection getFields()
  {
    return m_fields;
  }
  
  public IMethodCollection getMethods()
  {
    return m_methods;
  }
  
  public IAttributeCollection getAttributes()
  {
    return m_attributes;
  }
  
  public int[] getFields(String name)
  {
    return m_fields.get(this, name);
  }
  
  public int[] getMethods(String name)
  {
    return m_methods.get(this, name);
  }
  
  public Object clone()
  {
    try
    {
      ClassDef _clone = (ClassDef)super.clone();
      
      m_version = ((int[])m_version.clone());
      m_constants = ((IConstantCollection)m_constants.clone());
      m_interfaces = ((IInterfaceCollection)m_interfaces.clone());
      m_fields = ((IFieldCol
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd