FileDocCategorySizeDatePackage
emmajavaTask.javaAPI DocAndroid 1.5 API18898Wed May 06 22:41:16 BST 2009com.vladium.emma

emmajavaTask

public class emmajavaTask extends org.apache.tools.ant.taskdefs.Java
author
Vlad Roubtsov, (C) 2003

Fields Summary
private org.apache.tools.ant.types.Path
m_classpath
private String
m_classname
private File
m_jar
private org.apache.tools.ant.types.Commandline
m_appArgs
private boolean
m_fork
private boolean
m_forkUserOverride
private boolean
m_enabled
private org.apache.tools.ant.types.Path
m_libClasspath
private VerbosityCfg
m_verbosityCfg
private GenericCfg
m_genericCfg
private com.vladium.emma.instr.FilterCfg
m_filterCfg
private com.vladium.emma.report.ReportCfg
m_reportCfg
private boolean
m_scanCoveragePath
private boolean
m_dumpSessionData
private File
m_outFile
private Boolean
m_outFileMerge
Constructors Summary
Methods Summary
public final Commandline.ArgumentcreateArg()
Not overridable [due to limitations in ANT's Commandline].

        if (m_appArgs == null)
            m_appArgs = new Commandline ();
        
        return m_appArgs.createArgument ();
    
public org.apache.tools.ant.types.PathcreateClasspath()

        if (m_classpath == null)
            m_classpath = new Path (project);
        
        return m_classpath.createPath ();
    
public final com.vladium.emma.instr.FilterCfg.filterElementcreateFilter()

        return m_filterCfg.createFilter ();
    
public final com.vladium.emma.report.ReportCfg.Element_HTMLcreateHtml()

        return m_reportCfg.createHtml ();
    
public final PropertyElementcreateProperty()

        return m_genericCfg.createProperty ();
    
public final org.apache.tools.ant.types.PathcreateSourcepath()

        return m_reportCfg.createSourcepath ();
    
public final com.vladium.emma.report.ReportCfg.Element_TXTcreateTxt()

        return m_reportCfg.createTxt ();
    
public final com.vladium.emma.report.ReportCfg.Element_XMLcreateXml()

        return m_reportCfg.createXml ();
    
public voidexecute()

        log (IAppConstants.APP_VERBOSE_BUILD_ID, Project.MSG_VERBOSE);
        
        if (getClasspath () == null)
            throw (BuildException) SuppressableTask.newBuildException (getTaskName ()
                + ": this task requires 'classpath' attribute to be set", location).fillInStackTrace ();
            

        if (isEnabled ())
        {
            // fork:
            if (m_forkUserOverride && ! m_fork)
                log (getTaskName () + ": 'fork=\"false\"' attribute setting ignored (this task always forks)", Project.MSG_WARN);
            
            super.setFork (true); // always fork
            
            // add emma libs to the parent task's classpath [to support non-extdir deployment]:
            final Path libClasspath = m_libClasspath;
            if ((libClasspath != null) && (libClasspath.size () > 0))
            {
                super.createClasspath ().append (libClasspath);
            }
            
            // classname|jar (1/2):
            super.setClassname ("emmarun");
            
            // <emmajava> extensions:
            {
                // report types:
                {
                    String reportTypes = Strings.toListForm (m_reportCfg.getReportTypes (), ',");
                    if ((reportTypes == null) || (reportTypes.length () == 0)) reportTypes = "txt";
                    
                    super.createArg ().setValue ("-r");
                    super.createArg ().setValue (reportTypes);
                }
                
                // full classpath scan flag:
                {
                    if (m_scanCoveragePath)
                    {
                        super.createArg ().setValue ("-f");
                    }
                }
                
                // dump raw data flag and options:
                {
                    if (m_dumpSessionData)
                    {
                        super.createArg ().setValue ("-raw");
                        
                        if (m_outFile != null)
                        {
                            super.createArg ().setValue ("-out");
                            super.createArg ().setValue (m_outFile.getAbsolutePath ());
                        }
                        
                        if (m_outFileMerge != null)
                        {
                            super.createArg ().setValue ("-merge");
                            super.createArg ().setValue (m_outFileMerge.booleanValue () ? "y" : "n");
                        }
                    }
                    else
                    {
                        if (m_outFile != null)
                            log (getTaskName () + ": output file attribute ignored ('fullmetadata=\"true\"' not specified)", Project.MSG_WARN);
                        
                        if (m_outFileMerge != null)
                            log (getTaskName () + ": merge attribute setting ignored ('fullmetadata=\"true\"' not specified)", Project.MSG_WARN);
                    }
                } 
                
                // instr filter:
                {
                    final String [] specs = m_filterCfg.getFilterSpecs ();
                    if ((specs != null) && (specs.length > 0))
                    {
                        super.createArg ().setValue ("-ix");
                        super.createArg ().setValue (Strings.toListForm (specs, ',"));
                    }
                }
                
                // sourcepath:
                {
                    final Path srcpath = m_reportCfg.getSourcepath ();
                    if (srcpath != null)
                    {
                        super.createArg ().setValue ("-sp");
                        super.createArg ().setValue (Strings.toListForm (srcpath.list (), ',"));
                    }
                }
                
                // all other generic settings:
                {
                    final IProperties reportSettings = m_reportCfg.getReportSettings ();
                    final IProperties genericSettings = m_genericCfg.getGenericSettings ();
                    
                    // TODO: another options is to read this file in the forked JVM [use '-props' pass-through]
                    // the best option depends on how ANT resolves relative file names 
                    final IProperties fileSettings = m_genericCfg.getFileSettings ();
                    
                    // verbosity settings use dedicated attributes and hence are more specific
                    // than anything generic:
                    final IProperties verbositySettings = m_verbosityCfg.getSettings ();
                    
                    // (1) file settings have lower priority than any explicitly named overrides
                    // (2) named report settings override generic named settings
                    // (3) verbosity settings use dedicated attributes (not overlapping with report
                    // cfg) and hence are more specific than anything generic
                    final IProperties settings = IProperties.Factory.combine (reportSettings,
                                                 IProperties.Factory.combine (verbositySettings,
                                                 IProperties.Factory.combine (genericSettings,
                                                                              fileSettings)));
                    
                    final String [] argForm = settings.toAppArgsForm ("-D");
                    if (argForm.length > 0)
                    {
                        for (int a = 0; a < argForm.length; ++ a)
                            super.createArg ().setValue (argForm [a]);
                    }
                }
            }
            
            // [assertion: getClasspath() is not null]
            
            // classpath:
            super.createArg ().setValue ("-cp");
            super.createArg ().setPath (getClasspath ());
                        
            // classname|jar (2/2):
            if (getClassname () != null)
                super.createArg ().setValue (getClassname ());
            else if (getJar () != null)
            {
                super.createArg ().setValue ("-jar");
                super.createArg ().setValue (getJar ().getAbsolutePath ());
            }
            else
                throw (BuildException) SuppressableTask.newBuildException (getTaskName ()
                    + "either 'jar' or 'classname' attribute must be set", location).fillInStackTrace ();
                
            // main class args:
            if (m_appArgs != null)
            {
                final String [] args = m_appArgs.getArguments ();
                for (int a = 0; a < args.length; ++ a)
                {
                    super.createArg ().setValue (args [a]); // note: spaces etc are escaped correctly by ANT libs
                }
            }
        }
        else
        {
            // fork:
            super.setFork (m_fork);
            
            // [assertion: getClasspath() is not null]
            
            // classpath:
            super.createClasspath ().append (getClasspath ()); // can't use setClasspath() for obvious reasons
            
            // classname|jar:
            if (getClassname () != null)
                super.setClassname (getClassname ());
            else if (getJar () != null)
                super.setJar (getJar ());
            else
                throw (BuildException) SuppressableTask.newBuildException (getTaskName ()
                    + "either 'jar' or 'classname' attribute must be set", location).fillInStackTrace ();
            
            // main class args:
            if (m_appArgs != null)
            {
                final String [] args = m_appArgs.getArguments ();
                for (int a = 0; a < args.length; ++ a)
                {
                    super.createArg ().setValue (args [a]); // note: spaces etc are escaped correctly by ANT libs
                }
            }    
        }
        
        super.execute ();
    
protected java.lang.StringgetClassname()

        return m_classname;
    
protected org.apache.tools.ant.types.PathgetClasspath()

        return m_classpath;
    
protected java.io.FilegetJar()

        return m_jar;
    
public voidinit()

        super.init ();

        m_verbosityCfg = new VerbosityCfg ();
        m_genericCfg = new GenericCfg (this);
        m_filterCfg = new FilterCfg (this);
        m_reportCfg = new ReportCfg (project, this);
        setEnabled (true);        
    
protected booleanisEnabled()

        return m_enabled;
    
public voidsetArgs(java.lang.String args)
This is already deprecated in ANT v1.4. However, it is still supported by the parent task so I do likewise.

        throw (BuildException) SuppressableTask.newBuildException (getTaskName ()
            + ": disallows using <java>'s deprecated 'args' attribute", location).fillInStackTrace ();
    
public voidsetClassname(java.lang.String classname)

        if (getJar () != null)
            throw (BuildException) SuppressableTask.newBuildException (getTaskName ()
                + "'jar' and 'classname' attributes cannot be set at the same time", location).fillInStackTrace ();
            
        m_classname = classname;
    
public voidsetClasspath(org.apache.tools.ant.types.Path path)

        if (m_classpath == null)
            m_classpath = path;
        else
            m_classpath.append (path);
    
public voidsetClasspathRef(org.apache.tools.ant.types.Reference ref)

        createClasspath ().setRefid (ref);
    
public final voidsetColumns(java.lang.String columns)

        m_reportCfg.setColumns (columns);
    
public final voidsetDepth(com.vladium.emma.report.IReportEnums.DepthAttribute depth)

        m_reportCfg.setDepth (depth);
    
public voidsetDumpsessiondata(boolean dump)

        m_dumpSessionData = dump;
    
public voidsetEnabled(boolean enabled)

        m_enabled = enabled;
    
public voidsetEncoding(java.lang.String encoding)

        m_reportCfg.setEncoding (encoding);
    
public final voidsetFilter(java.lang.String filter)

        m_filterCfg.setFilter (filter);
    
public final voidsetFork(boolean fork)
Not overridable.

        m_fork = fork;
        m_forkUserOverride = true;
    
public voidsetFullmetadata(boolean full)

        m_scanCoveragePath = full; // defaults to false TODO: maintain the default in a central location
    
public voidsetJar(java.io.File file)

        if (getClassname () != null)
            throw (BuildException) SuppressableTask.newBuildException (getTaskName ()
                + "'jar' and 'classname' attributes cannot be set at the same time", location).fillInStackTrace ();
            
        m_jar = file;
    
public final voidsetLibclasspath(org.apache.tools.ant.types.Path classpath)

        if (m_libClasspath == null)
            m_libClasspath = classpath;
        else
            m_libClasspath.append (classpath);
    
public final voidsetLibclasspathRef(org.apache.tools.ant.types.Reference ref)

        if (m_libClasspath == null)
            m_libClasspath = new Path (project);
        
        m_libClasspath.createPath ().setRefid (ref);
    
public voidsetMerge(boolean merge)

        m_outFileMerge = merge ? Boolean.TRUE : Boolean.FALSE;       
    
public final voidsetMetrics(java.lang.String metrics)

        m_reportCfg.setMetrics (metrics);
    
public voidsetOutfile(java.io.File file)

        if (m_outFile != null)
            throw (BuildException) SuppressableTask.newBuildException (getTaskName ()
                + ": session data file attribute already set", location).fillInStackTrace ();
            
        m_outFile = file;
    
public final voidsetProperties(java.io.File file)

        m_genericCfg.setProperties (file);
    
public voidsetSessiondatafile(java.io.File file)

        if (m_outFile != null)
            throw (BuildException) SuppressableTask.newBuildException (getTaskName ()
                + ": session data file attribute already set", location).fillInStackTrace ();
            
        m_outFile = file;
    
public final voidsetSort(java.lang.String sort)

        m_reportCfg.setSort (sort);
    
public final voidsetSourcepath(org.apache.tools.ant.types.Path path)

        m_reportCfg.setSourcepath (path);
    
public final voidsetSourcepathRef(org.apache.tools.ant.types.Reference ref)

        m_reportCfg.setSourcepathRef (ref);
    
public final voidsetUnits(com.vladium.emma.report.IReportEnums.UnitsTypeAttribute units)

        m_reportCfg.setUnits (units);
    
public voidsetVerbosity(VerbosityCfg.VerbosityAttribute verbosity)

        m_verbosityCfg.setVerbosity (verbosity);
    
public voidsetVerbosityfilter(java.lang.String filter)

        m_verbosityCfg.setVerbosityfilter (filter);