Grokbase Groups Ant dev January 2008
FAQ
I prefer collecting all configuration errors and reporting them at once
over throwing a BuildException for each error. Ok Ant is not a GUI ....
I implemented a helper class for that - is it worth to introduce that
into Ant Core?


Jan



/**
* @see <a
href="http://martinfowler.com/eaaDev/Notification.html">Notification
Pattern</a>
*/
public class AntConfigurationChecker {
List errors = new ArrayList();
Task task;

public AntConfigurationChecker(Task task) {
this.task = task;
}

public void assertConfig(boolean bedingung, String
fehlermeldung) {
if (bedingung) {
errors.add(fehlermeldung);
}
}

public void fail(String fehlermeldung) {
errors.add(fehlermeldung);
}

public void checkErrors() throws BuildException {
if (!errors.isEmpty()) {
StringBuffer sb = new StringBuffer();
sb.append("Configuration error on <");
sb.append(task.getTaskName());
sb.append(">:");
sb.append(System.getProperty("line.separator"));
for (Iterator it = errors.iterator();
it.hasNext();) {
String msg = (String) it.next();
sb.append("- ");
sb.append(msg);

sb.append(System.getProperty("line.separator"));
}
throw new BuildException(sb.toString());
}
}
}



public class MyTask {
private void checkConfiguration() {
AntConfigurationChecker checker = new
AntConfigurationChecker(this);
checker.assertConfig(
xmlfile == null && txtfile == null,
"You have to specify one of 'txtfile' or
'xmlfile'.");
checker.assertConfig(
release == null,
"You have to specify the 'release'.");
checker.checkErrors();
}
public void execute() throws BuildException {
checkConfiguration();
...
}
}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org

Search Discussions

  • Kevin Jackson at Jan 28, 2008 at 2:17 pm
    Hi,
    I prefer collecting all configuration errors and reporting them at once
    over throwing a BuildException for each error. Ok Ant is not a GUI ....
    I implemented a helper class for that - is it worth to introduce that
    into Ant Core?
    I have no problem unless you want it in 1.7.1, trunk is fine though
    sounds good :)

    Kev

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
    For additional commands, e-mail: dev-help@ant.apache.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdev @
categoriesant
postedJan 28, '08 at 2:08p
activeJan 28, '08 at 2:17p
posts2
users2
websiteant.apache.org

2 users in discussion

Kevin Jackson: 1 post Jan Materne: 1 post

People

Translate

site design / logo © 2017 Grokbase