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/testcases/org/apache/tools/ant/util JAXPUtilsTest.java
Date Thu, 31 Oct 2002 14:30:08 GMT
bodewig     2002/10/31 06:30:08

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/taskdefs/optional
                        TraXLiaison.java
               src/main/org/apache/tools/ant/taskdefs/optional/junit
                        AggregateTransformer.java
               src/main/org/apache/tools/ant/util JAXPUtils.java
               src/testcases/org/apache/tools/ant/taskdefs/optional
                        TraXLiaisonTest.java
  Added:       src/testcases/org/apache/tools/ant/util JAXPUtilsTest.java
  Log:
  Merge Stephane's system-id refactoring into HEAD.
  
  Revision  Changes    Path
  1.303     +2 -2      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.302
  retrieving revision 1.303
  diff -u -r1.302 -r1.303
  --- WHATSNEW	18 Oct 2002 07:00:53 -0000	1.302
  +++ WHATSNEW	31 Oct 2002 14:30:06 -0000	1.303
  @@ -22,8 +22,8 @@
   * <manifest> wouldn't update an existing manifest if only an attribute
     of an existing section changed.
   
  -* ant.bat now supports the ANT_ARGS environment variable again (like
  -  Ant 1.5 did).
  +* ant.bat now supports the ANT_ARGS and JAVACMD environment variables
  +  again (like Ant 1.5 did).
   
   * The "plain" <junit> <formatter> could throw a NullPointerException
     if an error occured in setUp.
  
  
  
  1.22      +12 -20    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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- TraXLiaison.java	25 Jul 2002 15:21:11 -0000	1.21
  +++ TraXLiaison.java	31 Oct 2002 14:30:07 -0000	1.22
  @@ -79,6 +79,7 @@
   import org.apache.tools.ant.taskdefs.XSLTLiaison;
   import org.apache.tools.ant.taskdefs.XSLTLogger;
   import org.apache.tools.ant.taskdefs.XSLTLoggerAware;
  +import org.apache.tools.ant.util.JAXPUtils;
   import org.xml.sax.EntityResolver;
   import org.xml.sax.InputSource;
   import org.xml.sax.XMLReader;
  @@ -144,7 +145,7 @@
               fos = new BufferedOutputStream(new FileOutputStream(outfile));
               StreamResult res = new StreamResult(fos);
               // not sure what could be the need of this...
  -            res.setSystemId(getSystemId(outfile));
  +            res.setSystemId(JAXPUtils.getSystemId(outfile));
               Source src = getSource(fis, infile);
               transformer.transform(src, res);
           } finally {
  @@ -192,7 +193,7 @@
           } else {
               src = new StreamSource(is);
           }
  -        src.setSystemId(getSystemId(infile));
  +        src.setSystemId(JAXPUtils.getSystemId(infile));
           return src;
       }
   
  @@ -218,7 +219,7 @@
               StreamSource src = new StreamSource(xslStream);
               // Always set the systemid to the source for imports, includes...
               // in xsl and xml...
  -            src.setSystemId(getSystemId(stylesheet));
  +            src.setSystemId(JAXPUtils.getSystemId(stylesheet));
               Templates templates = getFactory().newTemplates(src);
               Transformer transformer = templates.newTransformer();
   
  @@ -244,23 +245,6 @@
           }
       }
   
  -    // make sure that the systemid is made of '/' and not '\' otherwise
  -    // crimson will complain that it cannot resolve relative entities
  -    // because it grabs the base uri via lastIndexOf('/') without
  -    // making sure it is really a /'ed path
  -    protected String getSystemId(File file) {
  -        String path = file.getAbsolutePath();
  -        path = path.replace('\\', '/');
  -
  -        // on Windows, use 'file:///'
  -        if (File.separatorChar == '\\') {
  -            return FILE_PROTOCOL_PREFIX + "/" + path;
  -        }
  -        // Unix, use 'file://'
  -        return FILE_PROTOCOL_PREFIX + path;
  -    }
  -
  -
       /**
        * return the Transformer factory associated to this liaison.
        * @return the Transformer factory associated to this liaison.
  @@ -398,6 +382,14 @@
           }
   
           logger.log(msg.toString());
  +    }
  +
  +    // kept for backwards compatibility
  +    /**
  +     * @deprecated use org.apache.tools.ant.util.JAXPUtils#getSystemId instead
  +     */
  +    protected String getSystemId(File file) {
  +        return JAXPUtils.getSystemId(file);
       }
   
   } //-- TraXLiaison
  
  
  
  1.21      +8 -9      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
  
  Index: AggregateTransformer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- AggregateTransformer.java	26 Sep 2002 12:11:37 -0000	1.20
  +++ AggregateTransformer.java	31 Oct 2002 14:30:07 -0000	1.21
  @@ -64,6 +64,7 @@
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.Task;
  +import org.apache.tools.ant.util.JAXPUtils;
   import org.apache.tools.ant.types.EnumeratedAttribute;
   import org.w3c.dom.Document;
   
  @@ -212,20 +213,18 @@
           if (NOFRAMES.equals(format)){
               xslname = "junit-noframes.xsl";
           }
  -        URL url = null;
           if (styleDir == null){
  -            url = getClass().getResource("xsl/" + xslname);
  +            URL url = getClass().getResource("xsl/" + xslname);
               if (url == null){
                   throw new FileNotFoundException("Could not find jar resource " + xslname);
               }
  -        } else {
  -            File file = new File(styleDir, xslname);
  -            if (!file.exists()){
  -                throw new FileNotFoundException("Could not find file '" + file + "'");
  -            }
  -            url = new URL("file", "", file.getAbsolutePath());
  +            return url.toExternalForm();
  +        }
  +        File file = new File(styleDir, xslname);
  +        if (!file.exists()){
  +            throw new FileNotFoundException("Could not find file '" + file + "'");
           }
  -        return url.toExternalForm();
  +        return JAXPUtils.getSystemId(file);
       }
   
   }
  
  
  
  1.3       +27 -0     jakarta-ant/src/main/org/apache/tools/ant/util/JAXPUtils.java
  
  Index: JAXPUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/util/JAXPUtils.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JAXPUtils.java	25 Jul 2002 15:21:24 -0000	1.2
  +++ JAXPUtils.java	31 Oct 2002 14:30:07 -0000	1.3
  @@ -53,6 +53,7 @@
    */
   package org.apache.tools.ant.util;
   
  +import java.io.File;
   import javax.xml.parsers.FactoryConfigurationError;
   import javax.xml.parsers.ParserConfigurationException;
   import javax.xml.parsers.SAXParser;
  @@ -75,6 +76,11 @@
   public class JAXPUtils {
   
       /**
  +     * The file protocol: 'file://'
  +     */
  +    private static final String FILE_PROTOCOL_PREFIX = "file://";
  +
  +    /**
        * Parser factory to use to create parsers.
        * @see #getParserFactory
        *
  @@ -145,6 +151,27 @@
           } catch (SAXException e) {
               throw convertToBuildException(e);
           }
  +    }
  +
  +    /**
  +     * This is a best attempt to provide a URL.toExternalForm() from
  +     * a file URL. Some parsers like Crimson choke on uri that are made of
  +     * backslashed paths (ie windows) as it is does not conform
  +     * URI specifications.
  +     * @param file the file to create the system id from.
  +     * @return the systemid corresponding to the given file.
  +     * @since Ant 1.5.2
  +     */
  +    public static String getSystemId(File file){
  +        String path = file.getAbsolutePath();
  +        path = path.replace('\\', '/');
  +
  +        // on Windows, use 'file:///'
  +        if (File.separatorChar == '\\') {
  +            return FILE_PROTOCOL_PREFIX + "/" + path;
  +        }
  +        // Unix, use 'file://'
  +        return FILE_PROTOCOL_PREFIX + path;
       }
   
       /**
  
  
  
  1.10      +0 -1      jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
  
  Index: TraXLiaisonTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TraXLiaisonTest.java	12 Apr 2002 13:26:54 -0000	1.9
  +++ TraXLiaisonTest.java	31 Oct 2002 14:30:07 -0000	1.10
  @@ -2,7 +2,6 @@
   
   import org.apache.tools.ant.taskdefs.XSLTLiaison;
   import org.apache.tools.ant.taskdefs.XSLTLogger;
  -import org.apache.tools.ant.taskdefs.condition.Os;
   import org.apache.tools.ant.BuildException;
   
   import java.io.File;
  
  
  
  1.2       +80 -0     jakarta-ant/src/testcases/org/apache/tools/ant/util/JAXPUtilsTest.java
  
  
  
  

--
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