How do you compare strings in Ant? - string

In ant 1.6x the condition is never true despite app.get.method=download, why doesnt this work?
<target name="-get-method">
<condition property="do.download">
<equals arg1="${app.get.method}" arg2="download" />
</condition>
<echo message="${do.download}" />
</target>

Properties in ant are global and immutable.
You have probably already set the do.download property somewhere else.
Trying printing the value of do.download BEFORE the condition element it will probably already be "false".

Related

How to decrease Hybris build time in case the data model does not need an update?

Lets say that a task needs to be done and there are no data model changes needed(i.e items.xml does not need to be touched).
For example a new Interceptor is needed for an existing Item Type. In this case I just need a new spring bean and a new Java class.
After I do the changes, If I run an "ant build" it takes approximately 1:30(one minute and a half), sometimes even more than that.
From what I noticed Hybris tries to check every extension that is included in localExtension.xml with their required extensions as well, and that is taking a lot of time.
How can I perform a faster build ? It should not take that much time since the only thing that is needed in my Interceptor case is to compile the new Interceptor class, and that's it.
I understand that when data model is changed the models.jar needs to be deleted, the new sources need to be generated and compiled in a new models.jar and that requires time. But in the more simple scenario it should work a lot faster.
PS: I know about JRebel but this question addresses the cases in which the developer does not have JRebel.
In platform/build.xml add below ant target:
<target name="compileExtensions" description="Compiles only the provided extensions">
<compile_only_specified_extensions/>
</target>
In platform/resources/ant/compiling.xml add the macro definition:
<macrodef name="compile_only_specified_extensions">
<sequential>
<foreachextprovidedincli>
<do>
<if>
<not>
<isset property="ext.#{extname}.warextension" />
</not>
<then>
<extension_compile extname="#{extname}" />
</then>
<else>
<external_extension_build extname="#{extname}"/>
</else>
</if>
</do>
</foreachextprovidedincli>
</sequential>
</macrodef>
Define foreachextprovidedincli in platform/resources/ant/util.xml
<macrodef name="foreachextprovidedincli">
<element name="do" optional="false" />
<attribute name="param" default="extname" />
<sequential>
<for list="${extensions.to.compile}" param="#{param}" delimiter=";">
<sequential>
<do />
</sequential>
</for>
</sequential>
</macrodef>
Now what I simply have to do to compile my classes is run the following command:
ant compileExtensions -Dextensions.to.compile="extensionName1;extensionName2;extensionName3"
With above command the build was reduced to 4 seconds.

NLog layout variable evaluates blank

I am on NLog 4.3.5.
I have a long, complicated layout string that I want to save in a <variable /> for use in four layout attributes. Unfortunately, if I refer to the variable using
layout="${layout_full}"
then NLog complains that it cannot find that layout formatter (even though it isn't a layout formatter, it's a variable); and if I refer to the variable using
layout="${var:layout_full}"
then the layout evaluates to a blank string.
In other words, this:
<variable name="layout-full" value="
${longdate} [${level}] ${logger} ${all-event-properties}${newline}
${message}
${when:when='${exception}'!='':inner=
${newline}${exception}
${newline}${stacktrace}}
" />
<target name="stdout" xsi:type="Console" error="false" layout="a${var:layout-full}b" />
shows all log entries as "ab".
I have also tried putting all four targets into a SplitGroup and applying a layout to the group, but that's apparently unsupported.
Not sure if this is the case here, but the <variable> should be outside the <target> and <targets>

Getting intellisense to pick up intermediate cs file

