Browse Source

style

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@687620 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 17 years ago
parent
commit
01a000d122
1 changed files with 41 additions and 38 deletions
  1. +41
    -38
      src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java

+ 41
- 38
src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java View File

@@ -110,9 +110,9 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
public class PropertyFile extends Task { public class PropertyFile extends Task {


/* ======================================================================== /* ========================================================================
*
* Instance variables.
*/
*
* Instance variables.
*/


// Use this to prepend a message to the properties file // Use this to prepend a message to the properties file
private String comment; private String comment;
@@ -124,14 +124,14 @@ public class PropertyFile extends Task {
private Vector entries = new Vector(); private Vector entries = new Vector();


/* ======================================================================== /* ========================================================================
*
* Constructors
*/
*
* Constructors
*/


/* ======================================================================== /* ========================================================================
*
* Methods
*/
*
* Methods
*/


/** /**
* Execute the task. * Execute the task.
@@ -163,7 +163,8 @@ public class PropertyFile extends Task {


private void readFile() throws BuildException { private void readFile() throws BuildException {
if (useJDKProperties) { if (useJDKProperties) {
// user chose to use standard Java properties, which loose comments and layout
// user chose to use standard Java properties, which loose
// comments and layout
properties = new Properties(); properties = new Properties();
} else { } else {
properties = new LayoutPreservingProperties(); properties = new LayoutPreservingProperties();
@@ -202,7 +203,8 @@ public class PropertyFile extends Task {


private void checkParameters() throws BuildException { private void checkParameters() throws BuildException {
if (!checkParam(propertyfile)) { if (!checkParam(propertyfile)) {
throw new BuildException("file token must not be null.", getLocation());
throw new BuildException("file token must not be null.",
getLocation());
} }
} }


@@ -223,12 +225,13 @@ public class PropertyFile extends Task {
} }


/** /**
* optional flag to use original Java properties (as opposed to layout preserving properties)
* optional flag to use original Java properties (as opposed to
* layout preserving properties)
*/ */
public void setJDKProperties(boolean val) { public void setJDKProperties(boolean val) {
useJDKProperties = val; useJDKProperties = val;
} }
private void writeFile() throws BuildException { private void writeFile() throws BuildException {
BufferedOutputStream bos = null; BufferedOutputStream bos = null;
try { try {
@@ -356,7 +359,7 @@ public class PropertyFile extends Task {
executeString(oldValue); executeString(oldValue);
} else { } else {
throw new BuildException("Unknown operation type: " throw new BuildException("Unknown operation type: "
+ type);
+ type);
} }
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
// Default to string type // Default to string type
@@ -373,17 +376,17 @@ public class PropertyFile extends Task {
} }


/** /**
* Handle operations for type <code>date</code>.
*
* @param oldValue the current value read from the property file or
* <code>null</code> if the <code>key</code> was
* not contained in the property file.
*/
* Handle operations for type <code>date</code>.
*
* @param oldValue the current value read from the property file or
* <code>null</code> if the <code>key</code> was
* not contained in the property file.
*/
private void executeDate(String oldValue) throws BuildException { private void executeDate(String oldValue) throws BuildException {
Calendar currentValue = Calendar.getInstance(); Calendar currentValue = Calendar.getInstance();


if (pattern == null) { if (pattern == null) {
pattern = "yyyy/MM/dd HH:mm";
pattern = "yyyy/MM/dd HH:mm";
} }
DateFormat fmt = new SimpleDateFormat(pattern); DateFormat fmt = new SimpleDateFormat(pattern);


@@ -420,19 +423,19 @@ public class PropertyFile extends Task {




/** /**
* Handle operations for type <code>int</code>.
*
* @param oldValue the current value read from the property file or
* <code>null</code> if the <code>key</code> was
* not contained in the property file.
*/
* Handle operations for type <code>int</code>.
*
* @param oldValue the current value read from the property file or
* <code>null</code> if the <code>key</code> was
* not contained in the property file.
*/
private void executeInteger(String oldValue) throws BuildException { private void executeInteger(String oldValue) throws BuildException {
int currentValue = DEFAULT_INT_VALUE; int currentValue = DEFAULT_INT_VALUE;
int newV = DEFAULT_INT_VALUE; int newV = DEFAULT_INT_VALUE;




DecimalFormat fmt = (pattern != null) ? new DecimalFormat(pattern) DecimalFormat fmt = (pattern != null) ? new DecimalFormat(pattern)
: new DecimalFormat();
: new DecimalFormat();
try { try {
String curval = getCurrentValue(oldValue); String curval = getCurrentValue(oldValue);
if (curval != null) { if (curval != null) {
@@ -471,12 +474,12 @@ public class PropertyFile extends Task {
} }


/** /**
* Handle operations for type <code>string</code>.
*
* @param oldValue the current value read from the property file or
* <code>null</code> if the <code>key</code> was
* not contained in the property file.
*/
* Handle operations for type <code>string</code>.
*
* @param oldValue the current value read from the property file or
* <code>null</code> if the <code>key</code> was
* not contained in the property file.
*/
private void executeString(String oldValue) throws BuildException { private void executeString(String oldValue) throws BuildException {
String newV = DEFAULT_STRING_VALUE; String newV = DEFAULT_STRING_VALUE;


@@ -503,18 +506,18 @@ public class PropertyFile extends Task {
if (type == Type.STRING_TYPE if (type == Type.STRING_TYPE
&& operation == Operation.DECREMENT_OPER) { && operation == Operation.DECREMENT_OPER) {
throw new BuildException("- is not supported for string " throw new BuildException("- is not supported for string "
+ "properties (key:" + key + ")");
+ "properties (key:" + key + ")");
} }
if (value == null && defaultValue == null) { if (value == null && defaultValue == null) {
throw new BuildException("\"value\" and/or \"default\" " throw new BuildException("\"value\" and/or \"default\" "
+ "attribute must be specified (key:" + key + ")");
+ "attribute must be specified (key:" + key + ")");
} }
if (key == null) { if (key == null) {
throw new BuildException("key is mandatory"); throw new BuildException("key is mandatory");
} }
if (type == Type.STRING_TYPE && pattern != null) { if (type == Type.STRING_TYPE && pattern != null) {
throw new BuildException("pattern is not supported for string " throw new BuildException("pattern is not supported for string "
+ "properties (key:" + key + ")");
+ "properties (key:" + key + ")");
} }
} }


@@ -651,7 +654,7 @@ public class PropertyFile extends Task {
/** no arg constructor */ /** no arg constructor */
public Unit() { public Unit() {
calendarFields.put(MILLISECOND, calendarFields.put(MILLISECOND,
new Integer(Calendar.MILLISECOND));
new Integer(Calendar.MILLISECOND));
calendarFields.put(SECOND, new Integer(Calendar.SECOND)); calendarFields.put(SECOND, new Integer(Calendar.SECOND));
calendarFields.put(MINUTE, new Integer(Calendar.MINUTE)); calendarFields.put(MINUTE, new Integer(Calendar.MINUTE));
calendarFields.put(HOUR, new Integer(Calendar.HOUR_OF_DAY)); calendarFields.put(HOUR, new Integer(Calendar.HOUR_OF_DAY));


Loading…
Cancel
Save