6 million ways to deploy, choose one
Die Aufgabe ist mit dem yuicompressor alle css files einzeln zu komprimieren.
Concatenation lasse ich weg.
Wir haben zur Auswahl 2 x mal als ant deploy und einmal die gute alte shell.
Das yuicompressor jar ist “installiert” und liegt hier:
/usr/share/ant/lib/yuicompressor.jar
Und es kann losgehen:
1. ant via apply task
Ein Property (im externen property file) für das jar:
yuicompressor=/usr/share/ant/lib/yuicompressor.jar
Und nun der task:
<target name="minifyCSS">
<apply executable="java" parallel="false" verbose="true" dest="${buildir}/project/${updateChannelTemp}/">
<fileset dir="${updateChannelTemp}/${SvnExportDir}/scripts/" includes="*.css" excludes="*.min.css"/>
<arg line="-jar"/>
<arg path="${yuicompressor}"/>
<arg line="-v"/>
<arg line="--charset latin1"/>
<srcfile />
<arg line="-o"/>
<mapper type="glob" from="*.css" to="*.css"/>
<targetfile/>
</apply>
<move todir="${buildir}/project/${updateChannelTemp}/${SvnExportDir}/scripts/" overwrite="true">
<fileset dir="${buildir}/project/${updateChannelTemp}/" includes="*.css" />
</move>
</target>
2. ant via yui-compressor task
Dazu brauch es noch ein paar Vorbereitungen:
Hierzu muss das Task noch “installiert” werden, ich packs mal zu den anderen jars und dazu ein Property:
yuicompressortask=/usr/share/ant/lib/yui-compressor-task.jar
Weiterhin den Ant ClassPath:
<path id="project.classpath">
[...]
<pathelement location="${yuicompressortask}" />
<pathelement location="${yuicompressor}" />
</path>
Den Task definieren:
<taskdef name="yui-compressor" classname="net.noha.tools.ant.yuicompressor.tasks.YuiCompressorTask">
und das eigentliche Target:
<target name="minifyCSS2">
<mkdir dir="${updateChannelTemp}/${SvnExportDir}/scripts/css/"/>
<yui-compressor
warn="false"
munge="true"
cssSuffix=".css"
jsSuffix=".js"
preserveallsemicolons="false"
fromdir="${updateChannelTemp}/${SvnExportDir}/scripts/"
todir="${updateChannelTemp}/${SvnExportDir}/scripts/css/">
<include name="*.css" />
</yui-compressor>
<move todir="${updateChannelTemp}/${SvnExportDir}/scripts/" overwrite="true">
<fileset dir="${updateChannelTemp}/${SvnExportDir}/scripts/css/" includes="*.css" />
</move>
<delete dir="${updateChannelTemp}/${SvnExportDir}/scripts/css/" />
</target>
3. via shell
java -jar /usr/share/ant/lib/yuicompressor.jar --type -v css < /home/builds/project/css/*.css > /home/builds/project/css/*.css
Fazit:
Ich hasse liebe ant.
Achtung: keine Gewähr, dass das die snippets funktionieren, weil ziemlich aus dem Kontext gerissen.
Ich wollte nur mal verdeutlichen was für ein overhead ant manchmal erzeugt.
Ich benutze es trotzdem ;)
eleg-ant :)