I have an XSD file (a DTD) which I run the XSD tool on to produce a C# file. I have modified my csproj's msbuild file in the following two places:
Added a special type for the item group:
<ItemGroup>
<SchemaFiles Include="Data\DeepZoomSchema.xsd">
</SchemaFiles>
</ItemGroup>
And then at the bottom of the file:
<Target Name="BeforeBuild" Inputs="#(SchemaFiles)" Outputs="#(SchemaFiles->'$(IntermediateOutputPath)%(Filename).cs')">
<XSD Language="CS" GenerateFromSchema="classes" SuppressStartupBanner="false" Namespace="DZParallelLib.Data" Sources="#(SchemaFiles)" AdditionalOptions="/out:$(IntermediateOutputPath)" />
<ItemGroup>
<Compile Include="#(SchemaFiles->'$(IntermediateOutputPath)%(Filename).cs')">
</Compile>
</ItemGroup>
</Target>
First of all, this project now compiles just fine. So I guess I have the hard part done. However, intellisense is broken in the sense that it never parses the DeepZoomSchema.cs output file.
In my ideal world, from the VS2012 IDE, I would like the .cs file to be found and parsed. I have found a way to do this, which is the following:
<ItemGroup>
<SchemaFiles Include="Data\DeepZoomSchema.xsd">
</SchemaFiles>
</ItemGroup>
<ItemGroup>
<Compile Include="#(SchemaFiles->'$(IntermediateOutputPath)%(Filename).cs')">
<Visible>False</Visible>
</Compile>
</ItemGroup>
And then the build step becomes a lot more simple:
<UsingTask TaskName="XSD" AssemblyName="Microsoft.Build.CppTasks.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Target Name="BeforeBuild" Inputs="#(SchemaFiles)" Outputs="#(SchemaFiles->'$(IntermediateOutputPath)%(Filename).cs')">
<XSD Language="CS" GenerateFromSchema="classes" SuppressStartupBanner="false" Namespace="DZParallelLib.Data" Sources="#(SchemaFiles)" AdditionalOptions="/out:$(IntermediateOutputPath)" />
</Target>
Now things are correctly parsed by the IDE (and the solution still builds), but it feels wrong. When I've written MS build rules in the past (and I admit, I've not done very many) I've always put the intermediate output files inside the build rule (as I did earlier on). Also, it feels like I should be using the "DependentUpon" tag here, and making them visible, just not shown by default in the IDE (sort of like a code-behind file??). Basically, the first solution feels like it is the "proper" way, but the IDE doesn't like it.
So, my question: Is there a better way to get what I want done than this second solution I've described?

How to prevent self-referencing foreign key values in XSD schema?

My XML (simplified) is like this:
<Actions>
<Action Id="1">
</Action>
<Action Id="2">
<DoSomething>
<ActionRef ActionId="1" /> <!-- valid -->
</DoSomething>
</Action>
</Actions>
The ActionId attribute value references the Id attribute value of the Action element. I've already set up a foreign key constraint in the XSD, and it works correctly.
I want to prevent self-referencing values in the foreign field, like this:
<Actions>
<Action Id="1">
</Action>
<Action Id="2">
<DoSomething>
<ActionRef ActionId="2" /> <!-- invalid -->
</DoSomething>
</Action>
</Actions>
Of course, this can easily be done within the application that processes the XML, and I'll fall back on that if what I'm asking for isn't possible, but I'd much rather have this done automatically by the validation process.
I tried adding [not(#ActionId = ../#Id)] to the foreign key selector XPath query, but that isn't valid in that context (nor am I sure it's correct either). Other than that, I have no idea what else to try, and it doesn't look like many people on the internets even set up foreign key relationships in their XSDs, let alone prevent this kind of situation (I found nothing on this exact topic).
It cannot be done - the selector syntax for XSD constraints is very limited. Other alternatives may include Schematron, which should be reasonable to integrate assuming your runtime has access to an XSLT processor. The effort could pay off is you decide to add more validation rules separate from the code of the application that processes the XML.

Log4Net composite RollingFileAppender with static file extension

Does the current version of Log4net have a way to create a RollingFileAppender with composite rolling style where the rolled files always preserves the given extension (.log in my case)?
Example of the format I would like:
MyLog.log
MyLog.2011-04-10.1.log
MyLog.2011-04-10.2.log
MyLog.2011-04-10.3.log
I found this post which says that there is a "PreserveLogFileNameExtension" property, but that it's not included in the official binaries. Is this still the case?
If so: Can anyone explain why this property is still not an offical part of Log4Net? I am a bit sceptical to use a custom build, but maybe I should not be?
I am also curious to know why the default functionality does not preserve the file extension. I do not see why it would gain the user that all the log files have different extensions.
Edit: Got it working by doing this:
1: Downloading and building the log4net source code
2: Applying these patches: https://issues.apache.org/jira/browse/LOG4NET-64
3: Setting PreserveLogFileNameExtension to "true" in the config.
Have you tried these parameters?
<file value="log-files\MyLog" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyy-MM-dd'.log'" />
<param name="StaticLogFileName" value="false" />
It will preserve the extension, but will give you a date in every filename like this.
MyLog2011-05-16.log
MyLog2011-05-17.log
MyLog2011-05-18.log
MyLog2011-05-19.log
Maybe it is possible to combine this with the size rolling?
The situation is unchanged. There is no newer release of log4net. It is quite unclear to me when (if) there will be a new release...
I think you do not need to worry to much about using a custom build. Test your software, if it works it is good enough.
EDIT: There is a new release that should include LOG4NET-64. Of course you can still stick to your custom build.
I'm using this configuration:
<file value="" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd'.log'" />
<staticLogFileName value="false" />
To get filenames like:
20111101.log
20111102.log
20111103.log

Resources