How to store properties in a list in Ant? - ant

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"/>

Related

Eclipse PDE :: Test properties

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.

Why can JSF resource bundle var be used differently with f:loadBundle and faces-config

I have one property file linked both ways (using f:loadBundle and faces-config.xml) both with different var names. So it would look like the following:
datatypes.properties:
A=first
B=second
C=third
faces-config.xml:
<resource-bundle>
<base-name>datatypes</base-name>
<var>myProp</var>
</resource-bundle>
myPage.xhtml:
<f:loadBundle basename="datatypes" var="prop"/>
in myPage.xhtml I make a list of all the keys from the property file. What I can't seem to understand is that when I use #{prop} in the code below it works but when I replace it with #{myProp} the list no longer displays.
<h:form>
<h:selectManyListbox id="list">
<f:selectItems value="#{myProp}"></f:selectItems>
</h:selectManyListbox>
</h:form>
I figure this means the variables in both cases are not the same behind the scenes but I would appreciate it if someone could explain (or point me to an explaination) in what way they are different. I would ideally like to just use #{myProp} without having to pull the keys out in code and store them in a list.
Thanks.
Both <f:loadBundle> and <resource-bundle> are different ways to load properties with difference being in their access scopes. The latter has by the way the additional benefit that the bundle is also injectable in a managed bean by #ManagedProperty("#{myProp}")
Using <resource-bundle> in faces-config.xml creates a global resource bundle which can be accessed anywhere in your application. This is implemented through a java.util.ResourceBundle instance.
Using <f:loadBundle> in your view creates a view-specific resource bundle which is accessible only within that view. The tag handler implements this using an internal implementation of a Map. This is as specified in the VDL of the tag:
Load a resource bundle localized for the Locale of the current view,
and expose it as a java.util.Map in the request attributes of the
current request under the key specified by the value of the "var"
attribute of this tag.
Now since you're trying to use the values from datatypes.properties through <f:selectItems>, you'll get the said exception. This is because the value attribute for the tag should evaluate to a Collection or an array.
Value expression pointing at any Collection or array. The member
elements may be instances of SelectItem or any Java Object.
So in order to use the global bundle instance, you first have to convert the same into a List<SelectItem> inside your backing bean before using it.
NOTE: You can verify the above cases by setting a breakpoint in the initializeItems(Object) method in the com.sun.faces.renderkit.SelectItemsIterator class. This is, of course, assuming that you're using the Mojarra implementation.

How to read a property from an ant build file to a gradle build script?

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.

passing parameters to dependent ant target

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.

Multiple Tiles Definition Files OR Passing Parameters to tiles.xml at Runtime

Is there any way to define a new tiles definition file other than the tiles.xml file at runtime (say tiles2.xml) and use it? I want to create a tiles2.xml using Java when a action is called. Or, can I pass the filename.jsp as a parameter to tiles.xml during runtime?
Here is what I am trying to do.
There are 50 menus. When any of the menus is clicked, parameters regarding the menu name are passed through an action to a Java class. The class checks and finds which file to open. Now, either I can pass that value to tiles.xml or create a new tiles definition file.
Please help. Thanks

Resources