xmltask error encoding - ant

I´m trying to get the value of node in the xml file. I observed that value is wrong. I´m belive that problem is the encoding. Someaone can help me ? below is my code:
In xml File:
<?xml version="1.0" encoding="UTF-8" ?>
<projects>
<project>
<application>Padrão</application> <!-- The problem is the character ~ -->
<name>padrao</name>
<icon>c:\buffer</icon>
<market>br.com.tls.test</market>
</project>
</projects>
My ant code
<xmltask source="config.xml" encoding="UTF-8">
<call path="//project">
<param name="name" path="name/text()" />
<param name="market" path="market/text()" />
<param name="icon" path="icon/text()" />
<param name="application" path="application/text()" />
<actions>
<echo message="#{application}" />
<init-release name="#{name}" market="#{market}" icon="#{icon}" application="#{application}"/>
</actions>
</call>
</xmltask>
Result
[echo]: padr#o
expected
[echo]: padrão
Solution
I changing the file to UTF-8 and I´d sucess in the replace.

I haven't used xmltask, but echo task also has encoding property, have you tried setting that as well?
e.g. <echo message="#{application}" encoding="UTF-8" />

Related

log4j2 appender talking to sql server database

This URL
https://logging.apache.org/log4j/log4j-2.0/manual/appenders.html
has this example:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="error">
<Appenders>
<JDBC name="databaseAppender" tableName="dbo.application_log">
<DataSource jndiName="java:/comp/env/jdbc/LoggingDataSource" />
<Column name="eventDate" isEventTimestamp="true" />
<Column name="level" pattern="%level" />
<Column name="logger" pattern="%logger" />
<Column name="message" pattern="%message" />
<Column name="exception" pattern="%ex{full}" />
</JDBC>
</Appenders>
<Loggers>
<Root level="warn">
<AppenderRef ref="databaseAppender"/>
</Root>
</Loggers>
</Configuration>
When I try to wire up to a sqlserver database......
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<JDBC name="SQLServerAppender" tableName="dbo.LogEntry">
<DataSource jndiName="jdbc:sqlserver://MyMachine\\MyInstance:1433;databaseName=LoggingDB;applicationName=myappname;integratedSecurity=true;" />
<Column name="EntryDateUtc" isEventTimestamp="true" />
<Column name="LOGGER" pattern="%C" />
<Column name="Level" pattern="%level" />
<Column name="Message" pattern="%m" />
<Column name="UserName" pattern="%x" />
<Column name="Priority" pattern="%p" />
<Column name="ElapsedMilliseconds" pattern="%r" />
<Column name="ThreadName" pattern="%t" />
<Column name="ThrowableMessage" pattern="%throwable " />
</JDBC>
I get errors like:
ERROR No ConnectionSource provided: connectionSource
ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.db.jdbc.JdbcAppender for element JDBC org.apache.logging.log4j.core.config.ConfigurationException: Arguments given for element JDBC are invalid: field 'connectionSource' has invalid value 'null'
How do I set up a connection string in the xml-configuration to talk to sqlserver?
Even though it doesn't match the documentation, I tried this:
<Appenders>
<JDBC name="SQLServerAppender" tableName="dbo.LogEntry">
<ConnectionSource jndiName="jdbc:sqlserver
It didn't work of course.
What is the magic syntax sugar?? #help
Thanks.
The value of DataSource jndiName is not a SQL Server connection string. If you want to use a SQL Server connection string then put in Log4J configuration put something like:
<appender name="SQLServer" class="org.apache.log4j.jdbc.JDBCAppender">
<param name="url" value="jdbc:sqlserver://MyMachine\\MyInstance:1433;databaseName=LoggingDB;applicationName=myappname;"/>
<param name="driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<param name="user" value="user_id"/>
<param name="password" value="password"/>
<param name="sql" value="INSERT INTO LOG4J_TABLE VALUES('%x','%d','%C','%p','%m')"/>
<layout class="org.apache.log4j.PatternLayout"></layout>
</appender>
<logger name="log4j.rootLogger" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="SQLServer"/>
</logger>
Which will write to a table that you must have created previously like:
CREATE TABLE LOG4J_TABLE (
User_Id VARCHAR(20) NOT NULL,
Date_Stamp DATETIME NOT NULL,
Logger VARCHAR(100) NOT NULL,
Level VARCHAR(10) NOT NULL,
Message VARCHAR(8000) NOT NULL
)
Note that you can´t use integratedSecurity=true straightforward from Java but must specify the user + password.
I think the problem is that JNDI is not enabled.
This is my configuration log4j2.xml:
<bean id="dataSourceProxy" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
<constructor-arg ref="dataSource"/>
</bean>
<bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSourceProxy"/>
</bean>
<bean id="jdbcTemplate" class="xx.com.xxxxx.framework.database.xxxxxJDBCTemplate">
<constructor-arg ref="dataSourceProxy"/>
</bean>
<bean id="DBSession" class="xx.com.xxxxx.framework.database.DBConnectionManager" lazy-init="true">
<constructor-arg type="java.lang.String" value="DBSession"/>
<constructor-arg ref="dataSourceProxy"/>
<constructor-arg ref="transactionManager"/>
<property name="template" ref="jdbcTemplate"/>
</bean>
It worked normally before we had upgraded log4j to log4j2. After upgrading, there was an error output from my weblogic console:
ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.db.jdbc.JdbcAppender for element JDBC org.apache.logging.log4j.core.config.ConfigurationException: Arguments given for element JDBC are invalid: field 'connectionSource' has invalid value 'null'
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.injectFields(PluginBuilder.java:210)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:121)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1120)
....
According to Apache documentation ,
a Log4j JDBC Appender configured with a DataSource is disabled by default. You may try to add java option -Dlog4j2.enableJndiJdbc=true to use JNDI's java protocol.
When we added set JAVA_OPTIONS=-Dlog4j2.enableJndiJdbc=true into our weblogic, the error was gone.
I hope it is helpful for you.

