why ant print time with a slash? - ant

I have this date format:
<entry key="buildDate" type="date" value="now" pattern="MM-dd-yyyy HH:mm:ss"/>
But ant gives me this result (in a key-value properties file):
buildDate=01-13-2012 14\:19\:59
Why ant add those slash in? because it is in a properties file?

Yes. The colons have special meaning in a Java properties file (they can act as key-value separators), so Ant needs to escape them with backslashes.

Ant doesn't add those \, it's Java.
See api docs for Properties, especially the store(Writer writer, String comments) method:
The key and element characters #, !, =, and : are written with a preceding backslash to ensure that they are properly loaded.

Related

How to retain backslash in apache ant replaceregexp task?

I have a property in application.properties as below
application.generalsettings.environmentname.blacklist=value_to_replace
And I have a task in build.xml as below
<replaceregexp file="application.properties" match="value_to_replace" replace="\"" byline="true"/>
However it giving me output like below:
application.generalsettings.environmentname.blacklist="
Instead of
application.generalsettings.environmentname.blacklist=\"
So is there any flag in replaceregexp to retain backslash as shown in above output ?
(I get XML parsing errors with your task as-is.)
I think this should work for you:
replace="\\\\""
At the moment your backslash is escaping the double quote after it.
You need to escape the backslash "twice", once so the XML can be parsed correctly, the second time so the substitution works, hence the 4 successive slashes above. " is the XML entity for a double quote.
I'm not sure why you XML parser is happy to parse "\"", seems very forgiving!

How do I specify tab(\t) as a separator for text in a Dataflow Template?

There are some Dataflow templates that support Column delimiter of the data files as an optional parameter (for instance, the template loading Text Files into Spanner), but I am unable to pass tabulator (i.e. \t) as a column delimiter. How do I do this?
There was a bug in the Dataflow UI that made it impossible to pass escaped characters to a Dataflow template.
Gladly, this is no longer the case. To specify tab as a delimiter, you can simply pass \\t, and the template will work as expected.
For passing any other parameter, note that you can escape any character. (e.g. \\n, \\t, etc).

karaf configuration property is garbled

I implement org.osgi.service.cm.ManagedService interface to get Karaf configuration. But when I give a Chinese value to the property, it is garbled.Initially, the files in the etc folder are encoded in latin1. I have tried to set utf-8 encoding, but it has no effect. Can anyone help me?
In Karaf, the configurations files (ie etc/*.cfg) are handled by the felix subproject "fileinstall".
fileinstall doesn't support yet to specified a custom character encoding for the configuration, it uses the Properties class and Properties.load(InputStream), which documents:
The load(Reader) / store(Writer, String) methods load and store
properties from and to a character based stream in a simple
line-oriented format specified below. The load(InputStream) /
store(OutputStream, String) methods work the same way as the
load(Reader)/store(Writer, String) pair, except the input/output
stream is encoded in ISO 8859-1 character encoding. Characters that
cannot be directly represented in this encoding can be written using
Unicode escapes as defined in section 3.3 of The Java™ Language
Specification; only a single 'u' character is allowed in an escape
sequence. The native2ascii tool can be used to convert property files
to and from other character encodings.
So, you have to encode your file in ISE-8859-1 and quote every UTF character, or use an xml file to encode your configuration files.
There is a way to change cfg files encoding.
Configuration for fileinstall subproject polling etc/*.cfg files is written in config.properties file.
You can add
felix.fileinstall.configEncoding = UTF-8
The solution was checked in Karaf 4

Ant propertyregex, replace only the last occurrence?

Let's say I have a package abc.bcd.html.efg.Hello.html, I want to tear down the .html extension without changing the package. How do I do it?
You should be able to do this with a regex like
(.*)\.html$
(the dollar matching the end of the input string). This would correspond to
<propertyregex property="some.property" input="abc.bcd.html.efg.Hello.html"
regex="(.*)\.html$$" select="\1" />
using a double dollar to "escape" the single dollar sign from being treated as part of a property expansion by ant - see "$$ Expansion" on this page.

property file path changed during ant build

<propertyfile file="${build.dir}/MyProperties.properties">
<entry key="releaseInformation"
type="string"
value="${build.time}"/>
</propertyfile>
When Ant copies my properties file over to the bin directory there is a property in it that has something like "samplePathName=C\:\Users\SomeUser\". But the property from the original file was "samplePathName=C:\Users\SomeUser\". How would the additional backslash end up there? I don't see anything that could possibly cause this to happen. Where should I begin looking other than the build.xml which only contains (relevant) the above line?
This is a common problem - the format of property files is defined by Sun (Oracle). Ant is conforming to this, which is why the escaping happens. There's no way round this using the propertyfile task - that's the way it's intended to work. If the file is genuinely a Java property file, then it shouldn't matter - the escaping should be handled correctly when the file is read.
However if you are hoping to use propertyfile to write a name-value config file that's for something else - where the escaping is not wanted - you'll need to adopt a different approach. As mentioned in the answer to a related question - you might use the Ant replace or replaceregexp tasks for this.

Resources