KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > nbbuild > Repeat


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.nbbuild;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.StringTokenizer JavaDoc;
24 import org.apache.tools.ant.BuildException;
25 import org.apache.tools.ant.Project;
26 import org.apache.tools.ant.Task;
27 import org.apache.tools.ant.taskdefs.CallTarget;
28 import org.apache.tools.ant.taskdefs.Property;
29
30 /**
31  * For each of specified property values calls target task of a specified name
32  * with property set to one of these values
33  *
34  * @author Radim Kubacki
35  */

36 public class Repeat extends Task {
37     
38     private List JavaDoc<String JavaDoc> values;
39     private String JavaDoc target;
40     private String JavaDoc startdir;
41     private String JavaDoc name;
42     
43     //
44
// init
45
//
46

47     public Repeat() {
48         values = new ArrayList JavaDoc<String JavaDoc>();
49         target = null;
50     }
51
52     //
53
// itself
54
//
55

56     /** Name of property that will be set for each call. */
57     public void setName (String JavaDoc s) {
58         log ("SET name = " + s, Project.MSG_DEBUG);
59
60         name = s;
61     }
62     
63     /** Comma separated list of values. */
64     public void setValues (String JavaDoc s) {
65         log ("SET values = " + s, Project.MSG_DEBUG);
66
67         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc (s, ", ");
68         values = new ArrayList JavaDoc<String JavaDoc>();
69         while ( tok.hasMoreTokens() ) {
70             values.add (tok.nextToken().trim());
71         }
72     }
73     
74     /** Name of target which will be used with ant task. If not specified,
75      * owning target name is used.
76      */

77     public void setTarget (String JavaDoc s) {
78         log ("SET target = " + s, Project.MSG_DEBUG);
79
80         target = s;
81     }
82
83     /** Execute this task. */
84     public void execute () throws BuildException {
85         if ( values.isEmpty() ) {
86             throw new BuildException("You must set at least one value!", getLocation());
87         }
88
89         if ( target == null ) {
90             throw new BuildException("Target must be set!", getLocation());
91         }
92
93         for (String JavaDoc val : values) {
94             log ("Process '" + val + "' location with '" + target + "' target ...", Project.MSG_VERBOSE);
95             
96             CallTarget antCall = (CallTarget) getProject().createTask("antcall");
97             antCall.init();
98             antCall.setLocation(getLocation());
99             
100             // ant.setDir (dir);
101
antCall.setTarget (target);
102             Property prop = antCall.createParam();
103             prop.setName(name);
104             prop.setValue(val);
105             
106             antCall.execute();
107         }
108     }
109     
110 }
111
Popular Tags