How can I use a variable inside an attribute's value?
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.data.mapper.SomeMapper">
<sql id="fields">
<![CDATA[
${alias}some_seq AS `${prefix}someSeq`,
...
]]>
</sql>
<sql id="fieldsAssociative">
<include refid="com.example.demo.data.mapper.SomeMapper.fields">
<property name="alias" value="#{alias}"/> <!-- Can I do this? -->
<property name="prefix" value="#{prefix}"/> <!-- Or this? -->
</include>
,
<include refid="com.example.demo.data.mapper.OtherMapper.fields">
<property name="alias" value="#{alias}2o"/>m
<property name="prefix" value="#{prefix}.otgher."/>
</include>
</sql>
</mapper>
How to add current date while creating a folder in nant?
I have <mkdir dir="${Test.Dir}" /> and as a result I need to get the folder created with name
"TestDir-04-04-2022".
Any advise? Thanks.
In my case I only found solution to use embeded C# code with custom function. Possible solutions:
Variant 1:
<?xml version="1.0" encoding="utf-8"?>
<project name="Deployment" default="Deploy">
<script language="C#" prefix="datetime">
<code>
<![CDATA[
[Function("now-formatted")]
public static string GetNowAsString(string format) {
return DateTime.Now.ToString(format);
}
]]>
</code>
</script>
<target name="DateTimeTest">
<property name="Test.Dir" value="${'TestDir-' + datetime::now-formatted('dd-MM-yyyy')}" />
<echo message="${Test.Dir}" />
<mkdir dir="${Test.Dir}" />
</target>
</project>
Variant 2:
<?xml version="1.0" encoding="utf-8"?>
<project name="Deployment" default="Deploy">
<script language="C#" prefix="datetime">
<code>
<![CDATA[
[Function("format")]
public static string GetNowAsString(DateTime datetime, string format) {
return datetime.ToString(format);
}
]]>
</code>
</script>
<target name="DateTimeTest">
<property name="Test.Dir" value="${'TestDir-' + datetime::format(datetime::now(), 'dd-mm-yyyy')}" />
<echo message="${Test.Dir}" />
<mkdir dir="${Test.Dir}" />
</target>
</project>
Note: datetime::now - is standard nant function.
Output:
DateTimeTest:
[echo] TestDir-08-23-2022
[mkdir] Creating directory 'C:\Test\TestDir-08-23-2022'.
BUILD SUCCEEDED
Total time: 0.2 seconds.
I have setup gwt remote logging based on the gwt documentation, however my logs are going to System.out instead of being written to a log file.
My gwt module looks like:
<module rename-to='ezdappserver'>
<inherits name="com.google.gwt.logging.Logging"/>
<set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />
<set-property name="gwt.logging.logLevel" value="FINEST"/>
<set-property name="gwt.logging.enabled" value="TRUE"/>
<set-property name="gwt.logging.consoleHandler" value="ENABLED" />
<set-property name="gwt.logging.popupHandler" value="DISABLED" />
</module>
My servlet definition is setup like:
<servlet>
<servlet-name>remoteLogging</servlet-name>
<servlet-class>com.google.gwt.logging.server.RemoteLoggingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>remoteLogging</servlet-name>
<url-pattern>/ezdappserver/remote_logging</url-pattern>
</servlet-mapping>
When an error is logged I see output in my console like so:
Mar 26, 2014 2:10:36 PM com.google.gwt.logging.server.RemoteLoggingServiceUtil logOnServer
SEVERE: Exception caught: (NotFoundError)
....Rest of error....
I was expecting this output to be written to a log file somewhere in my war. Also, I would really like to be able to specify where this file is located, however I haven't been able to find any documentation on that either.
Any help would be much appreciated.
NOTE: I am not running this through dev mode, this is with compiled code.
Thanks!
Try below options also in gwt.xml based on your requirement:
<!-- This handler sends log messages to the server, where they will be logged using the server side logging mechanism. -->
<set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />
<!-- Logs by calling method GWT.log. These messages can only be seen in Development Mode in the DevMode window. -->
<set-property name="gwt.logging.developmentModeHandler" value="ENABLED" />
<!-- These messages can only be seen in Development Mode in the DevMode window. -->
<set-property name="gwt.logging.systemHandler" value="ENABLED" />
<!-- Logs to the popup which resides in the upper left hand corner of application when this handler is enabled. -->
<set-property name="gwt.logging.popupHandler" value="DISABLED" />
<!-- Logs to the javascript console, which is used by Firebug Lite (for IE), Safari and Chrome. -->
<set-property name="gwt.logging.consoleHandler" value="DISABLED"/>
<!-- Logs to the firebug console. -->
<set-property name="gwt.logging.firebugHandler" value="DISABLED" />
If above configuration are still not working for you then try below code along with above configuration.
Add log4j.xml file to define the log file location with log level
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="DT=> %d [%.4t] %-5p %c{1} - %m%n" />
</layout>
</appender>
<appender name="SERVER_FILE_LOG" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${jboss.server.log.dir}/logs/DataTools_Server.log" />
<param name="Append" value="true" />
<param name="MaxFileSize" value="5MB" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%.4t] %-5p [%c] %m%n" />
</layout>
</appender>
<appender name="CLIENT_FILE_LOG" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${jboss.server.log.dir}/logs/DataTools_Client.log" />
<param name="Append" value="true" />
<param name="MaxFileSize" value="5MB" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%.4t] %-5p %m%n" />
</layout>
</appender>
<category name="com.x.y.server">
<priority value="DEBUG" />
<appender-ref ref="SERVER_FILE_LOG" />
<appender-ref ref="STDOUT" />
</category>
<category name="gwtRemoteLogging">
<priority value="ERROR" />
<appender-ref ref="CLIENT_FILE_LOG" />
</category>
<root>
<priority value ="ERROR" />
<appender-ref ref="SERVER_FILE_LOG" />
</root>
</log4j:configuration>
Define you own logging servlet by implementing RemoteLoggingService
import java.util.logging.Level;
import java.util.logging.LogRecord;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import com.google.gwt.logging.server.StackTraceDeobfuscator;
import com.google.gwt.logging.shared.RemoteLoggingService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import org.apache.log4j.Logger;
/**
* The Class GwtRemoteLogging.
*/
#SuppressWarnings("serial")
public class GwtRemoteLogging extends RemoteServiceServlet implements RemoteLoggingService {
/** The Constant logger. */
private StackTraceDeobfuscator deobfuscator = null;
private final static Logger logger = Logger.getLogger("gwtRemoteLogging");
#Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
/**
* Logs a Log Record which has been serialized using GWT RPC on the server.
*
* #return either an error message, or null if logging is successful.
*/
public final String logOnServer(LogRecord lr) {
try {
if (lr.getLevel().equals(Level.SEVERE)) {
logger.error(lr.getMessage(),lr.getThrown());
} else if (lr.getLevel().equals(Level.INFO)) {
logger.info(lr.getMessage(),lr.getThrown());
} else if (lr.getLevel().equals(Level.WARNING)) {
logger.warn(lr.getMessage(),lr.getThrown());
} else if (lr.getLevel().equals(Level.FINE)) {
logger.debug(lr.getMessage(),lr.getThrown());
} else {
logger.trace(lr.getMessage(),lr.getThrown());
}
} catch (Exception e) {
logger.error("Remote logging failed", e);
return "Remote logging failed, check stack trace for details.";
}
return null;
}
/**
* By default, this service does not do any deobfuscation. In order to do server side
* deobfuscation, you must copy the symbolMaps files to a directory visible to the server and
* set the directory using this method.
*
* #param symbolMapsDir
*/
public void setSymbolMapsDirectory(String symbolMapsDir) {
if (deobfuscator == null) {
deobfuscator = new StackTraceDeobfuscator(symbolMapsDir);
} else {
deobfuscator.setSymbolMapsDirectory(symbolMapsDir);
}
}
}
web.xml
<servlet>
<servlet-name>remoteLogServlet</servlet-name>
<servlet-class>com.x.y.server.servlet.GwtRemoteLogging</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>remoteLogServlet</servlet-name>
<url-pattern>/ezdappserver/remote_logging</url-pattern>
</servlet-mapping>
The RemoteServiceServlet uses java.util.logging to log, and by default it logs to the console (System.err, not System.out BTW).
If you want to log to a file, then you have to configure java.util.logging; either editing your global lib/logging.properties (not recommended), using your own config file that you pass to the JVM using the java.util.logging.config.file system property, or programmatically.
Depending on your servlet container, it can be configured by different means. For instance, Tomcat will read a logging.properties file in your WEB-INF/classes: http://tomcat.apache.org/tomcat-7.0-doc/logging.html#Using_java.util.logging_(default)
I have a Eclipse Plugin and I need to call ant inside of that plugin to make some stuffs, like run junit test and get the coverage of that test (using jacoco plugin for this purpose)...
My build.xml
<project name="Calculadora" default="rebuild" basedir="." xmlns:jacoco="antlib:org.jacoco.ant">
<property name="src" location="./src"/>
<property name="bin.dir" location="./bin"/>
<property name="bin.report.dir" location="${bin.dir}/report"/>
<property name="bin.exec.file" location="${bin.dir}/jacoco.exec"/>
<property name="junit.out.dir" location="${bin.report.dir}/junit/xml"/>
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="/tmp/jacocoant4002041518230825590.jar"/>
</taskdef>
<path id="classpath">
<pathelement location="${bin.dir}"/>
<pathelement location="${src}"/>
<pathelement location="/usr/lib/eclipse/plugins/org.junit4_4.5.0.v20090824/junit.jar"/>
</path>
<target name="clean">
<mkdir dir="${bin.report.dir}"/>
<mkdir dir="${junit.out.dir}"/>
</target>
<target name="test" depends="clean">
<jacoco:coverage destfile="${bin.exec.file}">
<junit fork="true" forkmode="once">
<classpath refid="classpath"/>
<formatter type="xml" usefile="true"/>
<test name="functions.test.ReadFile" todir="${junit.out.dir}"/>
</junit>
</jacoco:coverage>
</target>
<target name="report" depends="test">
<jacoco:report>
<executiondata>
<file file="${bin.exec.file}"/>
</executiondata>
<structure name="">
<classfiles>
<fileset dir="${bin.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src}"/>
</sourcefiles>
</structure>
<xml destfile="${bin.report.dir}/report.xml"/>
</jacoco:report>
<junitreport todir="${junit.out.dir}">
<fileset dir="${junit.out.dir}">
<include name="TEST-*.xml"/>
</fileset>
</junitreport>
</target>
<target name="rebuild" depends="clean,test,report"/>
</project>
The code to call Ant in Java:
// Creates a new Project object
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
p.addBuildListener(consoleLogger);
p.executeTarget(p.getDefaultTarget());
But when I run my plugin i get this error:
build.xml:34: java.lang.ClassNotFoundException:
org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.createMirror(JUnitTask.java:708)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.setupJUnitDelegate(JUnitTask.java:745)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:755)
at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at org.jacoco.ant.CoverageTask.execute(CoverageTask.java:95) at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616) at
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348) at
org.apache.tools.ant.Target.execute(Target.java:390) at
org.apache.tools.ant.Target.performTasks(Target.java:411) at
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1360)
at org.apache.tools.ant.Project.executeTarget(Project.java:1329)
Caused by: java.lang.ClassNotFoundException:
org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl at
org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1386)
at
org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1336)
at
org.apache.tools.ant.util.SplitClassLoader.loadClass(SplitClassLoader.java:52)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266) at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.createMirror(JUnitTask.java:701)
... 19 more
What's happening? What I am doing wrong?
Thanks in advance
I am trying to figure out how to write a simple if condition in nant
that will evaluate to true when both x & y properties are true.
<project default="all">
<property name="x" value="True" />
<property name="y" value="True" />
<target name="all">
<echo message="x is True" if="${x}" />
<echo message="y is True" if="${x}" />
<echo message="x AND y are True" if="${x} AND ${y}" />
<echo message="x AND y are True" if="${x} && ${y}" />
</target>
</project>
I cannot figure out the syntax for the x AND y echo message - I tried both AND and '&&' and that doesn't seem to work.(i keep getting error messages like : String was not recognized as a valid Boolean.)
You want to use if="${x and y}", where both x and y are in the same pair of brackets:
<project default="all">
<property name="x" value="true" />
<property name="y" value="true" />
<target name="all">
<echo message="x is True" if="${x}" />
<echo message="y is True" if="${y}" />
<echo message="x AND y are True" if="${x and y}" />
</target>
</project>
Hope that helps!