phing loadfile to property does not override previous value - phing

<loadfile property="test-from-file" file="value.txt" />
<echo message="test-from-file = ${test-from-file}" />
<loadfile property="test-from-file" file="value2.txt" />
<echo message="test-from-file = ${test-from-file}" />
The second loadfile does not change the value of the test-from-file property.
Is there any way to get this working?

As stated in comments by Jawi, properties are not overridden by design. A property works as a constant in Phing. So if it is already defined, then it won't be changed by later property definitions.
I think that you should revert your <property> task call in order to define your preferred sources first.
Alternatively, you can also use <property override="true"> to alter default behavior and override existing values, changing properties from constant to variable.

Related

GWT property with is-multi-valued already defined

While migrating from GWT 2.7.0 to 2.8.2 I came upon property:
<define-configuration-property name="CssResource.gssDefaultInUiBinder"
is-multi-valued="true" />
If this is left as it is, I get an error: The configuration property named CssResource.gssDefaultInUiBinder is already defined with a different 'is-multi-valued' setting.
Does that mean that I can't set attribute is-multi-valued to already defined property? Why would this work with GWT 2.7.0 then? Can anyone give me an explanation about this attribute? Because I am failing to find one...
Attribute set in GWT resources:
<!-- The default for GSS in UiBinder -->
<define-configuration-property name="CssResource.gssDefaultInUiBinder" is-multi-valued="false" />
gwt/user/src/com/google/gwt/resources/Resources.gwt.xml
Correct - you should not be trying to change is-multi-valued, it doesn't really make any sense. You can't re-define a property or configuration-property after it has been set, you can only set the value.
If you want to turn the gss-in-ui-binder flag on, use this:
<set-configuration-property name="CssResource.gssDefaultInUiBinder" value="true" />
If you want to turn it off, either do nothing, or do this:
<set-configuration-property name="CssResource.gssDefaultInUiBinder" value="false" />

SAPUI5 Smart Table - Smart Field make field mandatory with annotation

Is it possible to make a Property in SAPUI5 Smart Table mandatory so that a user can't leave a field empty while editing it?
I have found this document saying that it should be possible to set mandatory field control on Property in metadata.xml file with annotation like this:
<Property Name="NameLast" Type="Edm.String" Nullable="false" MaxLength="40" sap:label="Last name" sap:field-control="7" />
But with this setting I am getting following error in console:
2017-04-14 11:37:36.691429 MockServer: Resource not found for the segment '7'
2017-04-14 11:37:36.707985 The following problem occurred: HTTP request failed404,Not Found,{"error":{"code":404,"message":{"lang":"en","value":"Resource not found for the segment '7'"}}} -
EDIT:
Later I found out that sap:field-control should not contain number, but a path expression to another property which contains the number. However this also doesn't work:
<Property Name="NameLast" Type="Edm.String" Nullable="false" MaxLength="40" sap:label="Last name" sap:field-control="Name_fc" />
<Property Name="Name_fc" Type="Edm.Byte" />
Value of Name_fc property is '7'. I don't see any console error now, however I can still leave the input (NameLast) field empty without any validation and send it to OData service, which is not what I expect.
Here is a link to an example from sap where they use required fields. I have no idea though how they made it.
https://sapui5.netweaver.ondemand.com/sdk/explored.html#/sample/sap.ui.comp.sample.smartfield/code/SmartField.view.xml
For OData v2 the sap:field-control annotation on the Property can be
used to specify whether the field is mandatory.
<Property Name="Customer" ... sap:field-control="mandatory"/>
<Property Name="CompanyCode" ... sap:field-control="mandatory"/>
https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.ui.comp.smartfield.SmartField.html
The mandatory property of the entity has to be nullable="false". That's it.
Have a look at the smart field example from your link:
<Property Name="Name" Type="Edm.String" Nullable="false"
MaxLength="30" sap:label="Name" sap:creatable="false"
sap:quickinfo="Property annotation DataFieldWithUrl"
sap:updatable="true" sap:sortable="false" />
Btw. thanks for sharing your smart table example!
From my understanding there are 2 options:
1) Define a specific property as Mandatory --> Nullable="false"
2) Link a property to another property in the entity, the "field-control".
This field control can contain numbers and "7" means mandatory.
The linking from option 2 can be done in the MPC_EXT class (redefine the define method).
The actual value in the "field-control" property is set in the get_entity / get_en
However I am also having an issue with the smarttable. The mandatory fields do not light up red when empty.
Do it in brute force way in the Object Page extension controller.
var oField = this.getView().byId(<FieldId>)
oField.getDataProperty().property.nullable = "false" or "true".
"false" and "true" must be a string.
To convert a boolean to string use <boolean>.toString();

