سؤال

I'm rewriting build.xml file from Ant to Phing and everything goes fine with one exception. I need to add new line at the end of each appended file but I can't find any alternative for fixlastline="true".

In Ant it was

 <concat destfile="${libraryFilePrefix}.js" fixlastline="yes">
     <!-- many filesets -->
 </concat>

In Phing it's like

 <append destfile="${libraryFilePrefix}.js">
     <!-- many filesets -->
 </append>

Is there any attribute that works like fixlastline or maybe I need to find another way to achieve this?

هل كانت مفيدة؟

المحلول

I believe, one of the approaches (and possibly the only one) is applying replaceregexp filter on each fileset. You only need to apply filterchain at the beginning and it will do the job for each fileset, like this:

<append destfile="${libraryFilePrefix}.js">
    <filterchain>
        <replaceregexp>
            <regexp pattern="([^\n])$" replace="$1${line.separator}" ignoreCase="true"/>
        </replaceregexp>
    </filterchain>

    <!-- many filesets -->
</append>

نصائح أخرى

As of Phing 3.x the AppendTask is aware of the fixlastline attribute. Your Ant script provided is now working as expected

    <project name="concat-supports-fixlastline" default="concat-fixed-lastline" basedir=".">
        <target name="concat-fixed-lastline">            
            <concat destfile="${libraryFilePrefix}.js" fixlastline="yes">
                <!-- many filesets -->
            </concat>
        </target>
    </project>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top