ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs LoadFile.java
Date Fri, 01 Feb 2002 07:22:56 GMT
stevel      02/01/31 23:22:56

  Modified:    src/main/org/apache/tools/ant/taskdefs LoadFile.java
  Log:
  two new attrs to loadfile to make it more flexible in feeding other tasks
  
  Revision  Changes    Path
  1.6       +59 -8     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/LoadFile.java
  
  Index: LoadFile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/LoadFile.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LoadFile.java	20 Jan 2002 20:45:56 -0000	1.5
  +++ LoadFile.java	1 Feb 2002 07:22:56 -0000	1.6
  @@ -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
  @@ -56,14 +56,10 @@
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.ProjectHelper;
   
   
  -
  -import java.io.File;
  -import java.io.FileInputStream;
  -import java.io.InputStreamReader;
  -import java.io.IOException;
  -import java.io.BufferedInputStream;
  +import java.io.*;
   
   /**
    * Load a file into a property
  @@ -95,6 +91,16 @@
       private String property = null;
   
   
  +    /** flag to control if we flatten the file or no'
  +     *
  +     */
  +    private boolean makeOneLine=false;
  +
  +    /**
  +     * flag to control whether props get evaluated or not
  +     */
  +    private boolean evaluateProperties=false;
  +
       /**
        * Encoding to use for filenames, defaults to the platform's default
        * encoding. <p>
  @@ -140,6 +146,22 @@
           failOnError = fail;
       }
   
  +    /**
  +     * setter to flatten the file to a single line
  +     * @since 1.6
  +     */
  +    public void setMakeOneLine(boolean makeOneLine) {
  +        this.makeOneLine=makeOneLine;
  +    }
  +
  +    /**
  +     * setter to eval properties.
  +     * @since 1.6
  +     */
  +    public void setEvaluateProperties(boolean evaluateProperties) {
  +        this.evaluateProperties=evaluateProperties;
  +    }
  +
   
       /**
        * read in a source file to a property
  @@ -157,7 +179,7 @@
           }
           FileInputStream fis = null;
           BufferedInputStream bis = null;
  -        InputStreamReader instream = null;
  +        Reader instream = null;
           log("loading "+srcFile+" into property "+property,Project.MSG_VERBOSE);
           try {
               long len = srcFile.length();
  @@ -179,6 +201,12 @@
               }
               instream.read(buffer);
               String text = new String(buffer);
  +            if (makeOneLine) {
  +                text=stripLineBreaks(text);
  +            }
  +            if(evaluateProperties) {
  +                text=ProjectHelper.replaceProperties(project,text);
  +            }
               project.setNewProperty(property, text);
               log("loaded "+buffer.length+" characters",Project.MSG_VERBOSE);
               log(property+" := "+text,Project.MSG_DEBUG);
  @@ -199,6 +227,29 @@
               } catch (IOException ioex) {
               }
           }
  +    }
  +
  +    /**
  +     * strip out all line breaks from a string.
  +     * @param source source
  +     * This implementation always duplicates the string; it is nominally possible to probe
  +     * the string first looking for any line breaks before bothering to do a copy. But
we assume if
  +     * the option is requested, then line breaks are probably in the source string.
  +     */
  +    protected String stripLineBreaks(String source) {
  +        //Linebreaks. What do to on funny IBM mainframes with odd line endings?
  +        String linebreaks="\r\n";
  +        int len=source.length();
  +
  +        StringBuffer dest=new StringBuffer(len);
  +        for(int i=0;i<len;++i) {
  +            char ch=source.charAt(i);
  +            if(linebreaks.indexOf(ch)==-1) {
  +                dest.append(ch);
  +            }
  +        }
  +        return new String(dest);
  +
       }
   
   //end class
  
  
  

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