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

(-)src/main/org/apache/tools/ant/DefaultLogger.java (+43 lines)
Lines 42-47 Link Here
42
     */
42
     */
43
    public static final int LEFT_COLUMN_SIZE = 12;
43
    public static final int LEFT_COLUMN_SIZE = 12;
44
44
45
    /**
46
     * Tab sequence for indenting output where needed
47
     * Currently four spaces
48
     */
49
    public static final String TAB_SEQUENCE = "|   ";
50
45
    // CheckStyle:VisibilityModifier OFF - bc
51
    // CheckStyle:VisibilityModifier OFF - bc
46
    /** PrintStream to write non-error messages to */
52
    /** PrintStream to write non-error messages to */
47
    protected PrintStream out;
53
    protected PrintStream out;
Lines 208-213 Link Here
208
            && !event.getTarget().getName().equals("")) {
214
            && !event.getTarget().getName().equals("")) {
209
            String msg = StringUtils.LINE_SEP
215
            String msg = StringUtils.LINE_SEP
210
                + event.getTarget().getName() + ":";
216
                + event.getTarget().getName() + ":";
217
218
            //if addressing is on, tab it in
219
            if ( event.getProject().getAddressingOn() ) {
220
                StringBuffer tmp = new StringBuffer();
221
                ProjectAddress address = event.getProject().getAddress();
222
                if ( address != null ) {
223
                    for ( int i=0; i<address.noChambers(); i++ ) {
224
                        tmp.append(TAB_SEQUENCE);
225
                    }
226
                    msg = tmp.toString() + StringUtils.LINE_SEP;
227
                    msg += tmp.toString() + address +
228
                        " " + event.getTarget().getName() + ":";
229
                }
230
231
            }
232
211
            printMessage(msg, out, event.getPriority());
233
            printMessage(msg, out, event.getPriority());
212
            log(msg);
234
            log(msg);
213
        }
235
        }
Lines 260-268 Link Here
260
                for (int i = 0; i < size; i++) {
282
                for (int i = 0; i < size; i++) {
261
                    tmp.append(" ");
283
                    tmp.append(" ");
262
                }
284
                }
285
286
                //if addressing is on, tab it in even more
287
                StringBuffer tabs = new StringBuffer();
288
                if ( event.getProject().getAddressingOn() ) {
289
                    ProjectAddress address = event.getProject().getAddress();
290
                    if ( address != null ) {
291
                        for ( int i=0; i<address.noChambers(); i++ ) {
292
                            tabs.append(TAB_SEQUENCE);
293
                        }
294
                    }
295
                    tabs.append(TAB_SEQUENCE);
296
                    tmp = new StringBuffer( tabs.toString() + tmp.toString() );
297
                }
298
263
                tmp.append(label);
299
                tmp.append(label);
264
                label = tmp.toString();
300
                label = tmp.toString();
265
301
302
                //if simulation mode is on, use a customized label
303
                if ( event.getProject().isSimulationMode() ) {
304
                    if ( name.equals("ant") ) {
305
                        label = tabs.toString();
306
                    }
307
                }
308
266
                BufferedReader r = null;
309
                BufferedReader r = null;
