View | Details | Raw Unified | Return to bug 22020
Collapse All | Expand All

(-)src/main/org/apache/tools/ant/Main.java (+20 lines)
Lines 63-68 Link Here
63
import java.util.Enumeration;
63
import java.util.Enumeration;
64
import java.util.Properties;
64
import java.util.Properties;
65
import java.util.Vector;
65
import java.util.Vector;
66
import java.util.Iterator;
67
import java.util.Hashtable;
66
import org.apache.tools.ant.input.DefaultInputHandler;
68
import org.apache.tools.ant.input.DefaultInputHandler;
67
import org.apache.tools.ant.input.InputHandler;
69
import org.apache.tools.ant.input.InputHandler;
68
import org.apache.tools.ant.util.JavaEnvUtils;
70
import org.apache.tools.ant.util.JavaEnvUtils;
Lines 648-653 Link Here
648
                project.setKeepGoingMode(keepGoingMode);
650
                project.setKeepGoingMode(keepGoingMode);
649
651
650
                ProjectHelper.configureProject(project, buildFile);
652
                ProjectHelper.configureProject(project, buildFile);
653
654
		// enforce target accessibility constraints
655
		Hashtable configuredTargets = project.getTargets();
656
		Iterator iter = targets.iterator();
657
		while(iter.hasNext()) {
658
		    String tname = (String) iter.next();
659
		    Target t = (Target) configuredTargets.get(tname);
660
661
		    // t can be null if the user passed a non-existant target
662
		    if ( t != null && !t.isAccessibleFrom("command line")) {
663
			throw new BuildException ("Target " + tname 
664
						  + " cannot be invoked on "
665
						  + "the command line because "
666
						  + "the build file author "
667
						  + "has restricted it's "
668
						  + "accesibility.");
669
		    }
670
		}
651
671
652
                if (projectHelp) {
672
                if (projectHelp) {
653
                    printDescription(project);
673
                    printDescription(project);
(-)src/main/org/apache/tools/ant/Target.java (+44 lines)
Lines 82-87 Link Here
82
    private List children = new ArrayList();
82
    private List children = new ArrayList();
83
    /** Position in task list */
83
    /** Position in task list */
84
    private int taskPosition = 0;
84
    private int taskPosition = 0;
85
    /** Accesibility of this target. */
86
    private String access_mod="public";
85
87
86
    /** Project this target belongs to. */
88
    /** Project this target belongs to. */
87
    private Project project;
89
    private Project project;
Lines 161-166 Link Here
161
    }
163
    }
162
164
163
    /**
165
    /**
166
     * Sets the access modifier of this target.
167
     *
168
     * @param access_mod The access modifier for this target. Default is 
169
     *        "public".
170
     */
171
    public void setAccess(String access) {
172
	if ("public".equals(access) 
173
	    || "private".equals(access)) {
174
        this.access_mod = access;
175
	} else {
176
	    throw new BuildException("Unknown access type.");
177
	}
178
    }
179
180
    /**
164
     * Returns the name of this target.
181
     * Returns the name of this target.
165
     *
182
     *
166
     * @return the name of this target, or <code>null</code> if the
183
     * @return the name of this target, or <code>null</code> if the
Lines 442-446 Link Here
442
        }
459
        }
443
        String test = project.replaceProperties(unlessCondition);
460
        String test = project.replaceProperties(unlessCondition);
444
        return project.getProperty(test) == null;
461
        return project.getProperty(test) == null;
462
    }
463
464
    /**
465
     * Tests if the target may be invoked from the specified location.
466
     * The results of this test are dependant on the location and the access
467
     * level set by the builfile author (e.g. access="private"). This method
468
     * can only return sensible results for access points it knows about, so
469
     * attempts to call it on arbitrary access point names not defined in this
470
     * method will result in an IllegalArguementException. 
471
     *
472
     * @return whether or not the access point specified is permitted.
473
     *         If the access point is not recognized, an IllegalArgument
474
     *         exception is thrown.
475
     * @param  access_point Where the target is being accessed from.
476
     */
477
    
478
    public boolean isAccessibleFrom(String access_point) {
479
	if ("command line".equals(access_point)) {
480
	    if ("public".equals(this.access_mod)) {
481
		return true;
482
	    } else {
483
		return false;
484
	    }
485
	}
486
487
	throw new IllegalArgumentException("Unknown access point passed" 
488
					   + "to Target.isAccessibleFrom()");
445
    }
489
    }
446
}
490
}
(-)src/main/org/apache/tools/ant/helper/ProjectHelper2.java (+2 lines)
Lines 772-777 Link Here
772
                    }
772
                    }
773
                } else if (key.equals("depends")) {
773
                } else if (key.equals("depends")) {
774
                    depends = value;
774
                    depends = value;
775
                } else if (key.equals("access")) {
776
                    target.setAccess(value);
775
                } else if (key.equals("if")) {
777
                } else if (key.equals("if")) {
776
                    target.setIf(value);
778
                    target.setIf(value);
777
                } else if (key.equals("unless")) {
779
                } else if (key.equals("unless")) {

Return to bug 22020