I have an ant build script that is modifying a properties file. When it amends the properties with the new paths, it seems to escape the back slashes and colons. I understand this is probably working as intended but batch files use this property file further down the process and it is causing errors.
Is there an ant solution to this, or should I start looking at a shell script workaround?
Thanks,
BON
Ant target:
<target name="modify_workstation_properties" depends="loadWinEnvVars, loadUnixEnvVars">
<propertyfile file="${basedir}/Deliverables/config/framework_setup/workstation.properties">
<entry key="toplevel.project.dir" value="${basedir}"/>
<entry key="root.project.dir" value="${basedir}/Construction"/>
<entry key="root.dir" value="${basedir}/Framework/Construction/netc_os"/>
<entry key="jdk.home" value="${JDKHome}"/>
<entry key="wls.home" value="${WLSHome}"/>
<entry key="domain.dir" value="${DomainDir}"/>
<entry key="stage.dir" value="${DomainDir}"/>
</propertyfile>
</target>
Output:
# Top Level Root directory of the new working project
toplevel.project.dir=C\:\\forImage\\r16_dev_deploy
# Root directory of the new working project
root.project.dir=C\:\\forImage\\r16_dev_deploy/Construction
# Root directory of the framework project
root.dir=C\:\\forImage\\r16_dev_deploy/Framework/Construction/netc_os
...
No you can't modify the way that the properties are written. However after the file is written you could use the ReplaceRegExp task and correct the escaped characters.
Related
On the last few weeks I've been working on a JavaFX Application to deploy for both Unix and Windows. At the moment, I'm trying to customize the install scripts/ config files.
On MacOS I simply included the script to the class path using <property> on my ANT build file like this:
<property name="classpath" location="package/macosx/App-dmg-setup.scpt"/>
But when I try to do the same on Windows, doesn't work (continues using the default config file). I've already tried absolute path, env.CLASSPATH instead of classpath, and some other alternatives, with no success.
Thanks a lot ;)
Cheers!
Ok sorry this question, actually I was inadvertently changing the basedir variable. The correct definition should only be:
<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar"/>
<file name="${java.home}\lib\jfxrt.jar"/>
<file name="${basedir}"/>
</filelist>
</path>
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpathref="fxant"/>
Without another (re)definition.
Once again, thanks!
I have a build.xml file in my ant project and I'm trying to set a build number with properties. I have the following fields in a file called version.properties:
build.major.number
build.minor.number
build.revision.number
build.number
and my build.number format is:
${build.major.number}.${build.minor.number}.${build.revision.number}
and I am currently updating the number
of the revision with propertyfile operation="+" when running my "dist" target. Now everything is working quite fine, except that the build number is always taken from the previous build eg revision.number = 5, build number = 1.1.4.
I have gotten it to work with making 2 targets and dependency for updating the version.properties file with firstly updating the revision number and then in the next target updating the build.number file.
It seems that the operation="+" is executed after every value assignment in a target so I can get the updated value with creating a new target, but it seems sloppy and I would like to be able to do it in only 1 target.
If the 2-target option is as clean as you can get without any JS scripts or any extra packages then okay, I just need to know if it is like that.
Original version.properties
build.major.number=1
build.minor.number=1
build.revision.number=4
build.number=1.1.4
build.xml
<project name="ant-propertyfile-task" default="run" basedir=".">
<target name="run">
<propertyfile file="version.properties">
<entry key="build.revision.number" type="int" operation="+" value="1"/>
</propertyfile>
<loadproperties srcFile="version.properties"/>
<property
name="new.build.number"
value="${build.major.number}.${build.minor.number}.${build.revision.number}"
/>
<propertyfile file="version.properties">
<entry key="build.number" value="${new.build.number}"/>
</propertyfile>
</target>
</project>
Updated version.properties
build.major.number=1
build.minor.number=1
build.revision.number=5
build.number=1.1.5
I am trying to retrieve the list of all zip files present in a directory.
I have a directory ${src} which contains some zip files and I am using the following code
<target name="test">
<dirset id="dist.contents" dir="${src}" includes="*.zip"/>
<property name="prop.dist.contents" refid="dist.contents"/>
<echo message="${prop.dist.contents}" />
</target>
but it only echoes null.
I also tried includes="*" but it didn't make any difference.
I am using Ant version 1.7.0.
As written in the documentation:
A DirSet is a group of directories.
So since you want zip files, you should use a FileSet.
i have a variable abc and had the value this is ant script. This abc variable will keep on changing.
Using ANT script, how can i write the value out to the file?
The echo task in ANT is able to write to files
<echo file="output.txt" append="true">
abc=${abc}
</echo>
Use propertyfile task. An example taken from ant manual:
<propertyfile file="my.properties">
<entry key="abc" value="${abc}"/>
</propertyfile>
This may be better than echo as it updates the properties file with a given value, while echo appends to or overwrites the whole file.
I have a number of file/executable locations that are likely to be different depending on which computer I am running them on, and I would like to abstract these out through ant properties somehow. What's the best way to do this? Is there a system-wide ant setup script that gets called? Or can I make such a script?
In addition to Vladimir's solution you might have a default properties file for each of the OS or other you might deploy your build system on. Use the ${os.name} (and other Java system properties) to set up a path. For example
<property file="build-${os.name}.properties">
These files can be maintained and checked in into your version control system as well.
I use the more or less standard build.properties and build-local.properties files.
The first contains default values, common to all environments, the second only the exceptions. The first one is checked into subversion while the other is not.
EDIT : copy/pasting Akr's excellent idea
In addition you might have a default properties file for each of the OS or other you might deploy your build system on. These files can be checked in into your version control system as well.
The Ant script would then include all the files as follow (remember: in Ant the first definition wins):
<property file="build-local.properties"/>
<property file="build.properties"/>
<property file="build-${os.name}.properties">
Setup an ant build file called properties.xml, in which you should define the properties that you want to customize.
Here is properties.xml boilerplate I am using for my projects ( I've adapted it from one of the books on Ant ):
<?xml version="1.0" encoding="UTF-8"?>
<project
name="workspace-properties"
>
<dirname
property="workspace-properties.basedir"
file="${ant.file.workspace-properties}"
/>
<!--
==========================================================
Load Environment Variables
==========================================================
-->
<!-- #Load environment variables -->
<property environment="env" />
<!-- this is here to deal with the fact that an IntelliJ IDEA build
has no ant home
-->
<property
name="ant.home"
value="${env.ANT_HOME}"
/>
<!-- get Unix hostname, and set to Windows comparable name -->
<!-- #Trick to get host name x-platform -->
<property
name="env.COMPUTERNAME"
value="${env.HOSTNAME}"
/>
<!--
==========================================================
Load property files
Note: the ordering is VERY important.
==========================================================
-->
<!-- #Allow even users property file to relocate -->
<property
name="user.properties.file"
location="${user.home}/.build.properties"
/>
<!-- Load the application specific settings -->
<!-- #Project specific props -->
<property file="build.properties" />
<!--
==========================================================
Define your custom properties here.
You can overwrite them through build.properties and
${user.home}/.build.properties
==========================================================
-->
<property name="myexec1" location="/usr/bin/myexec1"/>
<property name="myexec2" location="/usr/bin/myexec2"/>
</project>
Important thing here is to come up with as many useful default property values as possible, then you may even never come up with custom build.properties files.
Then you just <import> this file in your project's build.xml.
<project
name="my-project"
>
<!-- this is done, so you may import my-project somewhere else -->
<dirname
property="my-project.basedir"
file="${ant.file.my-project}"
/>
<import file="${my-project.basedir}/relative/path/to/properties.xml"/>
<target name="using.myexec1">
<echo message="myexec1=${myexec1}"/>
</target>
</project>
If you want a custom value for myexec1 in my-project, just drop a custom flat build.properties file in the same directory where build.xml is located.
The build.properties file may look like this:
myexec1=c:/custom/path/to/myexec1.exe