267
                try {
310
                try {
268
                    r = new BufferedReader(
311
                    r = new BufferedReader(
(-)src/main/org/apache/tools/ant/Task.java (+13 lines)
Lines 340-345 Link Here
340
     * is still fired, but with the exception as the cause.
340
     * is still fired, but with the exception as the cause.
341
     */
341
     */
342
    public final void perform() {
342
    public final void perform() {
343
344
        //if in sim mode, dont execute tasks except antcall, ant and import
345
        if ( getProject().isSimulationMode() ) {
346
            boolean shouldExecute =
347
                getTaskName().equals("antcall") ||
348
                getTaskName().equals("ant") ||
349
                getTaskName().equals("import");
350
351
            if ( !shouldExecute ) {
352
                return;
353
            }
354
        }
355
343
        if (!invalid) {
356
        if (!invalid) {
344
            getProject().fireTaskStarted(this);
357
            getProject().fireTaskStarted(this);
345
            Throwable reason = null;
358
            Throwable reason = null;
(-)src/main/org/apache/tools/ant/Project.java (+127 lines)
Lines 210-215 Link Here
210
    private boolean keepGoingMode = false;
210
    private boolean keepGoingMode = false;
211
211
212
    /**
212
    /**
213
     * Simulation mode
214
     */
215
    private boolean simulationMode;
216
217
    /**
218
     * Addressing options
219
     */
220
    private boolean addressingOn = false;
221
    private ProjectAddress address = null;
222
    private int nextSubAddress = 1;
223
    private ProjectAddress addressingFrom = null;
224
    private ProjectAddress addressingTo = null;
225
    private ProjectAddress addressingDescend = null;
226
227
228
    /**
213
     * Set the input handler.
229
     * Set the input handler.
214
     *
230
     *
215
     * @param handler the InputHandler instance to use for gathering input.
231
     * @param handler the InputHandler instance to use for gathering input.
Lines 867-872 Link Here
867
    }
883
    }
868
884
869
    /**
885
    /**
886
     * Set simulation mode. In this mode Ant will only execute the
887
     * tasks involved in traversing the target tree, and skip the rest
888
     * Namely, these tasks are &lt;ant&gt;, &lt;antcall&gt; and &lt;import&gt;
889
     * @param simulationMode true to turn on simulation mode, false to turn it off
890
     */
891
    public void setSimulationMode(boolean simulationMode) {
892
        this.simulationMode = simulationMode;
893
    }
894
895
    /**
896
     * Return the simulation mode.
897
     * @return true if simulation mode is on, false otherwise
898
     */
899
    public boolean isSimulationMode() {
900
        return simulationMode;
901
    }
902
903
    /**
904
     * Set Addressing on or off.
905
     * When addressing is on, each project will be assigned an address
906
     * which will be displayed in front its targets' names as they are executed.
907
     * These addresses can be used to select subsets of subprojects to run
908
     * using the -from, -to and -descend arguments
909
     * @param addressingMode true to turn addressing on, false to turn it off
910
     */
911
    public void setAddressingOn( boolean addressingOn ) {
912
        this.addressingOn = addressingOn;
913
    }
914
915
    /**
916
     * Get the addressingMode for this project
917
     * @return true if Addressing is on, false otherwise
918
     */
919
    public boolean getAddressingOn() {
920
        return addressingOn;
921
    }
922
923
    /**
924
    * Sets the address of this project.
925
    * @param address The address of this project
926
    */
927
    public void setAddress( ProjectAddress address ) {
928
        this.address = address;
929
    }
930
    
931
    /**
932
    * Returns the address of this project.
933
    * @return the address of this project
934
    */
935
    public ProjectAddress getAddress() {
936
        return address;
937
    }
938
    
939
    /**
940
     * Get the next sub address and increment
941
     * Used when creating an address for a subproject
942
     * @return the next sub address of this project
943
     */
944
    public int getNextSubAddress() {
945
        return nextSubAddress++;
946
    }
947
948
    /**
949
     * Set the target to execute from by its address
950
     * @param from the address of the target to execute from
951
     */
952
    public void setAddressingFrom( ProjectAddress addressingFrom ) {
953
        this.addressingFrom = addressingFrom;
954
    }
955
956
    /**
957
     * Get the address of the target to execute from
958
     * @return the address of the target to execute from
959
     */
960
    public ProjectAddress getAddressingFrom() {
961
        return addressingFrom;
962
    }
963
964
    /**
965
     * Set the target to execute to by its address
966
     * @param from the address of the target to execute to
967
     */
968
    public void setAddressingTo( ProjectAddress addressingTo ) {
969
        this.addressingTo = addressingTo;
970
    }
971
972
    /**
973
     * Get the address of the target to execute to
974
     * @return the address of the target to execute to
975
     */
976
    public ProjectAddress getAddressingTo() {
977
        return addressingTo;
978
    }
979
980
    /**
981
     * Set the target to descend by its address
982
     * @param from the address of the target to descend
983
     */
984
    public void setAddressingDescend( ProjectAddress addressingDescend ) {
985
        this.addressingDescend = addressingDescend;
986
    }
987
988
    /**
989
     * Get the address of the target to descend
990
     * @return the address of the target to descend
991
     */
992
    public ProjectAddress getAddressingDescend() {
993
        return addressingDescend;
994
    }
995
996
    /**
870
     * Return the version of Java this class is running under.
997
     * Return the version of Java this class is running under.
871
     * @return the version of Java as a String, e.g. "1.1" .
998
     * @return the version of Java as a String, e.g. "1.1" .
872
     * @see org.apache.tools.ant.util.JavaEnvUtils#getJavaVersion
999
     * @see org.apache.tools.ant.util.JavaEnvUtils#getJavaVersion
(-)src/main/org/apache/tools/ant/ProjectAddress.java (+323 lines)
Line 0 Link Here
1
/*
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
3
 *  contributor license agreements.  See the NOTICE file distributed with
4
 *  this work for additional information regarding copyright ownership.
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
6
 *  (the "License"); you may not use this file except in compliance with
7
 *  the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *  Unless required by applicable law or agreed to in writing, software
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *  See the License for the specific language governing permissions and
15
 *  limitations under the License.
16
 *
17
 */
18
package org.apache.tools.ant;
19
20
/*
21
 * A class representing a project address
22
 * The main (root) project has a null address
23
 * Subprojects are created with &lt;ant&gt; and &lt;antcall&gt;
24
 * The subprojects of the main project have the addresses 1, 2, 3 etc.
25
 * Subprojects of project 1 have the addresses 1.1, 1.2, 1.3 etc.
26
 * Subprojects of project 2 have the addresses 2.1, 2.2, 2.3 etc.
27
 * And so on
28
 * Address "root" can be used to point to the root project
29
 * Address "infinity" points to a non-existent first level subproject with an
30
 * infinitly high address. If there are n subprojects in the main project,
31
 * the address "infinity" acts the same as address n+1)
32
 * Can be converted to a string representation and back
33
 * Objects of this class are immutable
34
 *
35
 */
36
public class ProjectAddress {
37
    
38
    private boolean isRoot = false;
39
    private boolean isInfinity = false;
40
    private int[] chambers = null;
41
    private int noChambers = -1;
42
    
43
    public static void main( String[] args ) {
44
        if ( args.length < 2 ) {
45
            System.err.println("Please specify two target addresses");
46
            return;
47
        }
48
49
        ProjectAddress a, b;
50
        try {
51
            a = new ProjectAddress(args[0]);
52
            b = new ProjectAddress(args[1]);
53
        } catch ( BuildException be ) {
54
            System.err.println("Failed to construct address");
55
            System.err.println(be.getMessage());
56
            return;
57
        }
58
        System.out.println( "a: " + a );
59
        System.out.println( "b: " + b );
60
        System.out.println( "a.isAfter(b): " + a.isAfter(b) );
61
        System.out.println( "b.isAfter(a): " + b.isAfter(a) );
62
        System.out.println( "a.isDescendantOf(b): " + a.isDescendantOf(b) );
63
        System.out.println( "b.isDescendantOf(a): " + b.isDescendantOf(a) );
64
65
    }
66
67
    /**
68
     * Construct a ProjectAddress from its string representation
69
     * @param addressAsString a string representation of an address
70
     */
71
    public ProjectAddress( String addressAsString ) throws BuildException {
72
73
        //catch null
74
        if ( addressAsString == null ) {
75
            throw new BuildException( "null address string" );
76
        }
77
78
        //catch root keyword
79
        if ( addressAsString.equals("root") ) {
80
            isRoot = true;
81
            return;
82
        }
83
84
        //catch infinity keyword
85
        if ( addressAsString.equals("infinity") ) {
86
            isInfinity = true;
87
            return;
88
        }
89
90
        //spilt string address into chambers
91
        String[] chambersAsStrings = addressAsString.split("\\.");
92
93
        //create empty chambers for this address
94
        noChambers = chambersAsStrings.length;
95
        chambers = new int[noChambers];
96
        
97
        //load the chambers, checking each is a positive integer
98
        for ( int i=0; i<chambersAsStrings.length; i++ ) {
99
100
            //check it's an int
101
            try {
102
                chambers[i] = Integer.parseInt( chambersAsStrings[i] );
103
            } catch( NumberFormatException e ) {
104
                throw new BuildException( "invalid address string (contains non int chambers): '" + addressAsString + "'" );
105
            }
106
107
            //check it's not negative
108
            if ( chambers[i] < 0 ) {
109
                throw new BuildException( "invalid address string (contains negative int chambers): '" + addressAsString +  "'" );
110
            }
111
112
        }
113
114
    }
115
116
    /**
117
     * Create a ProjectAddress as the child of the given parent ProjectAddress
118
     * using the given subaddress
119
     * E.g., passing in parent 3.5 and subaddress 2 will construct address 3.5.2
120
     */
121
    public ProjectAddress( ProjectAddress parent, int subAddress ) throws BuildException {
122
123
        if ( subAddress < 0 ) {
124
            throw new BuildException( "subaddress must be positive" );
125
        }
126
127
        if ( parent == null || parent.isRoot() ) {
128
129
            //create one chamber
130
            noChambers = 1;
131
            chambers = new int[noChambers];
132
            chambers[0] = subAddress;
133
134
        } else {
135
136
            //create empty chambers with one more chamber than parent
137
            noChambers = parent.noChambers()+1;
138
            chambers = new int[noChambers];
139
140
            //copy parent chambers to this address
141
            for ( int i=0; i<parent.noChambers(); i++ ) {
142
                chambers[i] = parent.getChamber(i);
143
            }
144
145
            //the last chamber is the sub address
146
            chambers[noChambers-1] = subAddress;
147
148
        }
149
150
    }
151
152
    /**
153
     * @return true if this address is the root, false otherwise
154
     */
155
    public boolean isRoot() {
156
        return isRoot;
157
    }
158
159
    /**
160
     * @return true if this address is the infinity address, false otherwise
161
     */
162
    public boolean isInfinity() {
163
        return isInfinity;
164
    }
165
166
    /**
167
     * Gets the value in the given chamber of this address
168
     * E.g., getChamber(2) on address 3.4.7.5 will return 7
169
     * @return the value in the given chamber
170
     */
171
    public int getChamber( int chamber ) {
172
        if ( chamber >=0 && chamber < noChambers ) {
173
            return chambers[chamber];
174
        } else {
175
            return -1;
176
        }
177
    }
178
179
    /**
180
     * @return the number of chambers this address has
181
     */
182
    public int noChambers() {
183
        return noChambers;
184
    }
185
186
    /**
187
     * Converts this address to its string representation
188
     * That is, either "root", "infinity", or a string like:
189
     * "1.11.2.6"
190
     * @return the string representation of this address
191
     */
192
    public String toString() {
193
        if ( isRoot ) {
194
            return "root";
195
        }
196
197
        if ( isInfinity ) {
198
            return "infinity";
199
        }
200
201
        StringBuffer addressString = new StringBuffer();
202
        for ( int i=0; i<noChambers; i++ ) {
203
            addressString.append( "" + chambers[i] );
204
            if ( i < noChambers -1 ) {
205
                addressString.append( "." );
206
            }
207
        }
208
        return addressString.toString();
209
210
    }
211
212
    /*
213
     * Returns true if this address is after the given address
214
     * E.g., new ProjectAddress("1.6").isAfter(new ProjectAddress("1.5")) would return true
215
     * E.g., new ProjectAddress("1.4").isAfter(new ProjectAddress("1.8.5)) would return false
216
     * By convention, consider an address to be after itself
217
     * Have used 'this' keyword in code for readablilty
218
     */
219
    public boolean isAfter( ProjectAddress otherAddress ) throws BuildException {
220
221
        //catch null
222
        if ( otherAddress == null ) {
223
            throw new BuildException(
224
                "Null ProjectAddress given in ProjectAddress.isAfter()");
225
        }
226
227
        //everything is after root
228
        if ( otherAddress.isRoot() ) {
229
            return true;
230
        }
231
232
        //root is after nothing
233
        //(except itself, but that's already caught)
234
        if ( this.isRoot ) {
235
            return false;
236
        }
237
238
        //infinity is after everything
239
        if ( this.isInfinity ) {
240
            return true;
241
        }
242
243
        //nothing is after infinity
244
        // (except itself, but that's already caught)
245
        if ( otherAddress.isInfinity() ) {
246
            return false;
247
        }
248
249
        //step through, checking that chambers of this are higher than
250
        //or equal to chambers of otherAddress
251
        for ( int i=0; i<otherAddress.noChambers(); i++ ) {
252
            
253
            int thisChamber = i < this.noChambers ? this.chambers[i] : 0;
254
255
            if(  thisChamber < otherAddress.getChamber(i) ) {
256
                return false;
257
            }
258
259
            if(  thisChamber > otherAddress.getChamber(i) ) {
260
                return true;
261
            }
262
        }
263
264
        //first [otherAddress.noChambers()] chambers are equal
265
        return true;
266
    }
267
268
269
    public boolean isDescendantOf( ProjectAddress otherAddress ) {
270
271
        //catch null
272
        if ( otherAddress == null ) {
273
            throw new BuildException(
274
                "Null ProjectAddress given in ProjectAddress.isDescendantOf()");
275
        }
276
277
        //everything decends from root
278
        if ( otherAddress.isRoot() ) {
279
            return true;
280
        }
281
282
        //root descends from nothing
283
        //(except itself but that's already caught)
284
        if ( this.isRoot ) {
285
            return false;
286
        }
287
288
        //infinity descends from itself
289
        if ( this.isInfinity && otherAddress.isInfinity() ) {
290
            return true;
291
        }
292
293
        //nothing descends from infinity
294
        //(except itself but that's already caught)
295
        if ( otherAddress.isInfinity() ) {
296
            return false;
297
        }
298
299
        //infinity descends only from nothing
300
        //(except root and itself, but that's already caught)
301
        if ( this.isInfinity ) {
302
            return false;
303
        }
304
305
        //make sure x is at least as deep as y
306
        if ( this.noChambers < otherAddress.noChambers() ) {
307
            return false;
308
        }
309
310
        //step through, making sure x values are equal to y values
311
        for ( int i=0; i<otherAddress.noChambers(); i++ ) {
312
            if(  this.chambers[i] != otherAddress.getChamber(i) ) {
313
                return false;
314
            }
315
        }
316
317
        //first [otherAddress.noChambers()] chambers are equal
318
        return true;
319
320
    }
321
322
323
}
(-)src/main/org/apache/tools/ant/taskdefs/Ant.java (+73 lines)
Lines 41-46 Link Here
41
import org.apache.tools.ant.Main;
41
import org.apache.tools.ant.Main;
42
import org.apache.tools.ant.types.PropertySet;
42
import org.apache.tools.ant.types.PropertySet;
43
import org.apache.tools.ant.util.FileUtils;
43
import org.apache.tools.ant.util.FileUtils;
44
import org.apache.tools.ant.util.StringUtils;
45
import org.apache.tools.ant.ProjectAddress;
44
46
45
/**
47
/**
46
 * Build a sub-project.
48
 * Build a sub-project.
Lines 103-108 Link Here
103
    /** the targets to call on the new project */
105
    /** the targets to call on the new project */
104
    private Vector targets = new Vector();
106
    private Vector targets = new Vector();
105
107
108
    /** address to give to the new project */
109
    private ProjectAddress address = null;
110
106
    /** whether the target attribute was specified **/
111
    /** whether the target attribute was specified **/
107
    private boolean targetAttributeSet = false;
112
    private boolean targetAttributeSet = false;
108
113
Lines 191-196 Link Here
191
    private void initializeProject() {
196
    private void initializeProject() {
192
        newProject.setInputHandler(getProject().getInputHandler());
197
        newProject.setInputHandler(getProject().getInputHandler());
193
198
199
        newProject.setSimulationMode(getProject().isSimulationMode());
200
201
        if ( getProject().getAddressingOn() ) {
202
            newProject.setAddressingOn(true);
203
            newProject.setAddress(address);
204
            newProject.setAddressingFrom(getProject().getAddressingFrom());
205
            newProject.setAddressingTo(getProject().getAddressingTo());
206
            newProject.setAddressingDescend(getProject().getAddressingDescend());
207
        }
208
194
        Iterator iter = getBuildListeners();
209
        Iterator iter = getBuildListeners();
195
        while (iter.hasNext()) {
210
        while (iter.hasNext()) {
196
            newProject.addBuildListener((BuildListener) iter.next());
211
            newProject.addBuildListener((BuildListener) iter.next());
Lines 327-332 Link Here
327
     * probably also if a BuildException is thrown by the new project.
342
     * probably also if a BuildException is thrown by the new project.
328
     */
343
     */
329
    public void execute() throws BuildException {
344
    public void execute() throws BuildException {
345
346
        //if addressing is on, check if we really want to excecute the subproject
347
        if ( getProject().getAddressingOn() ) {
348
349
            //figure out what the address of the target should be
350
            ProjectAddress callingAddress = getProject().getAddress();
351
            int subAddress = getProject().getNextSubAddress();
352
            address = new ProjectAddress( callingAddress, subAddress );
353
           
354
            boolean shouldExecuteOnFrom =
355
                getProject().getAddressingFrom() == null ||
356
                getProject().getAddressingFrom().isDescendantOf(address) ||
357
                address.isAfter(getProject().getAddressingFrom());
358
            if ( !shouldExecuteOnFrom ) {
359
                return;
360
            }
361
362
            boolean shouldExecuteOnDescend =
363
                getProject().getAddressingDescend() == null ||
364
                getProject().getAddressingDescend().isDescendantOf(address) ||
365
                address.isDescendantOf(getProject().getAddressingDescend());
366
            if ( !shouldExecuteOnDescend ) {
367
                return;
368
            }
369
370
            boolean shouldExecuteOnTo =
371
                getProject().getAddressingTo() == null ||
372
                !address.isAfter(getProject().getAddressingTo());
373
            if ( !shouldExecuteOnTo ) {
374
                return;
375
            }
376
        }
377
378
        //if in simulation mode, only execute antcalls
379
        if ( getProject().isSimulationMode() ) {
380
            if ( !getTaskName().equals("antcall") ) {
381
                StringBuffer msg = new StringBuffer(StringUtils.LINE_SEP);
382
                if ( address != null ) {
383
                    msg.append( address.toString() + " -> " );
384
                }
385
                if ( targets != null && targets.size() > 0 ) {
386
                    for ( int i=0; i<targets.size(); i++ ) {
387
                        msg.append( targets.get(i) );
388
                        if ( i<targets.size()-1 ) {
389
                            msg.append( "," );
390
                        }
391
                    }
392
                     msg.append( " " );
393
                }
394
                if ( antFile != null ) {
395
                    msg.append( "in " + antFile );
396
                }
397
398
                log( msg.toString() );
399
                return;
400
            }
401
        }
402
330
        File savedDir = dir;
403
        File savedDir = dir;
331
        String savedAntFile = antFile;
404
        String savedAntFile = antFile;
332
        Vector locals = new Vector(targets);
405
        Vector locals = new Vector(targets);
(-)src/main/org/apache/tools/ant/Main.java (-1 / +88 lines)
Lines 143-148 Link Here
143
    private Integer threadPriority = null;
143
    private Integer threadPriority = null;
144
144
145
    /**
145
    /**
146
     * simulation mode
147
     */
148
    private boolean simulationMode = false;
149
150
    /**
151
     * addressing options
152
     */
153
    private boolean addressingOn = false;
154
    private ProjectAddress addressingFrom = null;
155
    private ProjectAddress addressingTo = null;
156
    private ProjectAddress addressingDescend = null;
157
158
    /**
146
     * proxy flag: default is false
159
     * proxy flag: default is false
147
     */
160
     */
148
    private boolean proxy = false;
161
    private boolean proxy = false;
Lines 372-377 Link Here
372
                keepGoingMode = true;
385
                keepGoingMode = true;
373
            } else if (arg.equals("-nice")) {
386
            } else if (arg.equals("-nice")) {
374
                i = handleArgNice(args, i);
387
                i = handleArgNice(args, i);
388
            } else if (arg.equals("-sim")) {
389
                i = handleArgSim(args, i);
390
            } else if (arg.equals("-addressing")) {
391
                i = handleArgAddressing(args, i);
392
            } else if (arg.equals("-from")) {
393
                i = handleArgFromToDescend(args, i);
394
            } else if (arg.equals("-to")) {
395
                i = handleArgFromToDescend(args, i);
396
            } else if (arg.equals("-descend")) {
397
                i = handleArgFromToDescend(args, i);
375
            } else if (LAUNCH_COMMANDS.contains(arg)) {
398
            } else if (LAUNCH_COMMANDS.contains(arg)) {
376
                //catch script/ant mismatch with a meaningful message
399
                //catch script/ant mismatch with a meaningful message
377
                //we could ignore it, but there are likely to be other
400
                //we could ignore it, but there are likely to be other
Lines 562-567 Link Here
562
        return pos;
585
        return pos;
563
    }
586
    }
564
587
588
    /** Handle the -sim argument. */
589
    private int handleArgSim(String[] args, int pos) {
590
        simulationMode = true;
591
        return pos;
592
    }
593
594
    /** Handle the -addressing argument. */
595
    private int handleArgAddressing(String[] args, int pos) {
596
        addressingOn = true;
597
        return pos;
598
    }
599
600
    /** Handle the -from -to or -descend argument. */
601
    private int handleArgFromToDescend(String[] args, int pos) {
602
603
        ProjectAddress address;
604
        try {
605
            //this will throw its own BuildException
606
            //if the address in invalid
607
	        address = new ProjectAddress( args[++pos] );
608
        } catch (ArrayIndexOutOfBoundsException aioobe) {
609
            throw new BuildException(
610
                "You must specify an address when using the " +
611
                args[pos-1] + " argument");
612
        }
613
614
        if ( args[pos-1].equals( "-from" ) ) {
615
            addressingFrom = address;
616
        } else if ( args[pos-1].equals( "-to" ) ) {
617
            addressingTo = address;
618
        } else if ( args[pos-1].equals( "-descend" ) ) {
619
            addressingDescend = address;
620
        } else {
621
            //should never get here
622
            throw new BuildException(
623
                "Unrecognised addressing option: " + args[pos-1] );
624
        }
625
        addressingOn = true;
626
        return pos;
627
    }
628
565
    // --------------------------------------------------------
629
    // --------------------------------------------------------
566
    //    other methods
630
    //    other methods
567
    // --------------------------------------------------------
631
    // --------------------------------------------------------
Lines 738-743 Link Here
738
                                        buildFile.getAbsolutePath());
802
                                        buildFile.getAbsolutePath());
739
803
740
                project.setKeepGoingMode(keepGoingMode);
804
                project.setKeepGoingMode(keepGoingMode);
805
806
                project.setSimulationMode( simulationMode );
807
808
                //a special addressing situation, -to root
809
                if ( addressingOn && addressingTo != null && addressingTo.isRoot() ) {
810
                    return;
811
                }
812
813
                //addressing options
814
                if ( addressingOn ) {
815
                    project.setAddressingOn(true);
816
                    project.setAddressingFrom(addressingFrom);
817
                    project.setAddressingTo(addressingTo);
818
                    project.setAddressingDescend(addressingDescend);
819
                }
820
741
                if (proxy) {
821
                if (proxy) {
742
                    //proxy setup if enabled
822
                    //proxy setup if enabled
743
                    ProxySetup proxySetup = new ProxySetup(project);
823
                    ProxySetup proxySetup = new ProxySetup(project);
Lines 910-916 Link Here
910
        msg.append("  -noclasspath           Run ant without using CLASSPATH" + lSep);
990
        msg.append("  -noclasspath           Run ant without using CLASSPATH" + lSep);
911
        msg.append("  -autoproxy             Java1.5+: use the OS proxy settings"
991
        msg.append("  -autoproxy             Java1.5+: use the OS proxy settings"
912
                + lSep);
992
                + lSep);
913
        msg.append("  -main <class>          override Ant's normal entry point");
993
        msg.append("  -main <class>          override Ant's normal entry point" + lSep);
994
        msg.append("  -sim                   simulation - show targets that would be executed" + lSep
995
                 + "                           but don't actually do anything" + lSep );
996
        msg.append("  -addressing            turn on subproject addressing" + lSep);
997
        msg.append("  -from <address>        execute from subproject with <address>" + lSep);
998
        msg.append("  -to <address>          execute up to subproject with <address>" + lSep);
999
        msg.append("  -descend <address>     execute only subproject with <address>");
1000
914
        System.out.println(msg.toString());
1001
        System.out.println(msg.toString());
915
    }
1002
    }
916
1003

Return to bug 45612