001
014
015 package com.liferay.util.ant;
016
017 import com.liferay.portal.kernel.util.StringPool;
018
019 import java.text.MessageFormat;
020
021 import org.apache.tools.ant.BuildException;
022 import org.apache.tools.ant.Project;
023 import org.apache.tools.ant.taskdefs.Echo;
024
025
028 public class FormatTask extends Echo {
029
030 @Override
031 public void execute() throws BuildException {
032 if (message == null) {
033 throw new BuildException("The message attribute is mandatory");
034 }
035
036 Object[] arguments = _arguments.split(_separator);
037
038 String value = MessageFormat.format(message, arguments);
039
040 if (_property != null) {
041 Project project = getProject();
042
043 project.setProperty(_property, value);
044 }
045 else {
046 setMessage(value);
047
048 super.execute();
049 }
050 }
051
052 public void setArguments(String arguments) {
053 _arguments = arguments;
054 }
055
056 public void setProperty(String property) {
057 _property = property;
058 }
059
060 public void setSeparator(String separator) {
061 _separator = separator;
062 }
063
064 private String _arguments;
065 private String _property;
066 private String _separator = StringPool.COMMA;
067
068 }