i have two ant files
mainBuild.xml
subBuild.xml
subBuild.xml is imported in the mainBuild.xml. One of target from mainBuild depends on subBuild. I need to pass the argument to the dependent ant target. I dont want to use the <antcall> or the <ant> tags, as i need the some properties from the
You can define the arguments in the property files, and then read that property in ant like this.
<property file="build.start.properties"/>
All properties in the property file will be imported in ant, and will be available as ant properties, which you can use in both mainBuild.xml and subBuild.xml.
refer this for further reference
Macros are one way to have re-usable code in ant. You can call them with different argument. Re-using of targets (using property ) may not be desirable as the properties are immutable.
Related
The plug-in org.eclipse.ui.navigator.resources declares a commonFilter element with the id org.eclipse.ui.navigator.resources.filters.startsWithDot to extend org.eclipse.ui.navigator.navigatorContent:
<commonFilter
id="org.eclipse.ui.navigator.resources.filters.startsWithDot"
name="%filters.startsWithDot.name"
description="%filters.startsWithDot.description"
activeByDefault="true"
>
<filterExpression>
<and>
<adapt type="org.eclipse.core.resources.IResource">
<test property="org.eclipse.core.resources.name" value=".*"/>
</adapt>
</and>
</filterExpression>
</commonFilter>
The element <test> has the property org.eclipse.core.resources.name. I browsed the view Plug-in Registry to find out what this property means (and why it's not simply named name) but all I could find are further property assignments.
Can someone explain me what org.eclipse.core.resources.name means, why it's not enough to just use name as a property, and which class actually processes this value?
The value specified in the test property attribute is a value defined using the org.eclipse.core.expressions.propertyTesters extension point.
In this particular case the declaration is in the org.eclipse.core.resources plugin:
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
id="org.eclipse.core.resources.resourcePropertyTester"
class="org.eclipse.core.internal.propertytester.ResourcePropertyTester"
namespace="org.eclipse.core.resources"
properties="name,path,extension,readOnly,projectNature,persistentProperty,projectPersistentProperty,sessionProperty,projectSessionProperty"
type="org.eclipse.core.resources.IResource"/>
which defines a number of tests include the name test.
When you reference a property tester you must always specify the full name including the namespace - so it must be org.eclipse.core.resources.name and not just name, org.eclipse.core.resources is the namespace declared in the extension point. This is because there may be multiple property testers defined for name but each tester has a unique namespace so the full name is also unique.
org.eclipse.core.resources.name tests the resource name against a pattern. Any name starting with . in this case.
I am looking for a possibly clean and concise way of extracting a property from ant's build.xml file.
I know I could use ant.importBuild 'build.xml' but this would import all the targets, possibly causing name clashes e.g. with the java plugin, which is a known issue.
I am using gradle 1.6.
One way is to manually parse the XML file, for example using Groovy's XmlSlurper class. However, this won't replace any property references occurring in the property value. Another way is to configure an org.apache.tools.ant.Project object (similar to how ant.importBuild does it), and get the property value from there. Something like:
import org.apache.tools.ant.Project
import org.apache.tools.ant.ProjectHelper
task printPropertyValue {
doLast {
def antProject = new Project()
ProjectHelper.configureProject(antProject, file("build.xml"))
def value = antProject.getProperty("some.property")
while (value.contains('${')) {
value = antProject.replaceProperties(value)
}
println value
}
}
There may be a better way to recursively replace property references, but I couldn't find one.
Another potential solution is to use an external properties file that's read both by Ant and Gradle.
can i change the value of parameter in called target and then retrieve it in the calling target in ant.Probably By refid if there is any other way that is appreciated.
Normally you cannot modify an ant property in ant once it's set, but as oers pointed out in a comment, you can use the Variable task in ant-contrib. You can even override an existing property with a Variable. According to the documentation, you should still use properties in most cases, and only use variables in the cases where you really need to be able to modify a value.
Another workaround is to set additional properties and call the other targets using those properties.
Generally speaking, any ant task which accepts a <mapper> will also accept several tags designating particular mappers: <identitymapper>, <regexmapper>, etc.
But if you're writing your own task, you are supposed to supply a method for each possible tag that may exist inside your task. You don't want to add separate addConfiguredMapper(), addConfiguredIdentityMapper(), addConfiguredRegexMapper(), etc. methods. How do you easily set up a custom ant Task to take any arbitrary Mapper, specified by either the general <mapper> tag or the tag for each particular instance?
These are the two methods you will need to supply:
public Mapper createMapper() throws BuildException;
public void add(FileNameMapper fileNameMapper);
Take a look at the Copy task in the ant source distribution to see how these are implemented.
I would like to store the properties I read from a Java type property file in a list. Is there any way I can do that in Ant?
Properties are maps rather than lists. You can read in a set of properties from a file using the property task.
For example:
<property file="${dir}/external.properties"/>
This property file has the format as defined by the file used in the class java.util.Properties, with the same rules about how non-ISO8859-1 characters must be escaped.
When the property file is read it allows for properties in the file to be expanded. Once the file has been read, they are accessed as normal. So if external.properties contains:
test.dir=/usr/test
test.file=foo
test.target=${test.dir}/${test.file}/
You could reference test.target directly in your task:
<!-- Will create the directory structure /usr/test/foo -->
<mkdir dir="${test.target}"/>
See Property.
<property file="foo.properties"/>