I am using spring-2.5 (cannot upgrade, product dependency) and I notice a strange behaviour of the Eclipse formatter when I am using the p-namespace notation and some value expression:
If I use the standard way (without p-namespace) like this:
<bean id="ldapConfig" class="org.mycompany.project.config.LDAPConfig">
<property name="ldapServer" value="${ldap.server}" />
<property name="ldapPort" value="${ldap.port}" />
<property name="ldapBindDn" value="${ldap.bindDn}" />
<property name="ldapPass" value="${ldap.password}" />
</bean>
and press the key combination: Ctrl-Shift-F the formatting (e.g indentation) works very well.
Now if I use the p-namespace notation like this:
<bean id="ldapConfig" class="org.mycompany.project.config.LDAPConfig">
<p:ldapServer="${ldap.server}" />
<p:ldapPort="${ldap.port}" />
<p:ldapBindDn="${ldap.bindDn}" />
<p:ldapPass="${ldap.password}"/>
</bean>
When I press the key combination: Ctrl-Shift-F the formatting (e.g indentation)
removed some part of the code
<bean id="ldapConfig" class="org.mycompany.project.config.LDAPConfig">
<p:ldapServer = ldap.server } />
<p:ldapPort = ldap.port } />
<p:ldapBindDn = ldap.bindDn } />
<p:ldapPass = ldap.password } />
</bean>
Is there any incompatibility between the value expressions ( ${variable} ) and the p-namespace, or it is just an Eclipse bug on the XML formatting part?
Bean definition of ldapConfig when using p-namespace is not correct. By using the p-namespace you can use attributes as part of the bean element that describe your property values, instead of using nested elements. More details can be found here.
Assuming you have declared namespace as xmlns:p="http://www.springframework.org/schema/p"
The correct way to use it is:
<bean id="ldapConfig" class="org.mycompany.project.config.LDAPConfig"
p:ldapServer="${ldap.server}"
p:ldapPort="${ldap.port}"
p:ldapBindDn="${ldap.bindDn}"
p:ldapPass="${ldap.password}">
</bean>
Now try CTRL-SHIFT-F
Related
In my NAnt script I have a property:
<property name="changed.assemblyinfo" value="false" unless="${property::exists('changed.assemblyinfo')}" />
The property can be set from the command line using the -D switch like below, which works fine:
-D:changed.assemblyinfo=true
However, I also want to be able to update the property from within the script itself depending on some logic in the script i.e:
<property name="changed.assemblyinfo" value="true" />
However, every time I do this I get the error:
Read-only property "changed.assemblyinfo" cannot be overwritten
How do I set a property from within the script?
When you pass a property in on the command line, it is treated as a readonly property. From the docs:
iii. Define a read-only property. This is just like passing in the param on the command line.
<property name="do_not_touch_ME" value="hammer" readonly="true" />
That means that you're unable to update it. In your case, if you both need to be able to supply it from the command line and update it depending on logic means that you'll need to supply a default value on the command line that uses a different name, eg:
<property name="changed.assemblyinfo.default" value="false" unless="${property::exists('changed.assemblyinfo.default')}" />
<property name="changed.assemblyinfo" value="${changed.assemblyinfo.default}" />
So now changed.assemblyinfo will contain either the default value of changed.assemblyinfo.default or the value passed in on the command line, while you're free to overwrite it as normal:
<property name="changed.assemblyinfo" value="true" />
At the moment I'm calling findstr and storing the output in a property to check afterwards - I'm sure there must be a better solution.
<exec program="findstr.exe"
workingdir="${workspaceDir}"
commandline='/i /c:"someText" ${fileName}'
failonerror="false"
output="${coverageExcludeLog}"
resultproperty="foundFile"
/>
Is this really the best way of doing this?
<loadfile file="${fileName}" property="MyFileContents" />
<property name="Mystring" value="someText" />
<property name="search.file" value="${string::contains(MyFileContents, Mystring)}" />
<if test="${bool::parse(search.file)}" > <!-- true or false-->
<echo message="Found the string ${Mystring} in the file ${fileName}" />
</if>
In my cspex I have action that creates product
<public name="create.product" actor="ant">
<actorProperties>
<property key="buildFile" value="build/product.ant" />
<property key="targets" value="create.product" />
</actorProperties>
<properties>
<property key="profile" value="iitProfile" />
<property key="iu" value="iit.product" />
</properties>
<prerequisites alias="repository">
<attribute name="site.p2" />
</prerequisites>
<products alias="destination" base="${buckminster.output}">
<path path="product.${target.ws}.${target.os}.${target.arch}/" />
</products>
</public>
When the final product is being build, folder created looks like this product.${target.ws}.${target.os}.${target.arch}. How can I append qualifier replacement that I set via qualifier.replacement property? I thought I could do something like product.${target.ws}.${target.os}.${target.arch}_{qualifier.replacement} where qualifier.replacement is the property that was set during execution of buckminster.versionQualifier.
I know when I execute action site.p2.zip qualifier replacement is being appended to the name of the file, so how can I use this in my other actions? Do I have execute buckminster.versionQualifier task myself?
thanks!
Opened enhancement about this on eclipse bugzilla: https://bugs.eclipse.org/bugs/show_bug.cgi?id=321753
I need to do a simple addition in NANT program like 1 + 1 =2. I am finding it difficult as every variable is taken as string by default in NANT. I have also tried using int::parse but it did not work.
Regards
Sarathy
Perhaps you can use convert::to-int. There's also an operator overview here.
I also found two examples that perhaps help to understand overall usage (example 1, example 2):
From example 1:
<if test=“${int::parse(UnitTestsResult) != 0}“>
<fail message=“Atleast one unit test failed!“/>
</if>
From example 2:
<target name="repeat">
<property name="var1" value="0" overwrite="false" />
<echo message="${var1}" />
<property name="var1" value="${convert::to-int(var1) + 1)" />
<call target="repeat" if="${convert::to-int(var1) < 10}" />
</target>
<property name="a" value="1"/>
<echo message="${int::parse(a) + 2}" />
Gives:
[echo] 3
Summary:
How do I expand a property with value "download\${bulidmode}\project\setup.msi" to "download\Debug\project\setup.msi" if the property buildmode contained debug so I can use it as the file="" part of < copy >
Detail:
I have a bit of a requirement to be able to expand properties within a string in nant.
For example I have a target that is copying file A to B. A and B both come from a simple two field CSV file which I'm iterating through using
<foreach item="Line" in="filelist.csv" delim="," property="source.file,target.file">
<property name="sourcefile" value="${path::combine(source.dir,source)}" />
<property name="targetfile" value="${path::combine(download.dir,destination)}" />
<echo message="Copy ${sourcefile} to ${targetfile}" />
<copy file="${sourcefile" tofile="${destination}" />
</foreach>
and the filelist.csv will be
build\manifest.xml
solutiondirectory\setup-proj-directory\Release\setupproj.msi,ProductA\ProductA.msi
solutiondirectory\another-proj-dir\Release\setupproj.msi,ProductB\ProductB.msi
(The reason we split these out is that we write multi-tiered applications and deploy by MSI to each tier - so one product has multiple msi's all built with the same version numbers)
Anyway - I want to change this to that I no longer have "Release" in the filelist.csv file but something like ${build.mode}. I would wrap the above code with a
<foreach item="String" in="Release,Debug" delim="," property="build.mode">
....as above
</foreach>
and the property embedded within the string in the file gets expanded.
I've been beating my head against a brick wall for a few hours, but just can't figure it out.
Thanks
It is possible with a custom function :
<?xml version="1.0"?>
<project>
<script language="C#" prefix="vbfox" >
<code>
<![CDATA[
[Function("expand")]
public string ExpandString(string str)
{
return Project.Properties.ExpandProperties(str, Location.UnknownLocation);
}
]]>
</code>
</script>
<property name="hello" value="{path::combine('_hello_', '_world_')}" />
<property name="hello" value="${'$' + hello}" />
<echo message="${hello}" />
<echo message="${vbfox::expand(hello)}" />
</project>