i want to create an ANT Task that permit to execute bower update in my project.
I've written this target:
<target name="update-static-web-dependecy" description="Update static web dependency">
<exec dir="${static-web.dir}" executable="/usr/local/bin/bower">
<arg value="update"/>
</exec>
</target>
But when i'm going to run it i get this error :
env: node: No such file or directory
Result: 127
In my OS Bower is installed correctly with the arg -g and if i launch it from the shell it works well.
Can someone help me?
Regards,
Lorenzo
I'll take a guess that you could resolve by specifying the path to node in an env element in your exec block. Something like this
<property name="node.dir" value="/usr/local/bin"/>
<exec dir="${static-web.dir}" executable="/usr/local/bin/bower">
<env key="PATH" value="${env.PATH}:${node.dir}"/>
<arg value="update"/>
</exec>
For anyone wanting to do this in Phing, it's a little bit less involved, but the Ant answer might throw you. You can do it all in one go if you know where bower is:
<exec command="/usr/bin/bower install" dir="${dirs.httpdocs}" />
If you're doing something generic, you can check for the existence of bower.json first:
<!-- bower exists -->
<property name="bowerExists" value="false" />
<exec command="if [ -f '${dirs.httpdocs}/bower.json' ]; then echo 'true'; else echo 'false'; fi;"
outputProperty="bowerExists" />
<if>
<equals arg1="${bowerExists}" arg2="true" />
<then>
<echo>Installing Bower Packages</echo>
<exec command="/usr/bin/bower install" dir="${dirs.httpdocs}" />
</then>
</if>
Source: http://www.szabogabor.net/how-to-check-in-phing-if-a-file-or-directory-exists/
Related
I am trying to add autoprefix-cli to my ANT build. Below is my code.
<target name="auto">
<apply executable="autoprefixer-cli.bat" verbose="true" force="true" failonerror="true">
<arg value="-d" /> <!-- Turn on verbose -->
<arg value="prefix" />
<arg value="*.css" />
</apply>
</target>
When i do a ant build, it gives me an error saying resource not specified.
BUILD FAILED
D:\tempTest\AntTestProject\build.xml:25: no resources specified
Note: I can access autoprefix-cli from command line, its installed with -g flag and also it works when i directly use it from commandline.
The apply task basically loops the exec task on a batch of resources (files, directories, URLs, etc). If you only want to run one command, use exec instead.
However, you will likely also need to alter your command. From Ant's exec task documentation:
Note that .bat files cannot in general by executed directly. One
normally needs to execute the command shell executable cmd using the
/c switch.
https://ant.apache.org/manual/Tasks/exec.html
So instead you should have:
<exec executable="cmd" verbose="true" force="true" failonerror="true">
<arg value="/c" />
<arg value="autoprefixer-cli.bat" />
<arg value="-d" />
<arg value="prefix" />
<arg value="*.css" />
</exec>
Im trying to invoke a bash scrip from an ant target. This is my target :
<target name="report" depends="test">
<!-- Step 3: Create coverage report -->
<exec executable="./checkStyle.sh"
failonerror="true"
osfamily="unix"/>
<jacoco:report>
<!-- This task needs the collected execution data and ... -->
<executiondata>
<file file="${result.exec.file}" />
</executiondata>
<!-- the class files and optional source files ... -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${result.classes.dir}" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}" />
</sourcefiles>
</structure>
<!-- to produce reports in different formats. -->
<html destdir="${result.report.dir}" />
<csv destfile="${result.report.dir}/report.csv" />
<xml destfile="${result.report.dir}/report.xml" />
</jacoco:report>
</target>
And my bash script is :
#!/bin/bash
DEST_FOLDER='./target/checkstyle'
CLASSES_FILE='classes.txt'
REPORT_FILE='report.xml'
mkdir -p "$DEST_FOLDER"
rm -f "$DEST_FOLDER/$CLASSES_FILE"
rm -f "$DEST_FOLDER/$REPORT_FILE"
find ./project -name "*.java" >> "$DEST_FOLDER/$CLASSES_FILE"
while read p; do
java -jar ./utilJars/checkstyle-6.5-all.jar -c ./sun_checks.xml -f xml $p >> "$DEST_FOLDER/$REPORT_FILE"
done < $DEST_FOLDER/$CLASSES_FILE
When typing ./checkStyle everything works fine, but when I try "ant report" the following error is raised:
BUILD FAILED
/home/luci/workspace/operations/build.xml:60: exec returned: 3
Total time: 4 seconds
I`ve searched on google and that code seems to be "permision denied", but i dont know how i could solve this problem.
Generally with Ant (and Java), you cannot directly execute shell scripts. You need to execute the interpreter/shell and give the script as an argument.
For example:
<exec executable="/bin/bash" failonerror="true" osfamily="unix">
<arg value="-c"/>
<arg value="./checkStyle.sh"/>
</exec>
Is there a way use the svn ant task to get the svn revision number of a working copy and put it into a variable?
I would like to add an entry in my Java manifest file which includes the svn revision number, e.g. 0.9.65361 where 65361 is the revision number.
Aha, I found this idea, which depends only on the svnversion command-line utility in SVN.
<project name="ant-exec-example" default="svnversion" basedir=".">
<target name="svnversion">
<exec executable="svnversion" outputproperty="svnversion" />
<echo message="SVN Version: ${svnversion}"/>
</target>
</project>
Here's where it captures the version in an ant property:
<exec executable="svnversion" outputproperty="svnversion" />
There are a couple of ways -
Use a utility - I believe you are looking for this - https://code.google.com/p/svntask/ I have used it for some side
projects and it works well.
Use commandline utility. - "svn info http://svn.myweb.com/myproject". To use this method simply create a
batch file and put this command in the batch file. Then call this
batch file from your ant task and get the revision number from the
text by searching for that starts with line "Revision:". Or you can
just dump the whole result.
Here is my variant to bundle svn revisions info within the application artifact:
<target name="svn_revisions">
<hostinfo prefix="HOST"/>
<echo file="${dir.out}/.revisions" message="Built by ${user.name} on ${HOST.NAME}${line.separator}"/>
<exec dir="${basedir}" executable="svn" output="${dir.out}/.revisions" append="true">
<arg line="info"/>
</exec>
<exec dir="${basedir}" executable="svn" output="${dir.out}/.revisions" append="true">
<arg line="status -u"/>
</exec>
</target>
<target name="build-war" depends="compile, svn_revisions">
<war basedir="web" file="${dir.out}/ROOT.war" webxml="web/WEB-INF/web.xml">
<!-- main stuff -->
<zipfileset dir="${dir.out}" prefix="META-INF" includes=".revisions"/>
</war>
</target>
I have build.xml which calls swfbuild.xml. I want parent build.xml to use IBM JDK 1.5 and swfbuild.xml to use Sun JDK 1.6
Is there any option in <ant> task to specify different JDK to use?
I tried setting JAVACMD like below but that doesn't work either
How can I use different JDK for swfbuild.xml?
<target name="Compile_SWF">
<exec executable="cmd">
<env key="JAVACMD" value="C:/Program Files/Java/jdk1.6.0_18" />
</exec>
<echo message="Start to Compile SWF content" />
<ant antfile="swfbuild.xml" target="swf-masterbuild" />
<exec executable="cmd">
<env key="JAVACMD" value="C:/IBM/SDP/runtimes/base_v61/java" />
</exec>
</target>
In each xml file, you can specify the executable to use inside the javac task. You must include the fork=yes in addition to the executable= parameter.
<javac fork="yes" executable="C:/Program Files/Java/jdk1.7.0_17/bin/javac">
I am trying to add some tag information in my ant script using the following target but I get an error (Result=-1) and hg tells me it does not recognise the command:
<target name="-post-init">
<exec outputproperty="hg.tag" executable="hg">
<arg value="parents --template {latesttag}+{latesttagdistance}" />
</exec>
</target>
If I only include value="parents" it works fine.
If I run the command line hg parents --template {latesttag}+{latesttagdistance} it works fine too.
Any ideas on what is wrong in my syntax?
Just tried this and it works fine:
<exec outputproperty="hg.tag" executable="hg">
<arg value="parents" />
<arg value="--template" />
<arg value="{latesttag}+{latesttagdistance}" />
</exec>
I needed to split the arguments.