KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 package org.netbeans.nbbuild;
21
22 import java.util.*;
23
24 import org.apache.tools.ant.BuildException;
25 import org.apache.tools.ant.Project;
26 import org.apache.tools.ant.Task;
27
28 /** Set a default list of modules for a given configuration.
29  * Ugly implementation because of the poor support for initialization
30  * from nested elements in Ant.
31  * @author Jesse Glick
32  * @deprecated unused
33  */

34 @Deprecated JavaDoc
35 public class ConfigureModules extends Task {
36
37     private String JavaDoc property, config;
38     private List<Config> configs = new LinkedList<Config>();
39
40     /** You must add a <samp>&lt;config&gt;</samp> nested element for each configuration. */
41     public class Config {
42     public String JavaDoc name, modules;
43         /** Name of the configuration. Used in <samp>-Dmoduleconfig=...</samp> option. */
44     public void setName (String JavaDoc n) {
45         name = n;
46         //checkMyself ();
47
}
48         /** Comma-separated list of modules. */
49     public void setModules (String JavaDoc m) {
50         modules = m;
51         //checkMyself ();
52
}
53     public String JavaDoc toString () {
54         return name;
55     }
56         /*
57     private void checkMyself () {
58         if (name != null && modules != null && config.equals (name)) {
59         if (project0 ().getProperty (property) == null) {
60             project0 ().setProperty (property, modules);
61         } else {
62             log0 ("Note: not overriding property " + property, Project.MSG_VERBOSE);
63         }
64         }
65     }
66         */

67     }
68     /*
69     // Javac 1.2 nonsense:
70     private void log0 (String m, int l) {
71     log (m, l);
72     }
73     private Project project0 () {
74     return project;
75     }
76     */

77
78     /** Name of the property used to hold the resulting comma-separated list of modules. */
79     public void setProperty (String JavaDoc p) {
80     property = p;
81     }
82     /** The desired configuration. */
83     public void setSelectedconfig (String JavaDoc c) {
84     config = c;
85     }
86
87     public Config createConfig () {
88     Config c = new Config ();
89     configs.add (c);
90     return c;
91     }
92
93     public void execute () throws BuildException {
94     if (property == null || config == null)
95         throw new BuildException("Must set both the property and selectedconfig attributes", getLocation());
96     Iterator it = configs.iterator ();
97     while (it.hasNext ()) {
98         Config c = (Config) it.next ();
99         if (config.equals (c.name)) {
100         String JavaDoc value = c.modules;
101         if (value == null)
102             throw new BuildException("Missing modules attribute for config " + config, getLocation());
103         if (getProject().getProperty(property) == null) {
104             getProject().setProperty(property, value);
105         } else {
106             log ("Note: not overriding property " + property, Project.MSG_VERBOSE);
107         }
108         return;
109         }
110     }
111     throw new BuildException("Unrecognized module configuration: " + config + "; pick from: " + configs, getLocation());
112     }
113
114 }
115
Popular Tags