Ant: How to echo the name of targetfile within apply - ant

I'm not really familiar with Ant and i wonder how to print the name of the current processed file to the commandline.
This is what i have so far... It's a part of a macro which minifys files with the yui-compressor.
<apply executable="java" parallel="false" verbose="true" dest="#{target}">
<fileset dir="#{src}">
<include name="**/*.#{filetype}"/>
</fileset>
<arg line="-jar" />
<arg path="${yui.jar}" />
<arg value="--charset" />
<arg value="ANSI" />
<arg value="-o" />
<targetfile />
<mapper type="glob" from="*.#{filetype}" to="*.min.#{filetype}" />
</apply>
What i'm trying to get:
[echo] Start!
[apply] Processed: filename-1.min.js
[apply] Processed: filename-2.min.js
[apply] Processed: filename-3.min.js
[echo] Success!

I don't have a lot of experience with apply but you could try defining your fileset out of the apply element , getting your printed results and then referring to it into your apply element.
<fileset dir="#{src}" id="my.files">
<include name="**/*.#{filetype}"/>
</fileset>
<pathconvert pathsep="${line.separator}" property="processed.files" refid="my.files"/>
<echo>Start!</echo>
<echo message="${processed.files}"/>
<apply executable="java" parallel="false" verbose="true" dest="#{target}">
<fileset refid="my.files"/>
<arg line="-jar" />
<arg path="${yui.jar}" />
<arg value="--charset" />
<arg value="ANSI" />
<arg value="-o" />
<targetfile />
<mapper type="glob" from="*.#{filetype}" to="*.min.#{filetype}" />
</apply>
<echo>Success!</echo>
Of course this will only work if the apply executable doesn't print anything to clutter the output.

The best way I've found to do this is to add the debug or verbose flag to ant:
ant target-name -debug or ant target-name -verbose
This will then print the executing command-line. For example:
[apply] Executing 'lib\NUnit\bin\nunit-console-x86.exe' with arguments:
[apply] '/noshadow'
[apply] '/domain:multiple'
[apply] '/labels'
[apply] '/framework:net-4.5'
[apply] '/nologo'
[apply] 'C:\blah\foo.Tests.dll
Unfortunately, this will verbosely log everything, and not just the specific apply.

Related

Zend Server: Application name already exists