Remove first and last line from file?

I have a file that has lines like this.
(function($, _) {
.....
})(jQuery, jQuery.ZOF);
now I want to remove the first and last line of the file and then concat this file to another file , How could it be possible with ant?
loadfile can be used as follows:
<loadfile srcfile="test.xml" property="file.first.and.last.line.removed">
<filterchain>
<filterreader classname="org.apache.tools.ant.filters.HeadFilter">
<param name="lines" value="-1"/>
<param name="skip" value="1"/>
</filterreader>
<filterreader classname="org.apache.tools.ant.filters.TailFilter">
<param name="lines" value="-1"/>
<param name="skip" value="1"/>
</filterreader>
</filterchain>
</loadfile>
<echo message="${file.first.and.last.line.removed}" file="output.txt" append="true" />
First we use a HeadFilter to read everything but skipping the first line, then we "tail" the result with a TailFilter skipping the last line.
The last line appends the content to another file.

Ant: Convert class name to file path

How do I convert Java class names into file paths using Ant tasks?
For example, given a property containing foo.bar.Duck I'd like to get out foo/bar/Duck.class.
I tried (and failed) to implement this in terms of <pathconvert> and <regexpmapper>.
Here's a possible way to do this:
<property name="class.name" value="foo.bar.Duck"/>
<loadresource property="file.name">
<string value="${class.name}" />
<filterchain>
<replaceregex pattern="\." replace="/" flags="g" />
<replaceregex pattern="$" replace=".class" />
</filterchain>
</loadresource>
This puts the desired foo/bar/Duck.class into the file.name property.
Here's another way, using Ant resources and an unpackagemapper, which is designed for this purpose. The opposite package mapper is also available.
<property name="class.name" value="foo.bar.Duck"/>
<resources id="file.name">
<mappedresources>
<string value="${class.name}" />
<unpackagemapper from="*" to="*.class" />
</mappedresources>
</resources>
You use the resource value by means of the property helper syntax ${toString:...}, e.g.:
<echo message="File: ${toString:file.name}" />
Yields
[echo] File: foo/bar/Duck.class
I feel using ant script-javascript for this is much simpler
<property name="class.name" value="foo.bar.duck" />
<script language="javascript">
var className = project.getProperty("class.name");
println("before: " + className);
var filePath= className.replace("\\", "/");
println("File Path: "+filePath);
project.setProperty("filePath", filePath);
</script>
<echo message="${filePath}" />
note: that naming your variable same as argument e.g var wsPath may give error, it gave to me!
courtesy: https://stackoverflow.com/a/16099717/4979331

How to schedule a job in Quartz that repeats forever?

