How to apply pack200 using build file? - ant

How to apply pack200 using build file?
Please specify your answer where I am missing.
This is my code:
<target name="pack200">
<apply executable="pack200" parallel="false" dest="${build.dir}">
<arg value="--modification-time=latest"/>
<arg value="--deflate-hint=true"/>
<arg value="--segment-limit=-1"/>
<targetfile/>
<srcfile/>
<fileset dir="${build.dir}" includes="*/.jar" />
<mapper type="glob" from="D:/*" to="D:/*.pack.gz" />
</apply>
</target>

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.

Ant: How to use apply task with identical source and target file

I am trying to run an apply task with the following command:
jpegtran.exe -copy none -optimize -perfect ./images/file.jpg ./images/file.jpg
I would like to apply it recursively for all images. I have tried the following ant code but jpegtran says invalid arguments.
<target name="optimize.images.jpg">
<apply executable="jpegtran.exe" dir="${SRC_DIR}/public/assets/" parallel="false" verbose="true" resolveexecutable="true" force="true" vmlauncher="true">
<arg value="-copy none"/>
<arg value="-optimize"/>
<arg value="-perfect"/>
<srcfile/>
<targetfile/>
<fileset dir="${SRC_DIR}/public/assets/images" casesensitive="yes">
<include name="**/*.jpg"/>
</fileset>
<mapper type="identity"/>
</apply>
</target>
What could be wrong with my ant code?
One item that needs to be changed is the nested <arg> element for -copy none. Since there is a space in the argument, use the line attribute instead of value. See Apache Ant command line arguments.
<target name="optimize.images.jpg">
<apply executable="jpegtran.exe" dir="${SRC_DIR}/public/assets/"
parallel="false" verbose="true" resolveexecutable="true" force="true"
vmlauncher="true">
<arg line="-copy none"/>
<arg value="-optimize"/>
<arg value="-perfect"/>
<srcfile/>
<targetfile/>
<fileset dir="${SRC_DIR}/public/assets/images" casesensitive="yes">
<include name="**/*.jpg"/>
</fileset>
<mapper type="identity"/>
</apply>
</target>

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