we have a problem on our Zend Server during the deployment of an application.
We've set up a virtual host on our Zend Server called "dev.application-7.de".
We are trying to deploy our Zend Framework 2 project over Jenkins to this virtual host. Usually this works well.
But we got the following error in 3 out of 170 builds:
deploy:
[exec] ======================================================================
[exec] The application has thrown an exception!
[exec] ======================================================================
[exec] ZendServerWebApi\Model\Exception\ApiException
[exec] Invalid userAppName parameter: Application name 'application-7' already exists
[exec] 2015-03-13T11:35:12+01:00 ERR (3): Invalid userAppName parameter: Application name 'application-7' already exists<zendServerAPIResponse xmlns="http://www.zend.com/server/api/1.9">
[exec] <requestData>
[exec] <apiKeyName><![CDATA[ZendStudio]]></apiKeyName>
[exec] <method>applicationDeploy</method>
[exec] </requestData>
[exec] <errorData>
[exec] <errorCode>applicationConflict</errorCode>
[exec] <errorMessage><![CDATA[Invalid userAppName parameter: Application name 'application-7' already exists]]></errorMessage>
[exec] </errorData></zendServerAPIResponse>
To fix this problem, we deleted the virtual host and recreated it with the same config mentioned below.
Is there another way to fix the problem?
Further Information
Zend Server Version:
Version 8.0.2, Developer Standard Edition, Development profile
OS Version:
Ubuntu 14.04.1 LTS
Jenkins Version:
1.599
Information about the Virtual-Host:
Type: Zend Server defined
Created at: 27/Feb/2015 8:18:23
Document Root: /usr/local/zend/var/apps/https/dev.application-7.de/443/1.0.0_177/public/
Security: SSL enabled
Certificate File Path /etc/apache2/ssl/dev.application-7.de.crt
Key File Path /etc/apache2/ssl/dev.application-7.de.key
Chain File Path /etc/apache2/ssl/dev.application-7.de.csr
Virtual-Hosts Config:
<VirtualHost *:443>
SetEnv "APP_ENV" "dev"
DocumentRoot "/usr/local/zend/var/apps/https/dev.application-7.de/443/1.0.0_177/public/"
<Directory "/usr/local/zend/var/apps/https/dev.application-7.de/443/1.0.0_177/public/">
Options +Indexes +FollowSymLinks
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile "/etc/apache2/ssl/dev.application-7.de.crt"
SSLCertificateKeyFile "/etc/apache2/ssl/dev.application-7.de.key"
SSLCertificateChainFile "/etc/apache2/ssl/dev.application-7.de.csr"
ServerName dev.application-7.de:443
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
# include the folder containing the vhost aliases for zend server deployment
IncludeOptional "/usr/local/zend/etc/sites.d/https/dev.application-7.de/443/*.conf"
</VirtualHost>
Ant Build File:
<?xml version="1.0" encoding="UTF-8"?>
<project name="application-7-de-2" default="build">
<!-- By default, we assume all tools to be on the $PATH -->
<!-- <property name="toolsdir" value=""/> -->
<!-- Uncomment the following when the tools are in ${basedir}/vendor/bin -->
<!-- <property name="toolsdir" value="${basedir}/vendor/bin/"/> -->
<!-- Uncomment the following when the tools are in a custom path -->
<property name="baseuri" value="https://dev.application-7.de:443"/>
<property name="appname" value="application-7-de"/>
<property name="defaultserver" value="false"/>
<property name="toolsdir" value="/usr/local/zend/bin/"/>
<property name="params" value="APP_ENV=dev"/>
<property name="host" value="http://our-zend-server.de:10081"/>
<property name="key" value="ZendStudio"/>
<property name="secret" value="OUR_SECRET"/>
<target name="build" depends="prepare,composer,lint,phploc-ci,pdepend,phpmd-ci,phpcs-ci,phpcpd-ci,phpunit,phpdox,zpk,deploy" description=""/>
<target name="build-parallel" depends="prepare,lint,tools-parallel,phpunit,phpdox" description=""/>
<target name="tools-parallel" description="Run tools in parallel">
<parallel threadCount="2">
<sequential>
<antcall target="pdepend"/>
<antcall target="phpmd-ci"/>
</sequential>
<antcall target="phpcpd-ci"/>
<antcall target="phpcs-ci"/>
<antcall target="phploc-ci"/>
</parallel>
</target>
<target name="clean" unless="clean.done" description="Cleanup build artifacts">
<delete dir="${basedir}/build/api"/>
<delete dir="${basedir}/build/coverage"/>
<delete dir="${basedir}/build/logs"/>
<delete dir="${basedir}/build/pdepend"/>
<delete dir="${basedir}/build/phpdox"/>
<property name="clean.done" value="true"/>
</target>
<target name="prepare" unless="prepare.done" depends="clean" description="Prepare for build">
<mkdir dir="${basedir}/build/api"/>
<mkdir dir="${basedir}/build/coverage"/>
<mkdir dir="${basedir}/build/logs"/>
<mkdir dir="${basedir}/build/pdepend"/>
<mkdir dir="${basedir}/build/phpdox"/>
<property name="prepare.done" value="true"/>
</target>
<target name="composer" depends="prepare" description="Update dependencies">
<exec executable="${toolsdir}composer" failonerror="true">
<arg value="update"/>
<arg value="--working-dir"/>
<arg path="${basedir}"/>
</exec>
</target>
<target name="lint" description="Perform syntax check of sourcecode files">
<apply executable="php" failonerror="true">
<arg value="-l" />
<fileset dir="${basedir}/module">
<include name="**/*.php" />
<modified />
</fileset>
<fileset dir="${basedir}/tests">
<include name="**/*.php" />
<modified />
</fileset>
</apply>
</target>
<target name="phploc" description="Measure project size using PHPLOC and print human readable output. Intended for usage on the command line.">
<exec executable="${toolsdir}phploc">
<arg value="--count-tests" />
<arg path="${basedir}/module" />
<arg path="${basedir}/tests" />
</exec>
</target>
<target name="phploc-ci" depends="prepare" description="Measure project size using PHPLOC and log result in CSV and XML format. Intended for usage within a continuous integration environment.">
<exec executable="${toolsdir}phploc">
<arg value="--count-tests" />
<arg value="--log-csv" />
<arg path="${basedir}/build/logs/phploc.csv" />
<arg value="--log-xml" />
<arg path="${basedir}/build/logs/phploc.xml" />
<arg path="${basedir}/module" />
<arg path="${basedir}/tests" />
</exec>
</target>
<target name="pdepend" depends="prepare" description="Calculate software metrics using PHP_Depend and log result in XML format. Intended for usage within a continuous integration environment.">
<exec executable="${toolsdir}pdepend">
<arg value="--jdepend-xml=${basedir}/build/logs/jdepend.xml" />
<arg value="--jdepend-chart=${basedir}/build/pdepend/dependencies.svg" />
<arg value="--overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg" />
<arg path="${basedir}/module" />
</exec>
</target>
<target name="phpmd" description="Perform project mess detection using PHPMD and print human readable output. Intended for usage on the command line before committing.">
<exec executable="${toolsdir}phpmd">
<arg path="${basedir}/module" />
<arg value="text" />
<arg path="${basedir}/build/phpmd.xml" />
</exec>
</target>
<target name="phpmd-ci" depends="prepare" description="Perform project mess detection using PHPMD and log result in XML format. Intended for usage within a continuous integration environment.">
<exec executable="${toolsdir}phpmd">
<arg path="${basedir}/module" />
<arg value="xml" />
<arg path="${basedir}/build/phpmd.xml" />
<arg value="--reportfile" />
<arg path="${basedir}/build/logs/pmd.xml" />
</exec>
</target>
<target name="phpcs" description="Find coding standard violations using PHP_CodeSniffer and print human readable output. Intended for usage on the command line before committing.">
<exec executable="${toolsdir}phpcs">
<arg value="--standard=PSR2" />
<arg value="--extensions=php" />
<arg value="--ignore=autoload.php" />
<arg path="${basedir}/module" />
<arg path="${basedir}/tests" />
</exec>
</target>
<target name="phpcs-ci" depends="prepare" description="Find coding standard violations using PHP_CodeSniffer and log result in XML format. Intended for usage within a continuous integration environment.">
<exec executable="${toolsdir}phpcs" output="/dev/null">
<arg value="--report=checkstyle" />
<arg value="--report-file=${basedir}/build/logs/checkstyle.xml" />
<arg value="--standard=PSR2" />
<arg value="--extensions=php" />
<arg value="--ignore=autoload.php" />
<arg path="${basedir}/module" />
</exec>
</target>
<target name="phpcpd" description="Find duplicate code using PHPCPD and print human readable output. Intended for usage on the command line before committing.">
<exec executable="${toolsdir}phpcpd">
<arg path="${basedir}/module" />
</exec>
</target>
<target name="phpcpd-ci" depends="prepare" description="Find duplicate code using PHPCPD and log result in XML format. Intended for usage within a continuous integration environment.">
<exec executable="${toolsdir}phpcpd">
<arg value="--log-pmd" />
<arg path="${basedir}/build/logs/pmd-cpd.xml" />
<arg path="${basedir}/module" />
</exec>
</target>
<target name="phpunit" depends="prepare" description="Run unit tests with PHPUnit">
<exec executable="${toolsdir}phpunit" failonerror="true">
<arg value="--log-junit"/>
<arg value="build/logs/junit.xml"/>
<arg value="--configuration"/>
<arg path="${basedir}/tests/phpunit.xml"/>
</exec>
</target>
<target name="phpdox" depends="phploc-ci,phpcs-ci,phpmd-ci" description="Generate project documentation using phpDox">
<exec executable="${toolsdir}phpdox" dir="${basedir}/build"/>
</target>
<target name="zpk" depends="phpdox">
<exec executable="${toolsdir}zs-client" failonerror="true">
<arg value="packZpk"/>
<arg value="--folder=${basedir}"/>
<arg value="--destination=${basedir}"/>
<arg value="--name=application.zpk"/>
</exec>
</target>
<target name="deploy" depends="zpk">
<exec executable="${toolsdir}zs-client" failonerror="true">
<arg value="installApp"/>
<arg value="--baseUri=${baseuri}"/>
<arg value="--userAppName=${appname}"/>
<arg value="--defaultServer=${defaultserver}"/>
<arg value="--userParams=${params}"/>
<arg value="--zpk=${basedir}/application.zpk"/>
<arg value="--zsurl=${host}"/>
<arg value="--zskey=${key}"/>
<arg value="--zssecret=${secret}"/>
</exec>
</target>
</project>