Mybatis Generator's bug: configuration items should be ordered?

If I put "<commentGenerator>" after "<jdbcConnection>", MBG proposed an error that context content should match: blablabla...
But when I put "<commentGenerator>" before "<jdbcConnection>", everything is ok. Here I have something to complain to the official website that if the order of these items is need, why you do not tell us! What an important thing! You r kidding the freshmen. Maybe it is some where I do not know, but this is a key point to build the MBG's configuration file successfully, why not put this NOTE on the top of the tutorial or somewhere eye-catching?
<generatorConfiguration >
<classPathEntry location="D:\mariadb-java-client-1.1.7.jar" />
<context id="db" >
<commentGenerator>
<property name="suppressAllComments" value="true" />
<property name="suppressDate" value="true" />
</commentGenerator>
<jdbcConnection driverClass="org.mariadb.jdbc.Driver"
connectionURL="jdbc:mariadb://localhost:3306/dbname"
userId="root"
password="password"
/>
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- Model Class -->
<javaModelGenerator targetPackage="org.infrastructure.model" targetProject="infrastructure\src\main\java">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- XML Files -->
<sqlMapGenerator targetPackage="sqlMap" targetProject="infrastructure\src\main\config">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- DAO -->
<javaClientGenerator type="XMLMAPPER" targetPackage="org.infrastructure.dao" targetProject="infrastructure\src\main\java">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- Tables -->
<table tableName="user" domainObjectName="User" ></table>
</context>
</generatorConfiguration>
First of all, in your xml configuration file, it doesn't contains a valid root element, which always should be like <!DOCTYPE .../>. About how to add a correct root element of mybatis generator configuration file, please see example from MyBatis GeneratorXML Configuration File Reference.
If you correctly specified root element such as following:
<!DOCTYPE generatorConfiguration PUBLIC
"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"
>
This root element contains a typical DTD declaration located at http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd. This is the definition of the order of these items is need. And we are going to see what it looks like.
From line 47 of this document type definition, it defines element named context. The content is as following:
<!--
The context element is used to describe a context for generating files, and the source tables.
-->
<!ELEMENT context (property*, plugin*, commentGenerator?, jdbcConnection, javaTypeResolver?,javaModelGenerator, sqlMapGenerator?, javaClientGenerator?, table+)>
Which obviously defined the order of the element in context, that is:
property*, plugin*, commentGenerator?, jdbcConnection,
javaTypeResolver?,javaModelGenerator, sqlMapGenerator?,
javaClientGenerator?, table+
In this element, all children must occurs as following rules:
+ for specifying that there must be one or more occurrences of the item — the effective content of each occurrence may be different;
* for specifying that any number (zero or more) of occurrences is allowed — the item is optional and the effective content of each occurrence may be different;
? for specifying that there must not be more than one occurrence — the item is optional;
If there is no quantifier, the specified item must occur exactly one time at the specified position in the content of the element.
After we understanding its real meaning, why you could not change the order of commentGenerator and jdbcConnection should be clear.
Maybe you want to know how to make the element out of order, question How to define DTD without strict element order could be useful.
Wish it helpful.

