ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jan.Mate...@rzf.fin-nrw.de>
Subject AW: apply task trouble for command using < and >
Date Fri, 25 Nov 2005 12:05:58 GMT
I tuned the example...


	<!-- Define a new 'task' for easier use -->
	<macrodef name="jsmin">
		<!-- Where to find the development version of JavaScript files -->
		<attribute name="srcDir"/>
		<!-- Where to store the 'compressed' files -->
		<attribute name="destDir"/>
		<sequential>
		    <!-- Iterate over the JS-files and dont pass the filename as argument -->
            <apply executable="jsmin" addsourcefile="false">
            	<!-- Collect the JS-files -->
                <fileset dir="@{srcDir}" includes="*.js"/>
                <redirector>
                    <!-- redirect STDIN; fileset collects relative to its dir, but we need
relative to basedir -->
                    <inputmapper type="glob" from="*" to="@{srcDir}/*"/>
                    <!-- redirect STDOUT to file in dest-dir -->
		            <outputmapper id="out" type="glob"
    	                from="*.js"
        	            to="@{destDir}/*.js"/>
                </redirector>
            </apply>
		</sequential>
	</macrodef>

	<target name="jsmin2">
		<!-- compress the JavaScript files -->
		<jsmin srcDir="src" destDir="dest"/>
		<!-- print the compressed files out - for check only -->
        <concat><fileset dir="dest"/></concat>
	</target>



 

>-----Urspr√ľngliche Nachricht-----
>Von: Jakob Fix [mailto:jakob.fix@gmail.com] 
>
>
>>         <mapper id="out" type="glob"
>>                 from="*.js"
>>                 to="dest/*.js"/>
>
>"Map" (whatever this means exactly) each file ending in .js to 
>dest/*.js.  This will be used later on.


Mapping means applying a rule for converting a amount of names to
other names. You could think about using a 
    s#(.*)\.js#\dest\1.js#
but you got the meaning.


>>         <apply executable="jsmin">
>>             <fileset dir="src" includes="*.js"/>
>
>Create a fileset of all files in the src/ directory ending in 
>.js.  I guess this is represented internally as a list of 
>absolute pathnames of all files ending .js in the src/ 
>directory.  The apply task will then cycle through this list, 
>file by file.

Nope - not the fileset itself gives you absolute filenames. The
DirectoryScanner used internally does that. Have a look at the 
Tutorial "Tasks using Properties, Filesets & Paths" in the manual
for more about using filesets in tasks.
  http://ant.apache.org/manual/tutorial-tasks-filesets-properties.html#filesets


>>             <mapper refid="out"/>
>
> At least, I found you can put this element anywhere inside 
>the apply task.  Another thing, I commented this line out, and 
>the results are the same.  Bizarre?!

Havent looked at that. But maybe <apply> ignores nested <mappers> silently -
maybe only if a <redirector> is present. Main point here is the definition with
"id" and reusing it via "refid".



>And it works!  Wow, that's what I call black magic.

Black magic is ok ... for the first (few) steps.
But we want to give more knowledge to convert that into "white magic" ;-)



>Although, there's still one minor hiccup; the input filename 
>is passed to jsmin as an argument, but where?  I know this 
>because it re-appears at the beginning of the out output file 
>as a comment, which is what jsmin does with additional 
>arguments.  (This is why I tried to uncomment the <mapper 
>refid="out"/> line, but to no effect.)

Standard behaviour of <apply>, but can be switched off - as done in the
new code.



>Thanks a lot.  Now, how can I contribute some documentation for this?

For what exactly? 
Contributions are welcome as patches in bugzilla.



Jan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message