ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sbaill...@apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/optional TraXLiaisonTest.java
Date Wed, 30 Oct 2002 10:38:47 GMT
sbailliez    2002/10/30 02:38:47

  Modified:    src/main/org/apache/tools/ant/taskdefs/optional/junit Tag:
                        ANT_15_BRANCH AggregateTransformer.java
               src/main/org/apache/tools/ant/util Tag: ANT_15_BRANCH
                        JAXPUtils.java
               src/main/org/apache/tools/ant/taskdefs/optional Tag:
                        ANT_15_BRANCH TraXLiaison.java
               src/testcases/org/apache/tools/ant/taskdefs/optional Tag:
                        ANT_15_BRANCH TraXLiaisonTest.java
  Added:       src/testcases/org/apache/tools/ant/util Tag: ANT_15_BRANCH
                        JAXPUtilsTest.java
  Log:
  Fix systemid as created in the transformer.
  Refactor the systemid magic fromTraxLiaison into JAXPUtils.
  Reported by:  Frank Wagner <fwagner@ilog.fr>
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.16.2.3  +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.16.2.2
  retrieving revision 1.16.2.3
  diff -u -r1.16.2.2 -r1.16.2.3
  --- AggregateTransformer.java	26 Sep 2002 12:20:58 -0000	1.16.2.2
  +++ AggregateTransformer.java	30 Oct 2002 10:38:46 -0000	1.16.2.3
  @@ -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);
       }
   
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +29 -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.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- JAXPUtils.java	23 Apr 2002 11:42:51 -0000	1.1
  +++ JAXPUtils.java	30 Oct 2002 10:38:46 -0000	1.1.2.1
  @@ -63,6 +63,8 @@
   import javax.xml.parsers.SAXParser;
   import javax.xml.parsers.ParserConfigurationException;
   import javax.xml.parsers.FactoryConfigurationError;
  +import java.io.File;
  +
   
   /**
    * Collection of helper methods that retrieve a ParserFactory or
  @@ -77,6 +79,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
        *
  @@ -150,6 +157,27 @@
       }
   
       /**
  +     * 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;
  +    }
  +
  +    /**
        * @return a new SAXParser instance as helper for getParser and
        * getXMLReader.
        *
  @@ -179,5 +207,6 @@
               return new BuildException(e);
           }
       }
  +
   
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +80 -0     jakarta-ant/src/testcases/org/apache/tools/ant/util/Attic/JAXPUtilsTest.java
  
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.17.2.3  +13 -29    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.17.2.2
  retrieving revision 1.17.2.3
  diff -u -r1.17.2.2 -r1.17.2.3
  --- TraXLiaison.java	29 Jun 2002 15:31:06 -0000	1.17.2.2
  +++ TraXLiaison.java	30 Oct 2002 10:38:47 -0000	1.17.2.3
  @@ -60,6 +60,7 @@
   import java.io.IOException;
   
   import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.util.JAXPUtils;
   import org.apache.tools.ant.taskdefs.XSLTLiaison;
   import org.apache.tools.ant.taskdefs.XSLTLoggerAware;
   import org.apache.tools.ant.taskdefs.XSLTLogger;
  @@ -148,7 +149,7 @@
       public void setStylesheet(File stylesheet) throws Exception {
           xslStream = new FileInputStream(stylesheet);
           StreamSource src = new StreamSource(xslStream);
  -        src.setSystemId(getSystemId(stylesheet));
  +        src.setSystemId(JAXPUtils.getSystemId(stylesheet));
           templates = tfactory.newTemplates(src);
           transformer = templates.newTransformer();
           transformer.setErrorListener(this);
  @@ -177,10 +178,10 @@
               } else {
                   src = new StreamSource(fis);
               }
  -            src.setSystemId(getSystemId(infile));
  +            src.setSystemId(JAXPUtils.getSystemId(infile));
               StreamResult res = new StreamResult(fos);
               // not sure what could be the need of this...
  -            res.setSystemId(getSystemId(outfile));
  +            res.setSystemId(JAXPUtils.getSystemId(outfile));
   
               if (uriResolver != null)
                   transformer.setURIResolver(uriResolver);
  @@ -208,22 +209,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;
  -    }
  -
       public void addParam(String name, String value){
           transformer.setParameter(name, value);
       }
  @@ -252,19 +237,18 @@
           
           StringBuffer msg = new StringBuffer();
           if (e.getLocator() != null) {
  -            if (e.getLocator().getSystemId() != null) {
  -                String url = e.getLocator().getSystemId();
  -                if (url.startsWith("file:///")) {
  -                  url = url.substring(8);
  -                }
  -                msg.append(url);
  +            String systemId = e.getLocator().getSystemId();
  +            if (systemId != null) {
  +                msg.append(systemId);
               } else {
                   msg.append("Unknown file");
               }
  -            if (e.getLocator().getLineNumber() != -1) {                          
  -                msg.append(":" + e.getLocator().getLineNumber());
  -                if (e.getLocator().getColumnNumber() != -1) {
  -                    msg.append(":" + e.getLocator().getColumnNumber());
  +            int line = e.getLocator().getLineNumber();
  +            if (line != 0) {
  +                msg.append(':').append(line);
  +                int col = e.getLocator().getColumnNumber();
  +                if (col != 0) {
  +                    msg.append(':').append(col);
                   }
               }
           }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.9.2.1   +0 -13     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.9.2.1
  diff -u -r1.9 -r1.9.2.1
  --- TraXLiaisonTest.java	12 Apr 2002 13:26:54 -0000	1.9
  +++ TraXLiaisonTest.java	30 Oct 2002 10:38:47 -0000	1.9.2.1
  @@ -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;
  @@ -117,18 +116,6 @@
                   out.delete();
               }
           }
  -    }
  -
  -    public void testSystemId(){
  -        File file = null;
  -        if ( File.separatorChar == '\\' ){
  -            file = new File("d:\\jdk");
  -        } else {
  -            file = new File("/user/local/bin");
  -        }
  -        String systemid = ((TraXLiaison)liaison).getSystemId(file);
  -        assertTrue("SystemIDs should start by file:///", systemid.startsWith("file:///"));
  -        assertTrue("SystemIDs should not start with file:////", !systemid.startsWith("file:////"));
       }
   
       public void log(String message) {
  
  
  

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