Is it possible to assign default values to NAnt properties?

I'd like to use the property value as a part of an argument passed to a certain EXE via <exec/> task. There's a condition which influences the property initialization, that is, if condition is true, it should contain value, otherwise be just empty (but still defined).
This is what I ended up so far:
<property name="prop1" value="" />
<property name="prop1" value="some-value-based-on-condition" if="condition-goes-here" />
And later on:
<exec program="my.exe">
<arg value="C:\Root\Folder\${prop1}" />
...
</exec>
If the property is not set, I'd like to pass just C:\Root\Folder\ as an argument value.
Initializing the property in this way seems too much for such a simple operation. Is there a way to do it simpler using what's in NAnt at the moment? I would imagine something like:
<property name="prop1" value="somevalue-based-on-condition" if="condition" default="" />
The example below should meet your needs. It will create a property named 'SolutionConfiguration' and assign it the value 'Release' if and only if the same parameter isn't already defined (ie. it was defined via the command line).
<property name="SolutionConfiguration" value="Release" unless="${property::exists('SolutionConfiguration')}" />
For your scenario, try
<property name="RootFolder" value="c:\Root\Folder" unless="${property::exists('RootFolder')}" />
<exec program="my.exe">
<arg value="${RootFolder}\${prop1}" />
...
</exec>
Use overwrite="False"
<property name="RootFolder" value="c:\Root\Folder" overwrite="false" />

Does Castle Windsor allow the resolution of value types?

I'm trying to pass a parameter into a component that requires a System.TimeSpan. I'm only able to get the 'long ticks' ctor to resolve.
Here's a snippet of the config file:
<component id="timeInForce" type="System.TimeSpan, mscorlib">
<parameters>
<hours>0</hours>
<minutes>15</minutes>
<seconds>0</seconds>
</parameters>
</component>
<component id="FooSettings" type="Foo.FooSettings, Foo">
<parameters>
<tif>${timeInForce}</tif>
</parameters>
</component>
This is the exception:
Castle.MicroKernel.Handlers.HandlerException : Cant create component 'timeInForce'
as it has dependencies to be satisfied.
timeInForce is waiting for the following dependencies:
Keys (components with specific keys)
- ticks which was not registered.
Passing a tick value for the component parameter works, as in:
<parameters><tif>0</tif></parameters>
but this defeats the purpose.
What's happening (from what I can see) is that the ticks property is being incorrectly identified as a compulsory parameter (because it belongs to the constructor with the least number of arguments) even though all value types have a default parameter-less constructor.
However the constructor candidate matching the most parameters will still be selected even if you supply additional parameters (i.e. ticks) so you can work around this by just including ticks in the list of parameters:
<component id="timeInForce"" type="System.TimeSpan, mscorlib">
<parameters>
<ticks>0</ticks>
<hours>0</hours>
<minutes>15</minutes>
<seconds>0</seconds>
</parameters>
</component>
Here is a quick test to verify it works (which passes for against the castle trunk):
string xml = #"<?xml version=""1.0"" encoding=""utf-8"" ?>
<castle>
<components>
<component id=""timeInForce"" type=""System.TimeSpan, mscorlib"">
<parameters>
<ticks>0</ticks>
<hours>0</hours>
<minutes>15</minutes>
<seconds>0</seconds>
</parameters>
</component>
</components>
</castle>";
WindsorContainer container = new WindsorContainer(
new XmlInterpreter(new StaticContentResource(xml)));
TimeSpan span = container.Resolve<TimeSpan>("timeInForce");
Assert.AreEqual(new TimeSpan(0, 15, 0), span);
However, what I would suggest rather then the approach your using is to implement your own type converter, as discussed in the castle documentation.
That way you could develop your own shorthand form for a timespan i.e. "15m" or "2h15m" or whatever takes your fancy - making your config a little easier to read and maintain and working round the issues you're currently experiencing.