001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2005 ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ********************************************************************************/package net.sourceforge.cruisecontrol;
037:
038: import net.sourceforge.cruisecontrol.buildloggers.MergeLogger;
039: import net.sourceforge.cruisecontrol.publishers.email.EmailMapper;
040: import net.sourceforge.cruisecontrol.publishers.email.EmailMapping;
041: import net.sourceforge.cruisecontrol.config.ConfigurationPlugin;
042: import net.sourceforge.cruisecontrol.config.DashboardConfigurationPlugin;
043: import net.sourceforge.cruisecontrol.config.IncludeProjectsPlugin;
044: import net.sourceforge.cruisecontrol.config.PluginPlugin;
045: import net.sourceforge.cruisecontrol.config.SystemPlugin;
046: import net.sourceforge.cruisecontrol.config.ThreadsPlugin;
047: import net.sourceforge.cruisecontrol.config.DefaultPropertiesPlugin;
048:
049: import java.io.Serializable;
050: import java.util.HashMap;
051: import java.util.HashSet;
052: import java.util.Iterator;
053: import java.util.Map;
054: import java.util.Set;
055:
056: /**
057: * Type-safe, enumeration of CruiseControl plugin types.
058: */
059: public final class PluginType implements Serializable {
060: public static final PluginType BOOTSTRAPPER = new PluginType(
061: "bootstrapper", "bootstrappers");
062: public static final PluginType BOOTSTRAPPERS = new PluginType(
063: "bootstrappers", "project");
064: public static final PluginType BUILDER = new PluginType("builder",
065: "schedule");
066: public static final PluginType CONFIGURATION = new PluginType(
067: "configuration", "system");
068: public static final PluginType CRUISECONTROL = new PluginType(
069: "cruisecontrol", "");
070: public static final PluginType DATE_FORMAT = new PluginType(
071: "dateformat", "project");
072: public static final PluginType INCLUDE_PROJECTS = new PluginType(
073: "include.projects", "cruisecontrol");
074: public static final PluginType DASHBOARD_CONFIGURATION = new PluginType(
075: "dashboard", "cruisecontrol");
076: public static final PluginType LABEL_INCREMENTER = new PluginType(
077: "labelincrementer", "project");
078: public static final PluginType LISTENER = new PluginType(
079: "listener", "listeners");
080: public static final PluginType LISTENERS = new PluginType(
081: "listeners", "project");
082: public static final PluginType LOG = new PluginType("log",
083: "project");
084: public static final PluginType MAP = new PluginType("map", "email");
085: public static final PluginType MERGE_LOGGER = new PluginType(
086: "logger", "log");
087: public static final PluginType MANIPULATORS = new PluginType(
088: "manipulators", "log");
089: public static final PluginType MODIFICATION_SET = new PluginType(
090: "modificationset", "project");
091: public static final PluginType PROJECT = new PluginType("project",
092: "cruisecontrol");
093: public static final PluginType PLUGIN = new PluginType("plugin",
094: "cruisecontrol");
095: public static final PluginType EMAIL_MAPPER = new PluginType(
096: "propertiesmapper", "email");
097: public static final PluginType PAUSE = new PluginType("pause",
098: "schedule");
099: public static final PluginType PROPERTIES = new PluginType(
100: "property", "cruisecontrol");
101: public static final PluginType PUBLISHER = new PluginType(
102: "publisher", "publishers");
103: public static final PluginType PUBLISHERS = new PluginType(
104: "publishers", "project");
105: public static final PluginType SCHEDULE = new PluginType(
106: "schedule", "project");
107: public static final PluginType SOURCE_CONTROL = new PluginType(
108: "sourcecontrol", "modificationset");
109: public static final PluginType SYSTEM = new PluginType("system",
110: "cruisecontrol");
111: public static final PluginType THREADS = new PluginType("threads",
112: "configuration");
113:
114: private static final Map PLUGIN_TYPES = new HashMap() {
115: {
116: put(Bootstrapper.class, BOOTSTRAPPER);
117: put(ProjectConfig.Bootstrappers.class, BOOTSTRAPPERS);
118: put(Builder.class, BUILDER);
119: put(ConfigurationPlugin.class, CONFIGURATION);
120: put(CruiseControlConfig.class, CRUISECONTROL);
121: put(CCDateFormat.class, DATE_FORMAT);
122: put(LabelIncrementer.class, LABEL_INCREMENTER);
123: put(IncludeProjectsPlugin.class, INCLUDE_PROJECTS);
124: put(Listener.class, LISTENER);
125: put(ProjectConfig.Listeners.class, LISTENERS);
126: put(Log.class, LOG);
127: put(EmailMapping.class, MAP);
128: put(MergeLogger.class, MERGE_LOGGER);
129: put(Manipulator.class, MANIPULATORS);
130: put(ModificationSet.class, MODIFICATION_SET);
131: put(ProjectConfig.class, PROJECT);
132: put(PluginPlugin.class, PLUGIN);
133: put(EmailMapper.class, EMAIL_MAPPER);
134: put(ProjectConfig.Publishers.class, PUBLISHERS);
135: put(PauseBuilder.class, PAUSE);
136: put(DefaultPropertiesPlugin.class, PROPERTIES);
137: put(Publisher.class, PUBLISHER);
138: put(Schedule.class, SCHEDULE);
139: put(SourceControl.class, SOURCE_CONTROL);
140: put(SystemPlugin.class, SYSTEM);
141: put(ThreadsPlugin.class, THREADS);
142: put(DashboardConfigurationPlugin.class,
143: DASHBOARD_CONFIGURATION);
144: }
145: };
146:
147: private final String name;
148: private final String parentElementName;
149:
150: private PluginType(String type, String parentElementName) {
151: this .name = type;
152: this .parentElementName = parentElementName;
153: }
154:
155: public static PluginType find(Class pluginClass) {
156: if (pluginClass != null) {
157: for (Iterator i = PLUGIN_TYPES.entrySet().iterator(); i
158: .hasNext();) {
159: Map.Entry element = (Map.Entry) i.next();
160: if (((Class) element.getKey())
161: .isAssignableFrom(pluginClass)) {
162: return (PluginType) element.getValue();
163: }
164: }
165: }
166:
167: throw new IllegalArgumentException(pluginClass
168: + " is not a CruiseControl plugin.");
169: }
170:
171: public static PluginType[] getTypes() {
172: Set uniqueValues = new HashSet(PLUGIN_TYPES.values());
173: return (PluginType[]) uniqueValues
174: .toArray(new PluginType[uniqueValues.size()]);
175: }
176:
177: public static PluginType find(String name) {
178: if (name != null) {
179: for (Iterator iter = PLUGIN_TYPES.entrySet().iterator(); iter
180: .hasNext();) {
181: Map.Entry element = (Map.Entry) iter.next();
182: PluginType nextType = (PluginType) element.getValue();
183: if (nextType.getName().equals(name)) {
184: return nextType;
185: }
186: }
187: }
188:
189: throw new IllegalArgumentException(name
190: + " is not a CruiseControl plugin.");
191: }
192:
193: public String getName() {
194: return this .name;
195: }
196:
197: public String getParentElementName() {
198: return parentElementName;
199: }
200:
201: public String toString() {
202: return getName();
203: }
204:
205: private Object readResolve() {
206: return PluginType.find(this.name);
207: }
208: }
|