001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.nbbuild;
043:
044: import java.util.*;
045:
046: import org.apache.tools.ant.BuildException;
047: import org.apache.tools.ant.Project;
048: import org.apache.tools.ant.Task;
049:
050: /** Set a default list of modules for a given configuration.
051: * Ugly implementation because of the poor support for initialization
052: * from nested elements in Ant.
053: * @author Jesse Glick
054: * @deprecated unused
055: */
056: @Deprecated
057: public class ConfigureModules extends Task {
058:
059: private String property, config;
060: private List<Config> configs = new LinkedList<Config>();
061:
062: /** You must add a <samp><config></samp> nested element for each configuration. */
063: public class Config {
064: public String name, modules;
065:
066: /** Name of the configuration. Used in <samp>-Dmoduleconfig=...</samp> option. */
067: public void setName(String n) {
068: name = n;
069: //checkMyself ();
070: }
071:
072: /** Comma-separated list of modules. */
073: public void setModules(String m) {
074: modules = m;
075: //checkMyself ();
076: }
077:
078: public String toString() {
079: return name;
080: }
081: /*
082: private void checkMyself () {
083: if (name != null && modules != null && config.equals (name)) {
084: if (project0 ().getProperty (property) == null) {
085: project0 ().setProperty (property, modules);
086: } else {
087: log0 ("Note: not overriding property " + property, Project.MSG_VERBOSE);
088: }
089: }
090: }
091: */
092: }
093:
094: /*
095: // Javac 1.2 nonsense:
096: private void log0 (String m, int l) {
097: log (m, l);
098: }
099: private Project project0 () {
100: return project;
101: }
102: */
103:
104: /** Name of the property used to hold the resulting comma-separated list of modules. */
105: public void setProperty(String p) {
106: property = p;
107: }
108:
109: /** The desired configuration. */
110: public void setSelectedconfig(String c) {
111: config = c;
112: }
113:
114: public Config createConfig() {
115: Config c = new Config();
116: configs.add(c);
117: return c;
118: }
119:
120: public void execute() throws BuildException {
121: if (property == null || config == null)
122: throw new BuildException(
123: "Must set both the property and selectedconfig attributes",
124: getLocation());
125: Iterator it = configs.iterator();
126: while (it.hasNext()) {
127: Config c = (Config) it.next();
128: if (config.equals(c.name)) {
129: String value = c.modules;
130: if (value == null)
131: throw new BuildException(
132: "Missing modules attribute for config "
133: + config, getLocation());
134: if (getProject().getProperty(property) == null) {
135: getProject().setProperty(property, value);
136: } else {
137: log("Note: not overriding property " + property,
138: Project.MSG_VERBOSE);
139: }
140: return;
141: }
142: }
143: throw new BuildException("Unrecognized module configuration: "
144: + config + "; pick from: " + configs, getLocation());
145: }
146:
147: }
|