ant compress and override js/css files

Hello i am trying to compress all the .css and .js files from a directory and overwrite the original file with the same name(no concatenation)
I am using this code https://stackoverflow.com/a/3826896/579646 (also tried numerous other tutorials) but it doesn't work.
I tried this
<target name="css.minify">
<apply executable="java" parallel="false" dest="${builddir}/${NAME}/site/assets/css" verbose="true">
<fileset dir="${builddir}/${NAME}/site/assets/css" includes="**/*.css"/>
<arg line="-jar"/>
<arg path="yuicompressor.jar"/>
<arg line="--line-break 0"/>
<srcfile/>
<arg line="-o"/>
<arg line="-v"/>
<mapper type="glob" from="*.css" to="*-min.css"/>
<targetfile/>
</apply>
<move todir="${builddir}/${NAME}/site/assets/css" overwrite="true" >
<fileset dir="${builddir}/${NAME}/site/assets/css" />
<mapper type="glob" from="*-min.css" to="*.css"/>
</move>
</target>
and this
<target name="js.minify">
<apply executable="java" parallel="false">
<fileset dir="${builddir}/${NAME}/site/assets/js" includes="**/*.js" casesensitive="no"/>
<arg line="-jar"/>
<arg path="yuicompressor.jar"/>
<srcfile/>
<arg line="-o"/>
<mapper type="glob" from="*.js" to="*.js"/>
<targetfile/>
</apply>
</target>
They both seem to fail
What am i doing wrong?
I did a test directly using the jar, to see why was not working.
I understood that from command line this is the right command options sequence:
$java -jar WEB-INF/lib/yuicompressor.jar -v -o <destination-file-min.js> <source-file.js>
Note that if the path (parent folders) of the destination file does not exists, the library will not create it (java.io.FileNotFoundException).
So, Ant:
<copy flatten="false" includeemptydirs="true" todir="${js.target.dir}">
<fileset dir="${js.source.dir}" excludes="**/*.*" includes="**/*" />
</copy>
<apply executable="java" dest="${js.target.dir}" parallel="false" verbose="true" ignoremissing="true">
<fileset dir="${js.source.dir}" includes="**/*.js" excludes="**/*-min.js, **/*.min.js"/>
<arg line="-jar"/>
<arg path="docroot/WEB-INF/lib/yuicompressor.jar"/>
<arg line="-o"/>
<mapper type="glob" from="*.js" to="*-min.js"/>
<targetfile/>
<srcfile/>
</apply>
The Copy before Apply is needed to create the relative path of destination minified js.
NOTE that targetfile and srcfile are reversed as expected by the jar.
I pasted only the js part.. for css it's the same.
I use this for both css and js and it works just fine:
<apply executable="java" parallel="false">
<fileset dir="${src.dir}/js" includes="*.js" />
<arg line="-jar" />
<arg path="${lib.path}/yuicompressor-2.4.7.jar" />
<srcfile />
<arg line="-o" />
<mapper type="glob" from="*.js" to="${dest.dir}/js/*.js" />
<targetfile />
</apply>
In the js.minify target u shared seems like u're overwriting the js files (look at the mapper tag), be careful with that.
Also in the css u're moving all the css and renaming them after compressing, this can be done all with the yui compressor target (look at my code).
I hope this helps.