Is it possible to repeat a job in Quartz forever in a serial way?
Now, if I don't set RepeatInterval I get an error saying that RepeatInterval cannot be zero.
Is it possible to configure this using Spring.NET? What I have now is this:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<object id="ExampleBusinessObject" type="Edu3.Core.Job.ExampleJob, Edu3.Core"/>
<object id="JobDetail"
type="Spring.Scheduling.Quartz.MethodInvokingJobDetailFactoryObject,
Spring.Scheduling.Quartz">
<property name="TargetObject" ref="ExampleBusinessObject" />
<property name="TargetMethod" value="DoIt" />
<property name="Concurrent" value="false" />
</object>
<object id="SimpleTrigger"
type="Spring.Scheduling.Quartz.SimpleTriggerObject,
Spring.Scheduling.Quartz">
<!-- see the example of method invoking job above -->
<property name="JobDetail" ref="JobDetail" />
<!-- 10 seconds -->
<!--<property name="StartDelay" value="5s" />-->
<!-- repeat every 50 seconds -->
<property name="RepeatInterval" value="10s" />
</object>
<object id="quartzSchedulerFactory"
type="Spring.Scheduling.Quartz.SchedulerFactoryObject,
Spring.Scheduling.Quartz">
<property name="triggers">
<list>
<ref object="SimpleTrigger" />
</list>
</property>
</object>
</objects>
I don't want different threads executing the same job. I just want DoIt to be triggered. If DoIt is finished, then DoIt is triggered again. Like a infinitive while loop.
'RepeatCount' set to '-1'

Use ANT to update build number and inject into source code

In my build.xml file I am incrementing a build version number in a property file like so:
<target name="minor">
<propertyfile file="build_info.properties">
<entry key="build.minor.number" type="int" operation="+" value="1" pattern="00" />
<entry key="build.revision.number" type="int" value="0" pattern="00" />
</propertyfile>
</target>
I also have similar entries for the major and revision. (from Build numbers: major.minor.revision)
This works great. Now I would like to take this incremented build number and inject it into my source code:
//Main.as
public static const VERSION:String = "#(#)00.00.00)#";
By using:
<target name="documentVersion">
<replaceregexp file="${referer}" match="#\(#\).*#" replace="#(#)${build.major.number}.${build.minor.number}.${build.revision.number})#" />
</target>
Now this sorta works. It does indeed replace the version but with the outdated version number. So whenever I run the ANT script the build_info.properties is updated to the correct version but my source code file is using the pre updated value.
I have echoed to check that indeed I am incrementing the build number before I call the replace and I have noticed that echoing:
<echo>${build.minor.number}</echo>
//After updating it still shows old non updated value here but the new value in the property file.
So is there a way to retrieve the updated value in the property file so I can use it to inject into my source code?
Cheers
So after spending hours not being able to solve this, I post this question and then figure it out 20 minutes later.
The problem was I had this at the top of my build file:
<property file="build_info.properties"/>
I guess it was due to scoping and that properties are immutable thus I was never able to update the value. Removing that line and then adding the following got it working perfectly:
<target name="injectVersion">
<property file="build_info.properties"/>
<replaceregexp file="${referer}" match="#\(#\).*#" replace="#(#)${build.major.number}.${build.minor.number}.${build.revision.number})#" />
</target>
Why not just use <buildnumber/>?
Project used to increment build number in build.properties file
file parameters:
version.number=
build.number=
if changes version.number then build.number starts from 1
====================================================================== -->
<property name="versionFileName" value="build.properties" />
<property file="${versionFileName}" />
<property name="currentVersion" value="0.1.37"/>
<target name="calculate.version.build">
<script language="javascript">
<![CDATA[
var currentVersion = project.getProperty("currentVersion");
var oldVersion = project.getProperty("version.number");
var buildNumber = project.getProperty("build.number");
if (!currentVersion.equals(oldVersion)){
project.setProperty("currentBuild", 1);
} else {
var newBuildNumber = ++buildNumber;
project.setProperty("currentBuild", newBuildNumber);
}
]]>
</script>
</target>
<target name="update.version.build" depends="calculate.version.build">
<propertyfile file="${versionFileName}">
<entry key="build.number" type="int" operation="=" value="${currentBuild}" />
<entry key="version.number" type="string" operation="=" value="${currentVersion}" />
</propertyfile>
<echo message="New version: ${currentVersion}.${currentBuild}" />
</target>

Resources