ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional TraXLiaison.java XalanLiaison.java XslpLiaison.java
Date Fri, 12 Apr 2002 12:58:02 GMT
bodewig     02/04/12 05:58:02

  Modified:    src/main/org/apache/tools/ant/taskdefs XSLTLogger.java
                        XSLTLoggerAware.java XSLTProcess.java
               src/main/org/apache/tools/ant/taskdefs/optional
                        TraXLiaison.java XalanLiaison.java XslpLiaison.java
  Log:
  Make sure <style> resets its state - may even help the garbage collector.
  
  Revision  Changes    Path
  1.2       +4 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTLogger.java
  
  Index: XSLTLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTLogger.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XSLTLogger.java	7 Dec 2001 16:10:17 -0000	1.1
  +++ XSLTLogger.java	12 Apr 2002 12:58:02 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -54,6 +54,9 @@
   
   package org.apache.tools.ant.taskdefs;
   
  +/**
  + * @since Ant 1.5
  + */
   public interface XSLTLogger {
       /**
        * Log a message.
  
  
  
  1.2       +4 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTLoggerAware.java
  
  Index: XSLTLoggerAware.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTLoggerAware.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XSLTLoggerAware.java	7 Dec 2001 16:10:17 -0000	1.1
  +++ XSLTLoggerAware.java	12 Apr 2002 12:58:02 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -54,6 +54,9 @@
   
   package org.apache.tools.ant.taskdefs;
   
  +/**
  + * @since Ant 1.5
  + */
   public interface XSLTLoggerAware {
       void setLogger(XSLTLogger l);
   }
  
  
  
  1.40      +73 -80    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.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- XSLTProcess.java	11 Mar 2002 09:40:21 -0000	1.39
  +++ XSLTProcess.java	12 Apr 2002 12:58:02 -0000	1.40
  @@ -71,27 +71,15 @@
   /**
    * A Task to process via XSLT a set of XML documents. This is
    * useful for building views of XML based documentation.
  - * arguments:
  - * <ul>
  - * <li>basedir
  - * <li>destdir
  - * <li>style
  - * <li>includes
  - * <li>excludes
  - * </ul>
  - * Of these arguments, the <b>sourcedir</b> and <b>destdir</b>
are required.
  - * <p>
  - * This task will recursively scan the sourcedir and destdir
  - * looking for XML documents to process via XSLT. Any other files,
  - * such as images, or html files in the source directory will be
  - * copied into the destination directory.
    *
  - * @version $Revision: 1.39 $ 
  + * @version $Revision: 1.40 $ 
    *
    * @author <a href="mailto:kvisco@exoffice.com">Keith Visco</a>
    * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
    * @author <a href="mailto:russgold@acm.org">Russell Gold</a>
  - * @author <a href="stefan.bodewig@epost.de">Stefan Bodewig</a>
  + * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  + *
  + * @since Ant 1.1
    *
    * @ant.task name="style" category="xml"
    */
  @@ -159,13 +147,13 @@
       /**
        * Whether to style all files in the included directories as well.
        *
  -     * @since 1.35, Ant 1.5
  +     * @since Ant 1.5
        */
       private boolean performDirectoryScan = true;
   
       /**
        * Creates a new XSLTProcess Task.
  -     **/
  +     */
       public XSLTProcess() {
           fileUtils = FileUtils.newFileUtils();
       } //-- XSLTProcess
  @@ -174,7 +162,7 @@
        * Whether to style all files in the included directories as well.
        *
        * @param b true if files in included directories are processed.
  -     * @since 1.35, Ant 1.5
  +     * @since Ant 1.5
        */
       public void setScanIncludedDirectories(boolean b) {
           performDirectoryScan = b;
  @@ -186,6 +174,8 @@
        * @exception BuildException if there is an execution problem.
        */
       public void execute() throws BuildException {
  +        File savedBaseDir = baseDir;
  +
           DirectoryScanner scanner;
           String[]         list;
           String[]         dirs;
  @@ -194,74 +184,80 @@
               throw new BuildException("no stylesheet specified", location);
           }
           
  -        if (baseDir == null) {
  -            baseDir = project.resolveFile(".");
  -        }
  -        
  -        liaison = getLiaison();
  +        try {
  +            if (baseDir == null) {
  +                baseDir = project.resolveFile(".");
  +            }
           
  -        // check if liaison wants to log errors using us as logger
  -        if (liaison instanceof XSLTLoggerAware) {
  -            ((XSLTLoggerAware)liaison).setLogger(this);
  -        }
  +            liaison = getLiaison();
  +            
  +            // check if liaison wants to log errors using us as logger
  +            if (liaison instanceof XSLTLoggerAware) {
  +                ((XSLTLoggerAware)liaison).setLogger(this);
  +            }
  +            
  +            log("Using " + liaison.getClass().toString(), Project.MSG_VERBOSE);
  +            
  +            File stylesheet = project.resolveFile(xslFile);
  +            if (!stylesheet.exists()) {
  +                stylesheet = fileUtils.resolveFile(baseDir, xslFile);
  +                /*
  +                 * shouldn't throw out deprecation warnings before we know,
  +                 * the wrong version has been used.
  +                 */
  +                if (stylesheet.exists()) {
  +                    log("DEPRECATED - the style attribute should be relative " 
  +                        + "to the project\'s");
  +                    log("             basedir, not the tasks\'s basedir.");
  +                }
  +            }
           
  -        log("Using " + liaison.getClass().toString(), Project.MSG_VERBOSE);
  +            // if we have an in file and out then process them
  +            if (inFile != null && outFile != null) {
  +                process(inFile, outFile, stylesheet);
  +                return;
  +            }
           
  -        File stylesheet = project.resolveFile(xslFile);
  -        if (!stylesheet.exists()) {
  -            stylesheet = fileUtils.resolveFile(baseDir, xslFile);
               /*
  -             * shouldn't throw out deprecation warnings before we know,
  -             * the wrong version has been used.
  +             * if we get here, in and out have not been specified, we are
  +             * in batch processing mode.
                */
  -            if (stylesheet.exists()) {
  -                log("DEPRECATED - the style attribute should be relative " 
  -                    + "to the project\'s");
  -                log("             basedir, not the tasks\'s basedir.");
  -            }
  -        }
  -        
  -        // if we have an in file and out then process them
  -        if (inFile != null && outFile != null) {
  -            process(inFile, outFile, stylesheet);
  -            return;
  -        }
           
  -        /*
  -         * if we get here, in and out have not been specified, we are
  -         * in batch processing mode.
  -         */
  -        
  -        //-- make sure Source directory exists...
  -        if (destDir == null ) {
  -            String msg = "destdir attributes must be set!";
  -            throw new BuildException(msg);
  -        }
  -        scanner = getDirectoryScanner(baseDir);
  -        log("Transforming into " + destDir, Project.MSG_INFO);
  +            //-- make sure Source directory exists...
  +            if (destDir == null ) {
  +                String msg = "destdir attributes must be set!";
  +                throw new BuildException(msg);
  +            }
  +            scanner = getDirectoryScanner(baseDir);
  +            log("Transforming into " + destDir, Project.MSG_INFO);
           
  -        // Process all the files marked for styling
  -        list = scanner.getIncludedFiles();
  -        for (int i = 0; i < list.length; ++i) {
  -            process( baseDir, list[i], destDir, stylesheet );
  -        }
  -        if (performDirectoryScan) {
  -            // Process all the directories 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, stylesheet );
  +            // Process all the files marked for styling
  +            list = scanner.getIncludedFiles();
  +            for (int i = 0; i < list.length; ++i) {
  +                process( baseDir, list[i], destDir, stylesheet );
  +            }
  +            if (performDirectoryScan) {
  +                // Process all the directories 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, stylesheet );
  +                    }
                   }
               }
  +        } finally {
  +            liaison = null;
  +            stylesheetLoaded = false;
  +            baseDir = savedBaseDir;
           }
       } //-- execute
       
       /**
        * Set whether to check dependencies, or always generate.
        *
  -      * @param force true if always generate.
  -     **/
  +     * @param force true if always generate.
  +     */
       public void setForce(boolean force) {
           this.force = force;
       } //-- setForce
  @@ -362,18 +358,15 @@
        */
       private void resolveProcessor(String proc) throws Exception {
           if (proc.equals("trax")) {
  -            final Class clazz =
  -                loadClass(TRAX_LIAISON_CLASS);
  +            final Class clazz = loadClass(TRAX_LIAISON_CLASS);
               liaison = (XSLTLiaison)clazz.newInstance();
           } else if (proc.equals("xslp")) {
               log("DEPRECATED - xslp processor is deprecated. Use trax or "
                   + "xalan instead.");
  -            final Class clazz =
  -                loadClass(XSLP_LIASON_CLASS);
  +            final Class clazz = loadClass(XSLP_LIASON_CLASS);
               liaison = (XSLTLiaison) clazz.newInstance();
           } else if (proc.equals("xalan")) {
  -            final Class clazz =
  -                loadClass(XALAN_LIASON_CLASS);
  +            final Class clazz = loadClass(XALAN_LIASON_CLASS);
               liaison = (XSLTLiaison)clazz.newInstance();
           } else {
               liaison = (XSLTLiaison) loadClass(proc).newInstance();
  @@ -519,11 +512,11 @@
        */
       private void ensureDirectoryFor(File targetFile) 
            throws BuildException {
  -        File directory = new File( targetFile.getParent() );
  +        File directory = fileUtils.getParentFile(targetFile);
           if (!directory.exists()) {
               if (!directory.mkdirs()) {
                   throw new BuildException("Unable to create directory: "
  -                + directory.getAbsolutePath() );
  +                                         + directory.getAbsolutePath() );
               }
           }
       }
  
  
  
  1.16      +1 -0      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
  
  Index: TraXLiaison.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TraXLiaison.java	9 Apr 2002 14:51:55 -0000	1.15
  +++ TraXLiaison.java	12 Apr 2002 12:58:02 -0000	1.16
  @@ -89,6 +89,7 @@
    * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
    * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
    * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
  + * @since Ant 1.3
    */
   public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware {
   
  
  
  
  1.11      +3 -2      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XalanLiaison.java
  
  Index: XalanLiaison.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XalanLiaison.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- XalanLiaison.java	10 Jan 2002 13:59:34 -0000	1.10
  +++ XalanLiaison.java	12 Apr 2002 12:58:02 -0000	1.11
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -73,6 +73,7 @@
    *
    * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
    * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
  + * @since Ant 1.1
    */
   public class XalanLiaison implements XSLTLiaison {
   
  @@ -80,7 +81,7 @@
       protected File stylesheet;
   
       public XalanLiaison() throws Exception {
  -      processor = XSLTProcessorFactory.getProcessor();
  +        processor = XSLTProcessorFactory.getProcessor();
       }
   
       public void setStylesheet(File stylesheet) throws Exception {
  
  
  
  1.12      +14 -15    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XslpLiaison.java
  
  Index: XslpLiaison.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XslpLiaison.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- XslpLiaison.java	10 Jan 2002 13:59:34 -0000	1.11
  +++ XslpLiaison.java	12 Apr 2002 12:58:02 -0000	1.12
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -64,14 +64,12 @@
   import java.io.FileOutputStream;
   import java.io.OutputStreamWriter;
   
  -
  -
  -
   /**
    * Concrete liaison for XSLP
    *
    * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
    * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
  + * @since Ant 1.1
    */
   public class XslpLiaison implements XSLTLiaison {
   
  @@ -79,20 +77,21 @@
       protected XSLStylesheet xslSheet;
   
       public XslpLiaison() {
  -      processor = new XSLProcessor();
  -      // uh ?! I'm forced to do that otherwise a setProperty crashes with NPE !
  -      // I don't understand why the property map is static though...
  -      // how can we do multithreading w/ multiple identical parameters ?
  -      processor.getProperty("dummy-to-init-properties-map");
  +        processor = new XSLProcessor();
  +        // uh ?! I'm forced to do that otherwise a setProperty crashes
  +        // with NPE !  I don't understand why the property map is static
  +        // though...  how can we do multithreading w/ multiple identical
  +        // parameters ?
  +        processor.getProperty("dummy-to-init-properties-map");
       }
   
       public void setStylesheet(File fileName) throws Exception {
  -      XSLReader xslReader = new XSLReader();
  -      // a file:/// + getAbsolutePath() does not work here
  -      // it is really the pathname
  -      xslSheet = xslReader.read( fileName.getAbsolutePath() );
  +        XSLReader xslReader = new XSLReader();
  +        // a file:/// + getAbsolutePath() does not work here
  +        // it is really the pathname
  +        xslSheet = xslReader.read( fileName.getAbsolutePath() );
       }
  -
  +    
       public void transform(File infile, File outfile) throws Exception {
           FileOutputStream fos = new FileOutputStream(outfile);
           // XSLP does not support encoding...we're in hot water.
  @@ -101,7 +100,7 @@
       }
   
       public void addParam(String name, String expression){
  -      processor.setProperty(name, expression);
  +        processor.setProperty(name, expression);
       }
   
       public void setOutputtype(String type) throws Exception {
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message