How to locally echo Apply task?

Is it possible to execute an apply on a file set and have ant print the command it is executing?
For example:
<target name="test">
<apply executable="ls" failonerror="true" verbose="true" ignoremissing="false">
<fileset dir=".">
<include name="*.xml" />
</fileset>
<arg line="-la" />
</apply>
</target>
I would like the output to be something close to the following, with the key line being:
[apply] ls -la ./build.xml"
E.g.
Buildfile: /home/abarker/NetBeansProjects/TestProject/build.xml
test:
[apply] ls -la ./build.xml
[apply] -rw-r--r-- 1 abarker abarker 29231 Feb 13 11:29 /home/abarker/NetBeansProjects/TestProject/build.xml
[apply] Applied ls to 1 file and 0 directories.
There are several ideas I have:
You can use the outputproperty parameter. This will give you the output of the command in the <apply> task.
You can use fileset reference instead of an actual fileset.
Like this:
<property name="apply.files.prop" refid='apply.files'/>
<echo>The files you're operating on are "${apply.files.prop}"</echo>
<apply executable="ls" failonerror="true" verbose="true" ignoremissing="false">
<fileset refid="apply.files"/>
<arg line="-la" />
</apply>
You can then look at the fileset reference apply.files to see what files the <apply> task is operating on.
You can always add the -debug and -verbose flag when you run ant. This will print exactly what you want and then some -- then some a whole lot. I wish there was a way to turn verbose mode on and off on a particular task, but I don't know how to do that -- at least an easy way to do that.
For debug purposes - Just replace your own executable with echo. Here is an example of how I do it on Windows machines:
<target name="test">
<apply executable="cmd" failonerror="true" verbose="true" ignoremissing="false">
<fileset dir=".">
<include name="*.xml" />
</fileset>
<arg line="/c" />
<arg line="echo" />
<arg line="ls" />
<arg line="-la" />
</apply>
</target>
Normally when you run ant with -v/-verbose flag, it will print each execution of the command (this also includes exec and apply).

