Update of /cvsroot/xdoclet/xdoclet/core/src/xdoclet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11198/xdoclet/core/src/xdoclet
Modified Files: XDocletMain.java SubTask.java DocletContext.java Log Message: XDT-1329: added support for Ant style 'if' and 'unless' attributes for all SubTasks (thanks to Richard Easterling) Index: XDocletMain.java =================================================================== RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/XDocletMain.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -r1.14 -r1.15 *** XDocletMain.java 10 Jun 2003 13:32:37 -0000 1.14 --- XDocletMain.java 27 Apr 2005 14:32:58 -0000 1.15 *************** *** 38,50 **** for (int i = 0; i < subtasks.length; i++) { if (subtasks[i] != null) { ! if (log.isDebugEnabled()) { ! log.debug("SubTask " + subtasks[i].getSubTaskName() + " initialized."); ! } ! subtasks[i].init(xJavaDoc); ! DocletContext.getInstance().setActiveSubTask(subtasks[i]); ! log.info(Translator.getString(XDocletMessages.class, XDocletMessages.RUNNING_TASKNAME, new String[]{"<" + subtasks[i].getSubTaskName() + "/>"})); ! subtasks[i].execute(); } } --- 38,57 ---- for (int i = 0; i < subtasks.length; i++) { if (subtasks[i] != null) { ! if (subtasks[i].isIncluded()) { ! if (log.isDebugEnabled()) { ! log.debug("SubTask " + subtasks[i].getSubTaskName() + " initialized."); ! } ! subtasks[i].init(xJavaDoc); ! DocletContext.getInstance().setActiveSubTask(subtasks[i]); ! log.info(Translator.getString(XDocletMessages.class, XDocletMessages.RUNNING_TASKNAME, new String[]{"<" + subtasks[i].getSubTaskName() + "/>"})); ! subtasks[i].execute(); ! } ! else { ! if (log.isDebugEnabled()) { ! log.debug("Skipping disabled SubTask " + subtasks[i].getSubTaskName()); ! } ! } } } Index: SubTask.java =================================================================== RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/SubTask.java,v retrieving revision 1.75 retrieving revision 1.76 diff -C2 -r1.75 -r1.76 *** SubTask.java 10 Oct 2004 22:32:14 -0000 1.75 --- SubTask.java 27 Apr 2005 14:32:58 -0000 1.76 *************** *** 31,34 **** --- 31,39 ---- public abstract class SubTask extends DocletSupport implements Serializable { + + /** + * no test present state for 'if' and 'unless' properties. + */ + private final static String NO_TEST = ""; private XJavaDoc _xJavaDoc; *************** *** 57,60 **** --- 62,75 ---- /** + * The 'if' condition to test on execution. + */ + private String ifCondition = NO_TEST; + + /** + * The 'unless' condition to test on execution. + */ + private String unlessCondition = NO_TEST; + + /** * Gets the SubTaskName attribute of the SubTask object * *************** *** 107,110 **** --- 122,136 ---- /** + * Checks 'if' and 'unless' attributes for SubTask inclusion in execution of XDoclet parent Task. + * + * @return <code>true</code> when both 'if' and 'unless' tests are absent or when 'if' property is present or when + * 'unless' property is not present. + */ + public boolean isIncluded() + { + return testIfCondition() && testUnlessCondition(); + } + + /** * Sets an optional name for the subtask that will be seen in XDoclet's debug messages. * *************** *** 137,140 **** --- 163,190 ---- /** + * If no 'if' test is specified, this subtask will execute normally. When an 'if' test is present, the subtask will + * execute if the specified property is set to any value. + * + * @param property The property condition to test on execution. May be <code>null</code>, in which case no "if" + * test is performed. + */ + public void setIf(String property) + { + this.ifCondition = (property == null) ? NO_TEST : property; + } + + /** + * If no 'unless' test is specified, this subtask will execute normally. When an 'unless' test is present, the + * subtask will execute unless the specified property is set to any value. + * + * @param property The property condition to test on execution. May be <code>null</code>, in which case no "unless" + * test is performed. + */ + public void setUnless(String property) + { + this.unlessCondition = (property == null) ? NO_TEST : property; + } + + /** * Specifies a configuration parameter for the subtask. * *************** *** 226,228 **** --- 276,314 ---- return _xJavaDoc; } + + /** + * Tests whether or not the "if" condition is satisfied. + * + * @return <code>true</code> if no 'if' test is specified or when 'if' is specified and the property with the name + * given in 'if' is set to any value. + * @see #setIf(String) + */ + private boolean testIfCondition() + { + if (NO_TEST == ifCondition) { + return true; + } + + String test = getContext().getProperty(ifCondition); + + return test != null; + } + + /** + * Tests whether or not the "unless" condition is satisfied. + * + * @return <code>true</code> if no 'unless' test is specified or when 'unless' is specified and no property with + * the name given in 'unless' is present + * @see #setUnless(String) + */ + private boolean testUnlessCondition() + { + if (NO_TEST == unlessCondition) { + return true; + } + + String test = getContext().getProperty(unlessCondition); + + return test == null; + } } Index: DocletContext.java =================================================================== RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/DocletContext.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -r1.17 -r1.18 *** DocletContext.java 7 Jun 2002 14:10:36 -0000 1.17 --- DocletContext.java 27 Apr 2005 14:33:00 -0000 1.18 *************** *** 225,229 **** for (int i = 0; i < subTasks.length; i++) { if (subTasks[i] != null && subTasks[i].getSubTaskName().toLowerCase().equals(subtaskName.toLowerCase())) { ! return subTasks[i]; } } --- 225,229 ---- for (int i = 0; i < subTasks.length; i++) { if (subTasks[i] != null && subTasks[i].getSubTaskName().toLowerCase().equals(subtaskName.toLowerCase())) { ! return subTasks[i].isIncluded() ? subTasks[i] : null; } } ------------------------------------------------------- SF.Net email is sponsored by: Tell us your software development plans! Take this survey and enter to win a one-year sub to SourceForge.net Plus IDC's 2005 look-ahead and a copy of this survey Click here to start! http://www.idcswdc.com/cgi-bin/survey?id=105hix _______________________________________________ xdoclet-devel mailing list xdoclet-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xdoclet-devel