Skip to content

Commit

Permalink
[ReplaceRegexpTask] Added fail on error support
Browse files Browse the repository at this point in the history
  • Loading branch information
siad007 authored Sep 14, 2024
1 parent b2af8ce commit f8ce479
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Phing/Task/System/ReplaceRegexpTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ class ReplaceRegexpTask extends Task
*/
private $regexp;

private $failonerror = false;

/**
* If false, note errors but continue.
*/
public void setFailOnError($failonerror) {
$this->failonerror = $failonerror;
}

/**
* File to apply regexp on.
*/
Expand Down Expand Up @@ -201,6 +210,9 @@ public function main()
$in->close();
}
$this->log('Error reading file: ' . $e->getMessage(), Project::MSG_WARN);
if ($this->failonerror) {
throw new BuildException("Error reading file: '" . $file->getAbsolutePath() . "'", $e);
}
}

try {
Expand All @@ -214,6 +226,9 @@ public function main()
$out->close();
}
$this->log('Error writing file back: ' . $e->getMessage(), Project::MSG_WARN);
if ($this->failonerror) {
throw new BuildException("Error writing file back: '" . $file->getAbsolutePath() . "'", $e);
}
}
}
}
Expand Down

0 comments on commit f8ce479

Please sign in to comment.