ANT script : how to exclude several files with ASDOC engine

I want to exclude several files (*_include.as) in my source project, to generate ASDOC :
<target name="build-asdoc" depends="manifest">
<delete dir="${asdoc.dir}" />
<mkdir dir="${asdoc.dir}" />
<exec executable="${FLEX_HOME}/bin/asdoc.exe" failonerror="false">
<arg line="-doc-sources '${src.dir}'" />
<arg line="-doc-sources '${lib.dir}'" />
<arg line="-external-library-path '${ivy.cache.dir}/org.puremvc.as3/singlecore/swcs'" />
<arg line="-external-library-path '${ivy.cache.dir}/com.keepcore.calendar/KCCalendar/swcs'" />
<arg line="-external-library-path '${ivy.cache.dir}/org.as3commons/as3commons-lang/swcs'" />
<arg line="-main-title '${asdoc.mainTitle}'" />
<arg line="-window-title '${asdoc.windowTitle}'" />
<arg line="-output '${asdoc.dir}'" />
<arg line="-footer '${asdoc.footer}'" />
<arg line="-exclude-sources ?????" />
</exec>
</target>
Thank you very much,
Regards,
Anthony
Use a fileset and a path convert :
<fileset dir="${src.dir}" id="src.files">
<include name="**/*.cpp"/>
</fileset>
<pathconvert pathsep="," property="excluded.src.files" refid="src.files"/>
Now property ${excluded.src.files} will have your files separated by a space, you can add your own separator etc. according to your program input argument. Then you just pass this with your -exlucde-sources arg to your program and that's it.

