tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-tomcat/src/admin/WEB-INF/classes/tadm AntServletLogger.java GTestTEI.java GTestTag.java
Date Sat, 20 Jan 2001 20:14:28 GMT
costin      01/01/20 12:14:28

  Modified:    src/admin/WEB-INF admin.tld
  Added:       src/admin/WEB-INF/classes/tadm AntServletLogger.java
                        GTestTEI.java GTestTag.java
  Log:
  Added a new admin tag that runs a GTest test ( using ant as a driver -
  not easy since ant has now a lot of private methods that makes embedding it
  a bit hard, we may need a special driver - but what's important is to
  follow the "ant patterns" for introspection)
  
  Work in progress.
  
  Revision  Changes    Path
  1.3       +25 -0     jakarta-tomcat/src/admin/WEB-INF/admin.tld
  
  Index: admin.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/admin/WEB-INF/admin.tld,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- admin.tld	2000/12/27 21:41:26	1.2
  +++ admin.tld	2001/01/20 20:14:27	1.3
  @@ -76,4 +76,29 @@
   	
   
     </tag>
  +
  +
  +  <tag>
  +    <name>gtest</name>
  +    <tagclass>tadm.GTestTag</tagclass>
  +    <teiclass>tadm.GTestTEI</teiclass>
  +    <info>
  +      Run a GTest-based test suite.
  +    </info>
  +    <attribute>
  +       <name>testFile</name>
  +       <required>true</required>
  +    </attribute>
  +    <attribute>
  +       <name>testApp</name>
  +       <required>false</required>
  +    </attribute>
  +    <attribute>
  +       <name>target</name>
  +       <required>false</required>
  +       <rtexprvalue>true</rtexprvalue>
  +    </attribute>
  +  </tag>
  +
  +
   </taglib>
  
  
  
  1.1                  jakarta-tomcat/src/admin/WEB-INF/classes/tadm/AntServletLogger.java
  
  Index: AntServletLogger.java
  ===================================================================
  package tadm;
  import org.apache.tools.ant.*;
  
  import java.io.*;
  import javax.servlet.http.*;
  
  public class AntServletLogger implements BuildLogger {
      protected java.io.Writer out;
      protected java.io.PrintWriter err;
  
      protected int msgOutputLevel;
  
      private long startTime;
  
      protected static String lSep = System.getProperty("line.separator");
  
      protected boolean emacsMode = false;
  
      public AntServletLogger() {
  	
      }
      
      public void setMessageOutputLevel(int level) {
          this.msgOutputLevel = level;
      }
  
      public void setWriter(java.io.Writer output) {
          this.out = output;
  	this.err = new java.io.PrintWriter(output);
      }
  
      public void setEmacsMode(boolean emacsMode) {
          this.emacsMode = emacsMode;
      }
  
  
      public void setOutputPrintStream(PrintStream output) {
  	System.out.println("What the heck ");
      }
  
      public void setErrorPrintStream(PrintStream err) {
  	System.out.println("What the heck ");     
      }
  
      public void buildStarted(BuildEvent event) {
          startTime = System.currentTimeMillis();
      }
  
      public void buildFinished(BuildEvent event) {
          try {
  	    Throwable error = event.getException();
  	    
  	    if (error == null) {
  		out.write(lSep + "BUILD SUCCESSFUL");
  	    }
  	    else {
  		err.write(lSep + "BUILD FAILED" + lSep);
  		
  		if (error instanceof BuildException) {
  		    err.write(error.toString());
  		    
                  Throwable nested = ((BuildException)error).getException();
                  if (nested != null) {
                      nested.printStackTrace(err);
                  }
  		}
  		else {
  		    error.printStackTrace(err);
  		}
  	    }
  	    
  	    out.write(lSep + "Total time: " +
  		      (System.currentTimeMillis() - startTime));
  	    out.flush();
  	} catch( IOException ex ) {
  	    ex.printStackTrace();
  	}
      }
  
      public void targetStarted(BuildEvent event) {
          try {
  	    out.write("<h3>"+ event.getTarget().getName() + "</h3>");
  	    out.flush();
  	} catch(IOException ex ) {
  	    ex.printStackTrace();
  	}
      }
  
      public void targetFinished(BuildEvent event) {
          try {
  	    out.write("<hr>");
  	    out.flush();
  	} catch(IOException ex ) {
  	    ex.printStackTrace();
  	}
      }
  
      public void taskStarted(BuildEvent event) {
  	
      }
      
      public void taskFinished(BuildEvent event) {
  
      }
  
      public void messageLogged(BuildEvent event) {
          try {
  	    if( event.getPriority() > 2 )
  		return;
  
  	    out.write("\n<br>");
  	    // Print the message
  	    String msg=event.getMessage();
  	    if( msg.startsWith( "ERROR" )) {
  		out.write("<font color='red'>");
  	    }
  	    if( msg.startsWith("GOT" )) {
  		out.write("<pre>");
  	    }
  	    if( msg.startsWith("FAIL" )) {
  		out.write("</pre>");
  	    }
  	    out.write(event.getMessage());
  	    
  	    if( msg.startsWith( "ERROR" )) {
  		out.write("</font>");
  	    }
  	    out.flush();
  	} catch(IOException ex ) {
  	    ex.printStackTrace();
  	}
      }
  
  }
  
  
  
  1.1                  jakarta-tomcat/src/admin/WEB-INF/classes/tadm/GTestTEI.java
  
  Index: GTestTEI.java
  ===================================================================
  package tadm;
  import java.util.Vector;
  import java.util.Enumeration;
  import java.io.File;
  import java.net.URL;
  import javax.servlet.http.*;
  
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import org.apache.tomcat.core.Request;
  import org.apache.tomcat.core.Context;
  import org.apache.tomcat.core.ContextManager;
  
  
  import javax.servlet.jsp.tagext.TagData;
  import javax.servlet.jsp.tagext.TagExtraInfo;
  import javax.servlet.jsp.tagext.VariableInfo;
  
  public class GTestTEI extends TagExtraInfo {
  
      public VariableInfo[] getVariableInfo(TagData data) {
  	return (new VariableInfo[] {
  	    new VariableInfo("gtestSuccessCount",
  			     "java.lang.Integer",
  			     true,  VariableInfo.AT_BEGIN),
  	    new VariableInfo("gtestErrorCount",
  			     "java.lang.Integer",
  			     true,  VariableInfo.AT_BEGIN),
  	    new VariableInfo("gtestErrors",
  			     "java.util.Vector",
  			     true,  VariableInfo.AT_BEGIN)
  	});
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-tomcat/src/admin/WEB-INF/classes/tadm/GTestTag.java
  
  Index: GTestTag.java
  ===================================================================
  package tadm;
  import java.util.Vector;
  import java.util.Enumeration;
  import java.io.*;
  import java.net.URL;
  import javax.servlet.http.*;
  import javax.servlet.*;
  
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  
  import org.apache.tools.ant.*;
  
  /**
   * This tag will run a GTest-based test suite.
   * 
   */
  public class GTestTag extends TagSupport {
      PageContext pageContext;
      
      public GTestTag() {}
  
      public int doStartTag() throws JspException {
  	try {
  	    HttpServletRequest req=(HttpServletRequest)pageContext.
  		getRequest();
  
  	    ServletContext thisCtx=pageContext.getServletConfig().
  		getServletContext();
  
  	    // the admin can get other contexts, we are trusted
  	    ServletContext targetCtx=(testApp==null) ? thisCtx:
  		thisCtx.getContext( testApp );
  							    
  	    String base=targetCtx.getRealPath("/");
  	    
  	    runTest( base );
  	    //pageContext.setAttribute("cm", cm);
  
  	} catch (Exception ex ) {
  	    ex.printStackTrace();
  	}
  	return EVAL_BODY_INCLUDE;
      }
  
      public int doEndTag() throws JspException {
  	return EVAL_PAGE;
      }
      
      public void setPageContext(PageContext pctx ) {
  	this.pageContext=pctx;
      }
  
      public void setParent( Tag parent ) {
  	super.setParent( parent);
      }
  
      public void release() {
      }
  
      //-------------------- Properties --------------------
      String testFileName;
      String target;
      String testApp;
      
      /** Set the name of the test.xml, relative to the base dir.
       *  For example, /WEB-INF/test-tomcat.xml
       */
      public void setTestFile( String s ) {
  	testFileName=s;
      }
  
      /** Set the target - a subset of tests to be run
       */
      public void setTarget( String s ) {
  	target=s;
      }
  
      /** The application containing the test file
       *  ( if not set assume the test file is local to /admin app.
       */
      public void setTestApp( String s ) {
  	testApp=s;
      }
      
      // -------------------- Implementation methods --------------------
      
      private void runTest( String base) {
  	try {
  	    File testFile=new File( base + testFileName);
  	    
  	    Project project=new Project();
  	    
  	    AntServletLogger log=new AntServletLogger();
  	    log.setWriter( pageContext.getResponse().getWriter());
  	    project.addBuildListener( log );
  	    
  	    project.init();
  	    project.setUserProperty( "ant.file", testFile.toString());
  	    // XXX
  	    project.setUserProperty( "gdir", base + "/Golden");
  	    
  	    ProjectHelper.configureProject( project, testFile );
  	    
  	    Vector targets=new Vector();
  	    if( target==null ) target="client";
  	    
  	    targets.addElement( target );
  	    project.executeTargets( targets );
  	    
  	} catch( Exception ex ) {
  	    ex.printStackTrace();
  	}
      }
  }
  
  
  

Mime
View raw message