? patch.txt ? patch.txt.tmp Index: src/main/org/apache/tools/ant/Main.java =================================================================== RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/Main.java,v retrieving revision 1.91 diff -u -r1.91 Main.java --- src/main/org/apache/tools/ant/Main.java 5 Aug 2003 15:40:56 -0000 1.91 +++ src/main/org/apache/tools/ant/Main.java 11 Aug 2003 19:04:14 -0000 @@ -63,6 +63,8 @@ import java.util.Enumeration; import java.util.Properties; import java.util.Vector; +import java.util.Iterator; +import java.util.Hashtable; import org.apache.tools.ant.input.DefaultInputHandler; import org.apache.tools.ant.input.InputHandler; import org.apache.tools.ant.util.JavaEnvUtils; @@ -648,6 +650,24 @@ project.setKeepGoingMode(keepGoingMode); ProjectHelper.configureProject(project, buildFile); + + // enforce target accessibility constraints + Hashtable configuredTargets = project.getTargets(); + Iterator iter = targets.iterator(); + while(iter.hasNext()) { + String tname = (String) iter.next(); + Target t = (Target) configuredTargets.get(tname); + + // t can be null if the user passed a non-existant target + if ( t != null && !t.isAccessibleFrom("command line")) { + throw new BuildException ("Target " + tname + + " cannot be invoked on " + + "the command line because " + + "the build file author " + + "has restricted it's " + + "accesibility."); + } + } if (projectHelp) { printDescription(project); 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.43 diff -u -r1.43 Target.java --- src/main/org/apache/tools/ant/Target.java 24 Jul 2003 14:20:56 -0000 1.43 +++ src/main/org/apache/tools/ant/Target.java 11 Aug 2003 19:04:14 -0000 @@ -82,6 +82,8 @@ private List children = new ArrayList(); /** Position in task list */ private int taskPosition = 0; + /** Accesibility of this target. */ + private String access_mod="public"; /** Project this target belongs to. */ private Project project; @@ -161,6 +163,21 @@ } /** + * Sets the access modifier of this target. + * + * @param access_mod The access modifier for this target. Default is + * "public". + */ + public void setAccess(String access) { + if ("public".equals(access) + || "private".equals(access)) { + this.access_mod = access; + } else { + throw new BuildException("Unknown access type."); + } + } + + /** * Returns the name of this target. * * @return the name of this target, or null if the @@ -442,5 +459,32 @@ } String test = project.replaceProperties(unlessCondition); return project.getProperty(test) == null; + } + + /** + * Tests if the target may be invoked from the specified location. + * The results of this test are dependant on the location and the access + * level set by the builfile author (e.g. access="private"). This method + * can only return sensible results for access points it knows about, so + * attempts to call it on arbitrary access point names not defined in this + * method will result in an IllegalArguementException. + * + * @return whether or not the access point specified is permitted. + * If the access point is not recognized, an IllegalArgument + * exception is thrown. + * @param access_point Where the target is being accessed from. + */ + + public boolean isAccessibleFrom(String access_point) { + if ("command line".equals(access_point)) { + if ("public".equals(this.access_mod)) { + return true; + } else { + return false; + } + } + + throw new IllegalArgumentException("Unknown access point passed" + + "to Target.isAccessibleFrom()"); } } Index: src/main/org/apache/tools/ant/helper/ProjectHelper2.java =================================================================== RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java,v retrieving revision 1.28 diff -u -r1.28 ProjectHelper2.java --- src/main/org/apache/tools/ant/helper/ProjectHelper2.java 1 Aug 2003 05:52:31 -0000 1.28 +++ src/main/org/apache/tools/ant/helper/ProjectHelper2.java 11 Aug 2003 19:04:14 -0000 @@ -772,6 +772,8 @@ } } else if (key.equals("depends")) { depends = value; + } else if (key.equals("access")) { + target.setAccess(value); } else if (key.equals("if")) { target.setIf(value); } else if (key.equals("unless")) {