jakarta-watchdog-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sant...@locus.apache.org
Subject cvs commit: jakarta-watchdog-4.0/src/tools/org/apache/jspxml jsp2XMLTarget.java FileLister.java GetWorkspaceInXML.java jsp2XML.java
Date Thu, 30 Nov 2000 01:20:32 GMT
santosh     00/11/29 17:20:32

  Modified:    src/tools/org/apache/jspxml FileLister.java
                        GetWorkspaceInXML.java jsp2XML.java
  Added:       src/tools/org/apache/jspxml jsp2XMLTarget.java
  Log:
  XML files will have different names thaan jsp files to force the recompilation of jsp pages.
This will allow to run the tests with both XML and JSP pages at the same time without shutting
down the server.
  
  Revision  Changes    Path
  1.2       +0 -2      jakarta-watchdog-4.0/src/tools/org/apache/jspxml/FileLister.java
  
  Index: FileLister.java
  ===================================================================
  RCS file: /home/cvs/jakarta-watchdog-4.0/src/tools/org/apache/jspxml/FileLister.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileLister.java	2000/11/21 04:11:20	1.1
  +++ FileLister.java	2000/11/30 01:20:31	1.2
  @@ -25,10 +25,8 @@
   
   public Object[] listFiles()
   {
  -System.out.println("Please wait while FileLister searches all the subdirectries..........");
   
   addFiles(start_dir);
  -System.out.println("Search complete");
   return  file_list.toArray();
   }
   
  
  
  
  1.3       +59 -28    jakarta-watchdog-4.0/src/tools/org/apache/jspxml/GetWorkspaceInXML.java
  
  Index: GetWorkspaceInXML.java
  ===================================================================
  RCS file: /home/cvs/jakarta-watchdog-4.0/src/tools/org/apache/jspxml/GetWorkspaceInXML.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GetWorkspaceInXML.java	2000/11/23 22:49:46	1.2
  +++ GetWorkspaceInXML.java	2000/11/30 01:20:31	1.3
  @@ -2,10 +2,9 @@
   
   import java.io.*;
   import java.util.*;
  +import  org.apache.jspxml.jsp2XML;
  +import  org.apache.jspxml.jsp2XMLTarget;
   
  -import org.apache.jspxml.FileLister;
  -import org.apache.jspxml.jsp2XML;
  -
   //This file is an utility which helps running the entire jsp test suite with the 
   //XML view of JSP pages. It saves the original JSP files so that they can be restored back
   //XML views are generated dynamically and given the same file name as original jsp files
  @@ -17,17 +16,25 @@
   {
    String jsp_file=null;
    String xml_file=null ;
  + String jsp_root_dir = System.getProperty("JSP_ROOT");
  + String watchdog_home = System.getProperty("WATCHDOG_HOME");
  + String file_separator=System.getProperty("file.separator");
  +
  +if(jsp_root_dir==null)
  +{
  +System.out.println("JSP_ROOT variable is not set...exiting");
  +return;
  +}
   
  -if( args.length < 1)
  +if(watchdog_home==null )
     {
  - System.out.println("Usage : java jsp2XML <diretory>  ");
  - return;
  +  System.out.println("WATCHDOG_HOME variable is not set...exiting");
  +  return;
     }
   
  -String root = args[0];
   String extension="jsp" ; //files with extension .jsp
   
  -FileLister lister = new FileLister(root , extension) ;
  +FileLister lister = new FileLister(jsp_root_dir , extension) ;
   Object[] files = lister.listFiles();
   
   for(int i=0; i< files.length;i++)
  @@ -38,37 +45,25 @@
     if(index !=-1)
       xml_file = jsp_file.substring(0,index) + "XML" + ".jsp" ; 
   
  -//it should convert only if there has been no conversion so far
  -//The condition for which is no .original and no .xml file otherwise
  -//just rename the files properly
  +//it should convert only if the jsp file is newer than the XML file
   
  -File xml_save = new File (jsp_file + ".xml" ) ;
  -File jsp_save = new File (jsp_file + ".original" ) ;
  +File file_jsp = new File (jsp_file) ;
  +File file_xml = new File (xml_file);
   
  - if ( xml_save.exists() ) //the current workspace is in JSP and xml view 
  -			 // exists ..rename the files
  + if ( file_xml.exists()  )  //there was already a conversion
     {
  -new File(jsp_file).renameTo(new File(jsp_file + ".original") );
  -xml_save.renameTo(new File(jsp_file) );
  +if( file_xml.lastModified() > file_jsp.lastModified() )
   continue;
     }
  -
  - if ( jsp_save.exists() ) //the current workspace is in XML and JSP view 
  -			 // exists....do nothing
  -  {
  -   continue;
  -  }
   
  -//if we are here means this is the first time we are converting
  -//rename the JSp file and convert to XML view
  +//if we are here means we need to convert the jsp file to xml
   
  -new File(jsp_file).renameTo( new File(jsp_file +".original") );
  -jsp2XML jsp_converter = new jsp2XML(jsp_file + ".original" );
  +jsp2XML jsp_converter = new jsp2XML(jsp_file);
   String xml= jsp_converter.ConvertJsp2XML();
   
   try
    {
  - FileWriter fw = new FileWriter(jsp_file);
  + FileWriter fw = new FileWriter(xml_file);
    fw.write(xml);
    fw.close();
    }
  @@ -79,7 +74,43 @@
   
   }  //end for
   
  +//we generated the workspace in XML...now we need to create the 
  +//jsp-gtest-xml file that has targets for running the tests against 
  +//the XML view of the JSP pages
  +
  +File jsp_target = new File(watchdog_home + file_separator +"conf" +
  +		           file_separator + "jsp-gtest.xml" );
  +
  +File xml_target = new File(watchdog_home + file_separator +"conf" +
  +                           file_separator +"jsp-gtest-xml.xml" );
  +
  +if( xml_target.exists() ) //the converted target file exists
  +{
  +
  +if(jsp_target.lastModified() < xml_target.lastModified() ) //do nothing
  +return;
   }
  +
  +//The jsp file is latest so we need a conversion
  +jsp2XMLTarget xml_gtest = new jsp2XMLTarget(watchdog_home + file_separator+
  +				"conf" + file_separator + "jsp-gtest.xml" );
  +
  +String targets_in_xml=xml_gtest.getXMLTarget();
  +
  +try
  + {
  + FileWriter fw = new FileWriter(watchdog_home + file_separator +"conf" +
  +                           file_separator +"jsp-gtest-xml.xml" );
  + fw.write(targets_in_xml);
  + fw.close();
  + }
  +catch(IOException ioe)
  + {
  +System.err.println("Error writing to XML Gtest file");
  + }
  +
  +}
  +
   
   } //end class
   
  
  
  
  1.3       +2 -2      jakarta-watchdog-4.0/src/tools/org/apache/jspxml/jsp2XML.java
  
  Index: jsp2XML.java
  ===================================================================
  RCS file: /home/cvs/jakarta-watchdog-4.0/src/tools/org/apache/jspxml/jsp2XML.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- jsp2XML.java	2000/11/23 22:49:46	1.2
  +++ jsp2XML.java	2000/11/30 01:20:31	1.3
  @@ -171,7 +171,7 @@
   readJspFileintoString(input_jsp_file) ;
   }
   
  -protected String parseDirective(String directive_str )
  +public String parseDirective(String directive_str )
   {
   // \t is not same as a space
   
  @@ -224,7 +224,7 @@
   }
   
   
  -protected String convert(String jsp )
  +public String convert(String jsp )
   {
   int element_index=0;
   int last_index=0;
  
  
  
  1.1                  jakarta-watchdog-4.0/src/tools/org/apache/jspxml/jsp2XMLTarget.java
  
  Index: jsp2XMLTarget.java
  ===================================================================
  package org.apache.jspxml;
  
  //Author : Santosh Singh
  //This class is a utility class for running watchdog tests against
  //The XML view of JSP Pages
  //It creates the Gtest target file for XML pages
  
  import java.io.*;
  
  public class  jsp2XMLTarget
  {
  private String input_jsp ;
  
  public jsp2XMLTarget(String jsp_file )
  {
  input_jsp=ReadFileintoString(jsp_file);
  }
  
  public static String ReadFileintoString(String jsp_file)
  {
    if (jsp_file ==null)
    return null;
  
  String new_line=System.getProperty("line.separator");
  String input_jsp="";
  
  try
  {
  FileReader in_file = new FileReader(jsp_file);
  BufferedReader br = new BufferedReader(in_file);
  String line=br.readLine() ;
  
  
      while(line !=null)
      {
      line=line+new_line ; //readLine removes new line
      input_jsp+=line;
      line=br.readLine() ;
  
      }
   br.close();
   in_file.close();
  
  }
  catch(IOException ioex)
   {
  System.out.println("I/O Error in Reading");
   }
  return input_jsp;
  } 
  
  public String getXMLTarget()
  {
  
  int start_index=0;
  int end_index=0;
  String start_element="GET" ;
  String end_element ="HTTP/1.0" ;
  String xml_target="" ;
  
  //anything between GET and HTTP/1.0 is a URI
  
  start_index = input_jsp.indexOf(start_element , end_index);
  
     while( start_index >0 )
     {
   xml_target += input_jsp.substring(end_index , start_index);
   end_index=input_jsp.indexOf(end_element , start_index);
   String uri = input_jsp.substring(start_index ,end_index);
   String param_string = null;
  
  //Parse the URI 
    int param_index = uri.indexOf('?') ; //params in request
  
     if(param_index >=  0)
     {
       param_string = uri.substring(param_index);
       uri = uri.substring(0,param_index);
     }
  
  //Now we have only Request String 
    int file_index = uri.lastIndexOf('/');  //this is the path separator in XML file
    int jsp_index = uri.lastIndexOf(".jsp");
  
  
    if((file_index >=0 ) && (jsp_index >=0) )
     {
     String file_name = uri.substring(file_index+1,jsp_index);
  
        if(param_string==null)
         param_string=uri.substring(jsp_index+4); //points beyond .jsp
     
      uri=uri.substring(0,file_index+1);
      file_name=file_name+"XML" + ".jsp"  ;
      uri=uri+file_name+param_string ;
     
      xml_target+=uri;
      int last_index = input_jsp.indexOf("\"",end_index) ;
      xml_target+=input_jsp.substring(end_index,last_index+1) ;
      end_index=last_index+1;
      start_index = input_jsp.indexOf(start_element , end_index);
      continue;
     }
  //Unfortunately it was a template text ..should be written as it is
    end_index=end_index+end_element.length();
    xml_target+=input_jsp.substring(start_index,end_index);
    start_index = input_jsp.indexOf(start_element , end_index);
  
     } //end while
  
  xml_target+=input_jsp.substring(end_index);
  return xml_target ;
  
  }
  
  }
  
  
  
  
  
  

Mime
View raw message