bodewig     00/07/25 01:30:40

  Modified:    .        build.xml
               src/main/org/apache/tools/ant/taskdefs XSLTProcess.java
  Log:
  Reprocess files if stylesheet has changed in style task.
  Submitted by: Russell Gold <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.46      +1 -0      jakarta-ant/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/build.xml,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- build.xml 2000/07/24 15:52:51     1.45
  +++ build.xml 2000/07/25 08:30:36     1.46
  @@ -32,6 +32,7 @@
     <property name="manifest" value="src/etc/manifest"/>
   
     <property name="build.compiler" value="classic"/>
  +  <property name="build.compiler.emacs" value="on"/>
   
     <!-- =================================================================== 
-->
     <!-- Check to see what optional dependencies are available               
-->
  
  
  
  1.7       +28 -23    
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
  
  Index: XSLTProcess.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XSLTProcess.java  2000/07/21 09:43:15     1.6
  +++ XSLTProcess.java  2000/07/25 08:30:37     1.7
  @@ -83,7 +83,8 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Keith Visco</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Sam Ruby</a>
  - * @version $Revision: 1.6 $ $Date: 2000/07/21 09:43:15 $
  + * @author <a href="mailto:[EMAIL PROTECTED]">Russell Gold</a>
  + * @version $Revision: 1.7 $ $Date: 2000/07/25 08:30:37 $
    */
   public class XSLTProcess extends MatchingTask {
   
  @@ -138,38 +139,40 @@
   
        log("Using "+liaison.getClass().toString(), Project.MSG_VERBOSE);
   
  -     try {
  -         // Create a new XSL processor with the specified stylesheet
  -         if (xslFile != null) {
  -                String file = new 
File(baseDir,xslFile.toString()).toString();
  -             log("Loading stylesheet " + file, Project.MSG_INFO);
  -                liaison.setStylesheet( file );
  -         }
  -     } catch (Exception ex) {
  -         log("Failed to read stylesheet " + xslFile, Project.MSG_INFO);
  -            throw new BuildException(ex);
  -     }
  +        long styleSheetLastModified = 0;
  +        if (xslFile != null) {
  +            try {
  +                // Create a new XSL processor with the specified stylesheet
  +                File file = new File( baseDir, xslFile.toString() );
  +                styleSheetLastModified = file.lastModified();
  +                log( "Loading stylesheet " + file, Project.MSG_INFO);
  +                liaison.setStylesheet( file.toString() );
  +            } catch (Exception ex) {
  +                log("Failed to read stylesheet " + xslFile, 
Project.MSG_INFO);
  +                throw new BuildException(ex);
  +            }
  +        }
   
        // Process all the files marked for styling
        list = scanner.getIncludedFiles();
        for (int i = 0;i < list.length; ++i) {
  -         process(baseDir,list[i],destDir);
  +            process( baseDir, list[i], destDir, styleSheetLastModified );
        }
  -
  +        
        // Process all the directoried marked for styling
        dirs = scanner.getIncludedDirectories();
        for (int j = 0;j < dirs.length;++j){
            list=new File(baseDir,dirs[j]).list();
            for (int i = 0;i < list.length;++i)
  -             process(baseDir,list[i],destDir);
  +                process( baseDir, list[i], destDir, styleSheetLastModified );
        }
       } //-- execute
   
       /**
        * Set the base directory.
       **/
  -    public void setBasedir(String dirName) {
  -         baseDir = project.resolveFile(dirName);
  +    public void setBasedir(File dir) {
  +        baseDir = dir;
       } //-- setSourceDir
   
       /**
  @@ -177,8 +180,8 @@
        * files should be copied to
        * @param dirName the name of the destination directory
       **/
  -    public void setDestdir(String dirName) {
  -         destDir = project.resolveFile(dirName);
  +    public void setDestdir(File dir) {
  +        destDir = dir;
       } //-- setDestDir
   
       /**
  @@ -284,9 +287,10 @@
        * Processes the given input XML file and stores the result
        * in the given resultFile.
       **/
  -    private void process(File baseDir,String xmlFile,File destDir)
  -        throws BuildException
  -    {
  +    private void process(File baseDir, String xmlFile, File destDir, 
  +                         long styleSheetLastModified)
  +        throws BuildException {
  +
        String fileExt=targetExtension;
        File   outFile=null;
        File   inFile=null;
  @@ -294,7 +298,8 @@
        try {
            inFile = new File(baseDir,xmlFile);
            outFile = new 
File(destDir,xmlFile.substring(0,xmlFile.lastIndexOf('.'))+fileExt);
  -         if (inFile.lastModified() > outFile.lastModified()) {
  +         if (inFile.lastModified() > outFile.lastModified() ||
  +                styleSheetLastModified > outFile.lastModified()) {
                   ensureDirectoryFor( outFile );
                //-- command line status
                log("Processing " + xmlFile + " to " + outFile, 
Project.MSG_VERBOSE);
  
  
  

Reply via email to