Invoking FindBugs from Ant: passing a space-separated list of files to java

I'm trying to invoke FindBugs from inside Ant. In order to control the amount of memory available to FindBugs, I've chosen not to use the ant-task. The problem I have now is that I want to pass a number of jars on the command-line to FindBugs:
java -jar .../findbugs.jar foo.jar bar.jar fie.jar
However, since these jars actually are Eclipse plugins, I don't know the exact name of the jars so I need a way to use a wildcard to obtain the list. This is what I've come up with:
<target name="findbugs">
<property name="findbugs.home" location="${user.home}/eclipse/findbugs" />
<path id="findbugs.input">
<fileset dir="${testDirectory}/eclipse/plugins">
<include name="my.plugins.*.jar" />
</fileset>
</path>
<path id="findbugs.auxinput">
<fileset dir="${testDirectory}/eclipse/plugins">
<include name="*.jar" />
<include name="**/*.jar" />
</fileset>
</path>
<java jar="${findbugs.home}/lib/findbugs.jar" fork="true">
<jvmarg value="-Xmx1048m" />
<arg value="-textui" />
<arg value="-output" />
<arg value="findbugs.xml" />
<arg value="-xml" />
<arg value="-exclude" />
<arg value="${basedir}/findbugsExclude.xml" />
<arg value="-auxclasspath" />
<arg pathref="findbugs.auxinput"/>
<arg pathref="findbugs.input" />
</java>
</target>
However, the findbugs.input pathref is a comma-separated list of jars, and not space-separated as FindBugs wants it. How do I get the list of jars as a space-separated list?
(Is this perhaps easier to do with the FindBugs ant-task. I can't really tell from the documentation.)
Use pathconvert, like this:
<pathconvert pathsep="," property="findbugs.input.csv" refid="findbugs.input"/>
Implementing in the target that you provided, I changed the reference from <arg pathref="findbugs.input" />
to <arg value="${findbugs.input.csv}" />
<target name="findbugs">
<property name="findbugs.home" location="${user.home}/eclipse/findbugs" />
<path id="findbugs.input">
<fileset dir="${testDirectory}/eclipse/plugins">
<include name="my.plugins.*.jar" />
</fileset>
</path>
<pathconvert pathsep="," property="findbugs.input.csv"
refid="findbugs.input"/>
<path id="findbugs.auxinput">
<fileset dir="${testDirectory}/eclipse/plugins">
<include name="*.jar" />
<include name="**/*.jar" />
</fileset>
</path>
<echo message="${findbugs.input.csv}" />
<java jar="${findbugs.home}/lib/findbugs.jar" fork="true">
<jvmarg value="-Xmx1048m" />
<arg value="-textui" />
<arg value="-output" />
<arg value="findbugs.xml" />
<arg value="-xml" />
<arg value="-exclude" />
<arg value="${basedir}/findbugsExclude.xml" />
<arg value="-auxclasspath" />
<arg pathref="findbugs.auxinput"/>
<arg value="${findbugs.input.csv}" />
</java>
</target>
Use <pathconvert> to convert the path into the proper format, storing it into a property then use <arg value...> instead of <arg pathref...>
You can control the memory from the ant task:
<findbugs jvmargs="-Xms512m -Xmx512m" ...>
...
</findbugs>

Resources