Index: src/main/org/apache/tools/ant/Project.java =================================================================== RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/Project.java,v retrieving revision 1.154.2.1 diff -c -b -r1.154.2.1 Project.java *** src/main/org/apache/tools/ant/Project.java 11 Dec 2003 12:16:46 -0000 1.154.2.1 --- src/main/org/apache/tools/ant/Project.java 16 Dec 2003 07:32:23 -0000 *************** *** 63,68 **** --- 63,71 ---- import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; + import java.util.List; + import java.util.LinkedList; + import java.util.Collections; import java.util.Properties; import java.util.Stack; import java.util.Vector; *************** *** 77,82 **** --- 80,87 ---- import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.JavaEnvUtils; import org.apache.tools.ant.util.StringUtils; + import org.apache.tools.ant.util.regexp.RegexpMatcher; + import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; /** *************** *** 1044,1049 **** --- 1049,1112 ---- */ public Hashtable getTargets() { return targets; + } + + private RegexpMatcherFactory targetMatcherFactory = new RegexpMatcherFactory(); + + public List findTargetNames(String expression) { + // if the given expression is an exact target name ... + if (targets.containsKey(expression)) { + return Collections.singletonList(expression); + } + + // try to create a Matcher to use the expression + RegexpMatcher matcher = null; + + if (targetMatcherFactory != null) { + try { + matcher = targetMatcherFactory.newRegexpMatcher(this); + } catch (BuildException e) { + String msg = "no supported regular expression matcher found," + + "the star dependencies support is disabled"; + log(msg, MSG_VERBOSE); + targetMatcherFactory = null; + } + } + + // if the star dependencies is disabled, return the given expression has the target name + if (matcher == null) { + return Collections.singletonList(expression); + } + + // add the implicit '^' and '$' to the expression if needed + if (! expression.startsWith("^")) { + expression = "^" + expression; + } + if (! expression.endsWith("$")) { + expression = expression + "$"; + } + + matcher.setPattern(expression); + + List foundTargetNames = new LinkedList(); + + for (Iterator iter=targets.keySet().iterator(); iter.hasNext(); ) { + String targetName = (String) iter.next(); + + if (matcher.matches(targetName)) { + foundTargetNames.add(targetName); + } + } + + if (foundTargetNames.isEmpty()) { + throw new BuildException("can't find a target name which matches '" + expression + "'"); + } + + Collections.sort(foundTargetNames); + + log("found targets " + foundTargetNames + " for '" + expression + "'", MSG_DEBUG); + + return foundTargetNames; } /** Index: src/main/org/apache/tools/ant/Target.java =================================================================== RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/Target.java,v retrieving revision 1.46 diff -c -b -r1.46 Target.java *** src/main/org/apache/tools/ant/Target.java 17 Sep 2003 14:23:27 -0000 1.46 --- src/main/org/apache/tools/ant/Target.java 16 Dec 2003 07:32:24 -0000 *************** *** 59,67 **** --- 59,69 ---- import java.util.Enumeration; import java.util.Iterator; import java.util.List; + import java.util.LinkedList; import java.util.StringTokenizer; import org.apache.tools.ant.util.CollectionUtils; + import org.apache.tools.ant.util.StringUtils; /** * Class to implement a target object with required parameters. *************** *** 78,83 **** --- 80,87 ---- private String unlessCondition = ""; /** List of targets this target is dependent on. */ private List dependencies = null; + /** false if the dependencies are not expanded for the moment */ + private boolean isDependenciesExpanded = false; /** Children of this target (tasks and data types). */ private List children = new ArrayList(); *************** *** 217,222 **** --- 221,247 ---- dependencies.add(dependency); } + private List expandDependencies() { + List targetNames = new LinkedList(); + + for (Iterator iter=dependencies.iterator(); iter.hasNext(); ) { + String dependency = (String) iter.next(); + + // simply some common expressions + // expressions ended with .* or which contains .*. + if (dependency.endsWith(".*") || dependency.indexOf(".*.") > -1) { + // protect the dots + dependency = StringUtils.replace(dependency, ".", "\\."); + // remplace * with [^.]+ + dependency = StringUtils.replace(dependency, "*", "[^.]+"); + } + + targetNames.addAll(getProject().findTargetNames(dependency)); + } + + return targetNames; + } + /** * Returns an enumeration of the dependencies of this target. * *************** *** 224,229 **** --- 249,259 ---- */ public Enumeration getDependencies() { if (dependencies != null) { + if (!isDependenciesExpanded) { + dependencies = expandDependencies(); + isDependenciesExpanded = true; + } + return Collections.enumeration(dependencies); } else { return new CollectionUtils.EmptyEnumeration();