75
75
* match="pattern"
76
76
* replace="pattern"
77
77
* flags="options"?
78
- * byline="true|false"? >
78
+ * byline="true|false"?
79
+ * failOnError="true|false"? >
79
80
* regexp?
80
81
* substitution?
81
82
* fileset*
101
102
* "true" indicates to perform replacement on a line by line basis
102
103
* "false" indicates to perform replacement on the whole file at once.
103
104
*
105
+ * failOnError --> Should this task fail if an error occurs (default is false)
106
+ * "true" indicates that this task should fail if an error occurs
107
+ * "false" indicates that this task should continue if an error occurs
108
+ *
104
109
* Example:
105
110
*
106
111
* The following call could be used to replace an old property name in a ".properties"
@@ -123,6 +128,7 @@ public class ReplaceRegExp extends Task {
123
128
private Union resources ;
124
129
private RegularExpression regex ;
125
130
private Substitution subs ;
131
+ private boolean failonerror = false ;
126
132
127
133
private static final FileUtils FILE_UTILS = FileUtils .getFileUtils ();
128
134
@@ -315,6 +321,15 @@ public void setPreserveLastModified(boolean b) {
315
321
preserveLastModified = b ;
316
322
}
317
323
324
+ /**
325
+ * If false, note errors but continue.
326
+ *
327
+ * @param failonerror true or false
328
+ */
329
+ public void setFailOnError (boolean failonerror ) {
330
+ this .failonerror = failonerror ;
331
+ }
332
+
318
333
/**
319
334
* Invoke a regular expression (r) on a string (input) using
320
335
* substitutions (s) for a matching regex.
@@ -481,10 +496,17 @@ public void execute() throws BuildException {
481
496
log ("An error occurred processing file: '"
482
497
+ file .getAbsolutePath () + "': " + e .toString (),
483
498
Project .MSG_ERR );
499
+ if (failonerror ) {
500
+ throw new BuildException ("An error occurred processing file: '" + file .getAbsolutePath () + "'" ,
501
+ e , getLocation ());
502
+ }
484
503
}
485
504
} else if (file != null ) {
486
505
log ("The following file is missing: '"
487
506
+ file .getAbsolutePath () + "'" , Project .MSG_ERR );
507
+ if (failonerror ) {
508
+ throw new BuildException ("The following file is missing: '" + file .getAbsolutePath () + "'" );
509
+ }
488
510
}
489
511
490
512
if (resources != null ) {
@@ -498,10 +520,17 @@ public void execute() throws BuildException {
498
520
log ("An error occurred processing file: '"
499
521
+ f .getAbsolutePath () + "': " + e .toString (),
500
522
Project .MSG_ERR );
523
+ if (failonerror ) {
524
+ throw new BuildException ("An error occurred processing file: '" + f .getAbsolutePath () + "'" ,
525
+ e , getLocation ());
526
+ }
501
527
}
502
528
} else {
503
529
log ("The following file is missing: '"
504
530
+ f .getAbsolutePath () + "'" , Project .MSG_ERR );
531
+ if (failonerror ) {
532
+ throw new BuildException ("The following file is missing: '" + f .getAbsolutePath () + "'" );
533
+ }
505
534
}
506
535
}
507
536
}
0 commit comments